Class: StrongerParameters::DateTimeConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/stronger_parameters/constraints/date_time_constraint.rb

Instance Method Summary collapse

Methods inherited from Constraint

#&, #==, #required, #required?, #|

Instance Method Details

#value(v) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/stronger_parameters/constraints/date_time_constraint.rb', line 6

def value(v)
  return v if v.is_a?(DateTime)

  begin
    DateTime.parse v
  rescue ArgumentError, TypeError
    StrongerParameters::InvalidValue.new(v, "must be a date")
  end
end