class Virtus::Attribute::Hash
Handles attributes with Hash type
Constants
- Type
FIXME: remove this once axiom-types supports it
@private
Attributes
key_type[R]
@api private
value_type[R]
@api private
Public Class Methods
build_type(definition)
click to toggle source
@api private
# File lib/virtus/attribute/hash.rb, line 89 def self.build_type(definition) Type.infer(definition.type) end
merge_options!(type, options)
click to toggle source
@api private
# File lib/virtus/attribute/hash.rb, line 94 def self.merge_options!(type, options) options[:key_type] ||= Attribute.build(type.key_type, :strict => options[:strict]) options[:value_type] ||= Attribute.build(type.value_type, :strict => options[:strict]) end
Public Instance Methods
coerce(*)
click to toggle source
Coerce members
@see [Attribute#coerce]
@api public
Calls superclass method
Virtus::Attribute.coerce
# File lib/virtus/attribute/hash.rb, line 104 def coerce(*) coerced = super return coerced unless coerced.respond_to?(:each_with_object) coerced.each_with_object({}) do |(key, value), hash| hash[key_type.coerce(key)] = value_type.coerce(value) end end
finalize()
click to toggle source
@api private
Calls superclass method
Virtus::Attribute#finalize
# File lib/virtus/attribute/hash.rb, line 115 def finalize return self if finalized? @key_type = options[:key_type].finalize @value_type = options[:value_type].finalize super end
finalized?()
click to toggle source
@api private
Calls superclass method
Virtus::Attribute#finalized?
# File lib/virtus/attribute/hash.rb, line 123 def finalized? super && key_type.finalized? && value_type.finalized? end