class Dinamo::Model::Caster
Attributes
types[R]
Public Class Methods
new()
click to toggle source
# File lib/dinamo/model/caster.rb, line 8 def initialize @types = {} end
Public Instance Methods
associate(key, type)
click to toggle source
# File lib/dinamo/model/caster.rb, line 35 def associate(key, type) fail Exceptions::UnsupportedTypeError, "%p type is not supported" % type unless @types.keys.include?(type) current = @types[type] current.support(key) end
cast(attributes)
click to toggle source
# File lib/dinamo/model/caster.rb, line 16 def cast(attributes) attributes.each_with_object({}) do |(key, value), casted| casted[key] = if found = @types.find { |_, any| any.supported_key?(key) } found.pop.cast(value) else value end end end
register(type, &block)
click to toggle source
# File lib/dinamo/model/caster.rb, line 12 def register(type, &block) @types[type] = Any.new(type, &block) end
supported_type?(type)
click to toggle source
# File lib/dinamo/model/caster.rb, line 27 def supported_type?(type) supported_types.include?(type) end
supported_types()
click to toggle source
# File lib/dinamo/model/caster.rb, line 31 def supported_types @types.keys end