class PeriodsValidator::Validator

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/periods_validator/validator.rb, line 5
def initialize(options)
  @end_range = options.fetch(:end_range, nil)
  @end_range_attribute = options.fetch(:end_range_attribute, :end_range)
  @periods = options.fetch(:in, [])

  super
end

Public Instance Methods

validate_each(record, _attribute, value) click to toggle source
# File lib/periods_validator/validator.rb, line 13
def validate_each(record, _attribute, value)
  end_range = @end_range || record.send(@end_range_attribute)
  options = {
    start_range: value,
    end_range: end_range,
    periods: @periods
  }

  validator = PeriodsValidator::Periods.new(options)

  return if validator.valid?

  record.errors.add(:base, validator.error)
end