Module: AttributeExtensions::Typecasting

Included in:
ClassMethods
Defined in:
lib/attribute_extensions/typecasting.rb,
lib/attribute_extensions/typecasting/symbol_typecaster.rb,
lib/attribute_extensions/typecasting/boolean_typecaster.rb,
lib/attribute_extensions/typecasting/default_typecaster.rb,
lib/attribute_extensions/typecasting/integer_typecaster.rb

Defined Under Namespace

Classes: BooleanTypecaster, DefaultTypecaster, IntegerTypecaster, SymbolTypecaster

Instance Method Summary collapse

Instance Method Details

#typecast(value, type) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/attribute_extensions/typecasting.rb', line 9

def typecast(value, type)
  if type.respond_to?(:call)
    type.call(value)
  else
    typecaster_for(type).call(value)
  end
end

#typecaster_for(type) ⇒ Object



17
18
19
20
# File 'lib/attribute_extensions/typecasting.rb', line 17

def typecaster_for(type)
  type = :default if type.nil?
  "AttributeExtensions::Typecasting::#{type.to_s.camelize}Typecaster".constantize.new
end