Class: RestaurantTypes::Normal
- Inherits:
-
Object
- Object
- RestaurantTypes::Normal
- Defined in:
- app/my_lib/restaurant_types/normal.rb
Overview
Used for set restaurant as normal restaurant Validate the required fields are expected by call #valid?
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#restaurant ⇒ Object
Returns the value of attribute restaurant.
Instance Method Summary collapse
-
#initialize(restaurant_id) ⇒ Normal
constructor
A new instance of Normal.
- #valid? ⇒ Boolean
Constructor Details
#initialize(restaurant_id) ⇒ Normal
Returns a new instance of Normal.
12 13 14 15 16 |
# File 'app/my_lib/restaurant_types/normal.rb', line 12 def initialize(restaurant_id) self.restaurant = Restaurant.find(restaurant_id) @errors = ActiveModel::Errors.new(self) self end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
30 31 32 |
# File 'app/my_lib/restaurant_types/normal.rb', line 30 def errors @errors end |
#restaurant ⇒ Object
Returns the value of attribute restaurant.
10 11 12 |
# File 'app/my_lib/restaurant_types/normal.rb', line 10 def restaurant @restaurant end |
Instance Method Details
#valid? ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/my_lib/restaurant_types/normal.rb', line 18 def valid? if ChargeImmediately.new(restaurant.id).valid? errors.add(:base, 'This Restaurant will charge CC immediately') false elsif ChargeOnHold.new(restaurant.id).valid? errors.add(:base, 'This Restaurant will charge CC on hold') false else true end end |