Class: PeriodsValidator::Validator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PeriodsValidator::Validator
- Defined in:
- lib/periods_validator/validator.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Validator
constructor
A new instance of Validator.
- #validate_each(record, _attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ Validator
Returns a new instance of Validator.
5 6 7 8 9 10 11 |
# File 'lib/periods_validator/validator.rb', line 5 def initialize() @end_range = .fetch(:end_range, nil) @end_range_attribute = .fetch(:end_range_attribute, :end_range) @periods = .fetch(:in, []) super end |
Instance Method Details
#validate_each(record, _attribute, value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/periods_validator/validator.rb', line 13 def validate_each(record, _attribute, value) end_range = @end_range || record.send(@end_range_attribute) = { start_range: value, end_range: end_range, periods: @periods } validator = PeriodsValidator::Periods.new() return if validator.valid? record.errors.add(:base, validator.error) end |