Class: RestaurantTypes::ChargeOnHold
- Inherits:
-
Object
- Object
- RestaurantTypes::ChargeOnHold
- Defined in:
- app/my_lib/restaurant_types/charge_on_hold.rb
Overview
Used for set restaurant as charge on hold Validate the required fields are expected by call #valid?
Instance Attribute Summary collapse
-
#adult_charge_amount ⇒ Object
Returns the value of attribute adult_charge_amount.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#kids_charge_amount ⇒ Object
Returns the value of attribute kids_charge_amount.
-
#min_party_size ⇒ Object
Returns the value of attribute min_party_size.
-
#pricing_type ⇒ Object
Returns the value of attribute pricing_type.
-
#restaurant ⇒ Object
Returns the value of attribute restaurant.
Class Method Summary collapse
Instance Method Summary collapse
- #assert_required_attrs ⇒ Object
-
#initialize(restaurant_id, options = {}) ⇒ ChargeOnHold
constructor
A new instance of ChargeOnHold.
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(restaurant_id, options = {}) ⇒ ChargeOnHold
Returns a new instance of ChargeOnHold.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 19 def initialize(restaurant_id, = {}) @errors = ActiveModel::Errors.new(self) self.restaurant = Restaurant.find(restaurant_id) .each_pair do |key, value| method = "#{key}=".to_sym if respond_to?(:method) send(method, value) else Rails.warn "undefined method #{method}" end end self end |
Instance Attribute Details
#adult_charge_amount ⇒ Object
Returns the value of attribute adult_charge_amount.
16 17 18 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 16 def adult_charge_amount @adult_charge_amount end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
46 47 48 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 46 def errors @errors end |
#kids_charge_amount ⇒ Object
Returns the value of attribute kids_charge_amount.
16 17 18 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 16 def kids_charge_amount @kids_charge_amount end |
#min_party_size ⇒ Object
Returns the value of attribute min_party_size.
16 17 18 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 16 def min_party_size @min_party_size end |
#pricing_type ⇒ Object
Returns the value of attribute pricing_type.
16 17 18 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 16 def pricing_type @pricing_type end |
#restaurant ⇒ Object
Returns the value of attribute restaurant.
16 17 18 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 16 def restaurant @restaurant end |
Class Method Details
.human_attribute_name(attr, _options = {}) ⇒ Object
67 68 69 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 67 def self.human_attribute_name(attr, = {}) attr.to_s end |
Instance Method Details
#assert_required_attrs ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 55 def assert_required_attrs if restaurant.min_party_size_to_charge.to_i <= 0 errors.add(:min_party_size, 'has to be greater than 0') end if restaurant.cc_immediate_charge_amount.present? errors.add(:charge_amount, 'should be present') end false end |
#save ⇒ Object
42 43 44 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 42 def save valid? && restaurant.save end |
#valid? ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'app/my_lib/restaurant_types/charge_on_hold.rb', line 33 def valid? if restaurant.cc_min_party_size.to_i.positive? && restaurant.cc_hold_amount.present? true else assert_required_attrs end end |