class Dinamo::Model::Caster::Any
Public Class Methods
new(type, &block)
click to toggle source
# File lib/dinamo/model/caster.rb, line 43 def initialize(type, &block) @type = type @block = block end
Public Instance Methods
cast(value)
click to toggle source
# File lib/dinamo/model/caster.rb, line 48 def cast(value) case @block.arity when 0 then @block.call when 1 then @block.call(value) when 2 then @block.call(@type, value) end rescue fail Exceptions::CastError, "%p can not be casted into %p" % [value, @type] end
support(key)
click to toggle source
# File lib/dinamo/model/caster.rb, line 59 def support(key) keys << key.to_sym unless supported_key?(key) end
supported_key?(key)
click to toggle source
# File lib/dinamo/model/caster.rb, line 63 def supported_key?(key) keys.include?(key.to_sym) end
Private Instance Methods
keys()
click to toggle source
# File lib/dinamo/model/caster.rb, line 69 def keys @keys ||= [] end