Class: Virtus::Attribute::EmbeddedValue
- Inherits:
-
Object
- Object
- Virtus::Attribute
- Object
- Virtus::Attribute::EmbeddedValue
- Defined in:
- lib/virtus/attribute/embedded_value.rb,
lib/virtus/attribute/embedded_value/from_struct.rb,
lib/virtus/attribute/embedded_value/from_open_struct.rb
Overview
EmbeddedValue
Direct Known Subclasses
Defined Under Namespace
Classes: FromOpenStruct, FromStruct
Constant Summary
Constants included from TypeLookup
Instance Attribute Summary
Attributes inherited from Virtus::Attribute
#coercion_method, #default, #name, #options
Class Method Summary collapse
-
.determine_type(klass) ⇒ Virtus::Attribute::EmbeddedValue
private
Determine type based on class.
-
.merge_options(type, options) ⇒ Hash
private
An updated options hash for configuring an EmbeddedValue instance.
Instance Method Summary collapse
-
#coerce(value) ⇒ Virtus
private
Coerce attributes into a virtus object.
Methods inherited from Virtus::Attribute
build, #define_accessor_methods, #define_reader_method, #define_writer_method, #get, #get!, #initialize, #inspect, #public_reader?, #public_writer?, #set, #set!, #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
Class Method Details
.determine_type(klass) ⇒ Virtus::Attribute::EmbeddedValue
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.
Determine type based on class
Virtus::EmbeddedValue.determine_type(Struct) # => Virtus::EmbeddedValue::FromStruct Virtus::EmbeddedValue.determine_type(VirtusClass) # => Virtus::EmbeddedValue::FromOpenStruct
48 49 50 51 52 53 54 |
# File 'lib/virtus/attribute/embedded_value.rb', line 48 def self.determine_type(klass) if klass <= Virtus || klass <= OpenStruct FromOpenStruct elsif klass <= Struct FromStruct end end |
.merge_options(type, options) ⇒ Hash
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.
Returns an updated options hash for configuring an EmbeddedValue instance.
34 35 36 |
# File 'lib/virtus/attribute/embedded_value.rb', line 34 def self.(type, ) .merge(:primitive => type) end |
Instance Method Details
#coerce(value) ⇒ Virtus
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.
Coerce attributes into a virtus object
63 64 65 |
# File 'lib/virtus/attribute/embedded_value.rb', line 63 def coerce(value) value if value.kind_of?(@primitive) end |