module ArInterval::Validations

Public Instance Methods

attribute(name, cast_type = ActiveRecord::Attributes::Type::Value, **options) click to toggle source
Calls superclass method
# File lib/ar_interval/validations.rb, line 14
def attribute(name, cast_type = ActiveRecord::Attributes::Type::Value, **options)
  case cast_type when :interval, ArInterval::Type then
    self.interval_fields = [*self.interval_fields, name]
  end

  super
end

Private Instance Methods

validate_interval_fields() click to toggle source
# File lib/ar_interval/validations.rb, line 23
        def validate_interval_fields
  interval_fields.each do |field|
    field_value = read_attribute_before_type_cast(field)
    begin
      ActiveSupport::Duration.parse(field_value)
    rescue ActiveSupport::Duration::ISO8601Parser::ParsingError => e
      errors.add(field, e.message)
    end
  end
end