Class: Virtus::Attribute::Collection::Type
- Inherits:
-
Struct
- Object
- Struct
- Virtus::Attribute::Collection::Type
- Defined in:
- lib/virtus/attribute/collection.rb
Overview
FIXME: temporary hack, remove when Axiom::Type works with EV as member_type
Instance Attribute Summary collapse
-
#member_type ⇒ Object
Returns the value of attribute member_type.
-
#primitive ⇒ Object
Returns the value of attribute primitive.
Class Method Summary collapse
- .axiom_type?(type) ⇒ Boolean
- .infer(type, primitive) ⇒ Object
- .infer_member_type(type) ⇒ Object
- .pending?(primitive) ⇒ Boolean
Instance Method Summary collapse
Instance Attribute Details
#member_type ⇒ Object
Returns the value of attribute member_type
15 16 17 |
# File 'lib/virtus/attribute/collection.rb', line 15 def member_type @member_type end |
#primitive ⇒ Object
Returns the value of attribute primitive
15 16 17 |
# File 'lib/virtus/attribute/collection.rb', line 15 def primitive @primitive end |
Class Method Details
.axiom_type?(type) ⇒ Boolean
36 37 38 |
# File 'lib/virtus/attribute/collection.rb', line 36 def self.axiom_type?(type) type.is_a?(Class) && type < Axiom::Types::Type end |
.infer(type, primitive) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/virtus/attribute/collection.rb', line 16 def self.infer(type, primitive) return type if axiom_type?(type) klass = Axiom::Types.infer(type) member = infer_member_type(type) || Object if EmbeddedValue.handles?(member) || pending?(member) Type.new(primitive, member) else klass.new { primitive primitive member_type Axiom::Types.infer(member) } end end |
.infer_member_type(type) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/virtus/attribute/collection.rb', line 40 def self.infer_member_type(type) return unless type.respond_to?(:count) member_type = if type.count > 1 raise NotImplementedError, "build SumType from list of types (#{type})" else type.first end if member_type.is_a?(Class) && member_type < Attribute && member_type.primitive member_type.primitive else member_type end end |
.pending?(primitive) ⇒ Boolean
32 33 34 |
# File 'lib/virtus/attribute/collection.rb', line 32 def self.pending?(primitive) primitive.is_a?(String) || primitive.is_a?(Symbol) end |
Instance Method Details
#coercion_method ⇒ Object
57 58 59 |
# File 'lib/virtus/attribute/collection.rb', line 57 def coercion_method :to_array end |