Class: Virtus::Attribute::Hash
- Inherits:
-
Virtus::Attribute
- Object
- Virtus::Attribute
- Virtus::Attribute::Hash
- Defined in:
- lib/virtus/attribute/hash.rb
Overview
Handles attributes with Hash type
Defined Under Namespace
Classes: Type
Constant Summary
Constants included from TypeLookup
Instance Attribute Summary collapse
- #key_type ⇒ Object readonly private
- #value_type ⇒ Object readonly private
Attributes inherited from Virtus::Attribute
#coercer, #default_value, #options, #primitive, #type
Class Method Summary collapse
Instance Method Summary collapse
-
#coerce ⇒ Object
Coerce members.
- #finalize ⇒ Object private
- #finalized? ⇒ Boolean private
Methods inherited from Virtus::Attribute
build, build_coercer, coerce, #coercible?, #define_accessor_methods, #initialize, #lazy?, #rename, #required?, #strict?, #value_coerced?
Methods included from TypeLookup
#determine_type, extended, #primitive
Methods included from Options
#accept_options, #accepted_options, #options
Constructor Details
This class inherits a constructor from Virtus::Attribute
Instance Attribute Details
#key_type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/virtus/attribute/hash.rb', line 11 def key_type @key_type end |
#value_type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/virtus/attribute/hash.rb', line 11 def value_type @value_type end |
Class Method Details
.build_type(definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/virtus/attribute/hash.rb', line 89 def self.build_type(definition) Type.infer(definition.type) end |
.merge_options!(type, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 97 |
# File 'lib/virtus/attribute/hash.rb', line 94 def self.(type, ) [:key_type] ||= Attribute.build(type.key_type) [:value_type] ||= Attribute.build(type.value_type) end |
Instance Method Details
#coerce ⇒ Object
Coerce members
104 105 106 107 108 109 110 111 112 |
# 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 ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
115 116 117 118 119 120 |
# File 'lib/virtus/attribute/hash.rb', line 115 def finalize return self if finalized? @key_type = [:key_type].finalize @value_type = [:value_type].finalize super end |
#finalized? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'lib/virtus/attribute/hash.rb', line 123 def finalized? super && key_type.finalized? && value_type.finalized? end |