Module: MyData::TypeCaster

Extended by:
TypeCaster
Included in:
TypeCaster
Defined in:
lib/my_data/type_caster.rb

Constant Summary collapse

ALLOWED_TYPES =
[
  :string,
  :integer,
  :float,
  :date,
  :time,
  :boolean,
  :resource
].freeze

Instance Method Summary collapse

Instance Method Details

#cast(value:, type:, resource: nil) ⇒ Object



21
22
23
24
25
# File 'lib/my_data/type_caster.rb', line 21

def cast(value:, type:, resource: nil)
  return type_cast_resource(value, resource) if type == :resource

  send("type_cast_#{type}", value)
end

#valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/my_data/type_caster.rb', line 17

def valid_type?(type)
  ALLOWED_TYPES.include?(type)
end