Class: StrongerParameters::TimeConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/stronger_parameters/constraints/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/time_constraint.rb', line 6

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

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