Class: Virtus::Attribute::Collection
- Inherits:
-
Virtus::Attribute
- Object
- Virtus::Attribute
- Virtus::Attribute::Collection
- Defined in:
- lib/virtus/attribute/collection.rb
Overview
Collection attribute handles enumerable-like types
Handles coercing members to the designated member type.
Defined Under Namespace
Classes: Type
Constant Summary
Constants included from TypeLookup
Instance Attribute Summary collapse
- #member_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
- #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
#member_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.
12 13 14 |
# File 'lib/virtus/attribute/collection.rb', line 12 def member_type @member_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.
63 64 65 |
# File 'lib/virtus/attribute/collection.rb', line 63 def self.build_type(definition) Type.infer(definition.type, definition.primitive) 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.
68 69 70 |
# File 'lib/virtus/attribute/collection.rb', line 68 def self.(type, ) [:member_type] ||= Attribute.build(type.member_type) end |
Instance Method Details
#coerce ⇒ Object
73 74 75 76 77 |
# File 'lib/virtus/attribute/collection.rb', line 73 def coerce(*) super.each_with_object(primitive.new) do |entry, collection| collection << member_type.coerce(entry) 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.
80 81 82 83 84 |
# File 'lib/virtus/attribute/collection.rb', line 80 def finalize return self if finalized? @member_type = @options[:member_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.
87 88 89 |
# File 'lib/virtus/attribute/collection.rb', line 87 def finalized? super && member_type.finalized? end |