Module: TypedParameter::TypeConstraint

Defined in:
lib/typed_parameter/type_constraint.rb

Class Method Summary collapse

Class Method Details

.value(type, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/typed_parameter/type_constraint.rb', line 4

def value(type, value)
  type_class = [type].flatten.first

  if type_class < TypedParameter::Base
    type.is_a?(Array) ? parameter_array(type_class, value) : type.permit(value)
  else
    constraint = TypedParameter::Constraints[type_class.name.to_sym]
    constraint ||= TypedParameter::Constraints::StringConstraint # Default

    type.is_a?(Array) ? constraint_array(constraint, value) : constraint.value(value)
  end
end