Class: VoucherForm::Validation
- Inherits:
-
Object
- Object
- VoucherForm::Validation
- Includes:
- DefaultErrorContainer, MoneyRails::ActionViewExtension
- Defined in:
- app/forms/voucher_form/validation.rb
Defined Under Namespace
Classes: InvalidVoucher
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#calculate ⇒ Object
readonly
Returns the value of attribute calculate.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#voucher ⇒ Object
readonly
Returns the value of attribute voucher.
Instance Method Summary collapse
-
#initialize(param, actor) ⇒ Validation
constructor
but what we need is admin checking.
- #validate ⇒ Object
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Constructor Details
#initialize(param, actor) ⇒ Validation
but what we need is admin checking
22 23 24 25 26 27 28 |
# File 'app/forms/voucher_form/validation.rb', line 22 def initialize(param, actor) self.param = param.to_h.with_indifferent_access @voucher = self.param[:voucher] @calculate = {} self.actor = actor.to_sym raise 'Invalid actor' unless %i[admin restaurant_staff owner user].include?(actor.to_sym) end |
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
9 10 11 |
# File 'app/forms/voucher_form/validation.rb', line 9 def actor @actor end |
#calculate ⇒ Object (readonly)
Returns the value of attribute calculate.
9 10 11 |
# File 'app/forms/voucher_form/validation.rb', line 9 def calculate @calculate end |
#param ⇒ Object
Returns the value of attribute param.
9 10 11 |
# File 'app/forms/voucher_form/validation.rb', line 9 def param @param end |
#voucher ⇒ Object (readonly)
Returns the value of attribute voucher.
9 10 11 |
# File 'app/forms/voucher_form/validation.rb', line 9 def voucher @voucher end |
Instance Method Details
#validate ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/forms/voucher_form/validation.rb', line 30 def validate errors.clear voucher_blank! inactive_voucher! voucher_type_present! if actor != :admin valid_quota_and_one_time! active_voucher! valid_on_specific_date! valid_currency_for_country! selected_day_is_active! valid_per_user_quota! valid_guest_quota! valid_device_type! end valid_package_params! valid_prefix_number! valid_city! valid_package_types! valid_restaurant_tag! valid_restaurant_voucher! if voucher_first_booking? email = user.persisted? ? user.email : param[:email] phone = user.persisted? ? user.phone : param[:phone] invalid_email_and_phone!(email, phone) invalid_for_new_customer! valid_first_booking_user!(email, phone) end voucher_delivery_and_invalid_distance! check_voucher_validity! valid_deductible_voucher! true rescue InvalidVoucher => e errors.add :base, e. false end |