Class: Virtus::Attribute::EmbeddedValue
- Inherits:
-
Object
- Object
- Virtus::Attribute
- Object
- Virtus::Attribute::EmbeddedValue
- Defined in:
- lib/virtus/attribute/embedded_value.rb
Overview
EmbeddedValue
Constant Summary
Constants included from TypeLookup
TypeLookup::EXTRA_CONST_ARGS, TypeLookup::TYPE_FORMAT
Instance Attribute Summary
Attributes inherited from Virtus::Attribute
#coercion_method, #default, #instance_variable_name, #name, #options, #reader_visibility, #writer_visibility
Class Method Summary collapse
-
.merge_options(type, options) ⇒ Hash
private
An updated options hash for configuring an EmbeddedValue instance.
Instance Method Summary collapse
-
#coerce(attributes_or_object) ⇒ Virtus
private
Coerce attributes into a virtus object.
-
#initialize(name, options = {}) ⇒ undefined
constructor
private
Sets @model ivar.
Methods inherited from Virtus::Attribute
build, #define_accessor_methods, #define_reader_method, #define_writer_method, determine_type, #get, #get!, #inspect, #public_reader?, #public_writer?, #set, #set!, #value_coerced?
Methods included from DescendantsTracker
Methods included from TypeLookup
Methods included from Options
#accept_options, #accepted_options, #options
Constructor Details
#initialize(name, options = {}) ⇒ undefined
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.
Sets @model ivar
46 47 48 49 |
# File 'lib/virtus/attribute/embedded_value.rb', line 46 def initialize(name, = {}) super @model = .fetch(:model, OpenStruct) end |
Class Method Details
.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.
35 36 37 |
# File 'lib/virtus/attribute/embedded_value.rb', line 35 def self.(type, ) .merge(:model => type) end |
Instance Method Details
#coerce(attributes_or_object) ⇒ 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
58 59 60 61 62 63 64 65 66 |
# File 'lib/virtus/attribute/embedded_value.rb', line 58 def coerce(attributes_or_object) value = if attributes_or_object.kind_of?(::Hash) @model.new(attributes_or_object) else attributes_or_object end super(value) end |