class Virtus::Attribute::Collection
Collection
attribute handles enumerable-like types
Handles coercing members to the designated member type.
Constants
- Type
FIXME: temporary hack, remove when Axiom::Type works with EV as
member_type
Attributes
member_type[R]
@api private
Public Class Methods
build_type(definition)
click to toggle source
@api private
# File lib/virtus/attribute/collection.rb, line 63 def self.build_type(definition) Type.infer(definition.type, definition.primitive) end
merge_options!(type, options)
click to toggle source
@api private
# File lib/virtus/attribute/collection.rb, line 68 def self.merge_options!(type, options) options[:member_type] ||= Attribute.build(type.member_type, strict: options[:strict]) end
Public Instance Methods
coerce(value)
click to toggle source
@api public
Calls superclass method
Virtus::Attribute::coerce
# File lib/virtus/attribute/collection.rb, line 73 def coerce(value) coerced = super return coerced unless coerced.respond_to?(:each_with_object) coerced.each_with_object(primitive.new) do |entry, collection| collection << member_type.coerce(entry) end end
finalize()
click to toggle source
@api private
Calls superclass method
Virtus::Attribute#finalize
# File lib/virtus/attribute/collection.rb, line 89 def finalize return self if finalized? @member_type = @options[:member_type].finalize super end
finalized?()
click to toggle source
@api private
Calls superclass method
Virtus::Attribute#finalized?
# File lib/virtus/attribute/collection.rb, line 96 def finalized? super && member_type.finalized? end
value_coerced?(value)
click to toggle source
@api public
Calls superclass method
Virtus::Attribute#value_coerced?
# File lib/virtus/attribute/collection.rb, line 84 def value_coerced?(value) super && value.all? { |item| member_type.value_coerced? item } end