Class: Virtus::Attribute::EmbeddedValue

Inherits:
Virtus::Attribute show all
Defined in:
lib/virtus/attribute/embedded_value.rb

Overview

EmbeddedValue handles virtus-like objects, OpenStruct and Struct

Defined Under Namespace

Classes: FromOpenStruct, FromStruct

Constant Summary collapse

TYPES =
[Struct, OpenStruct, Virtus, Model::Constructor].freeze

Constants included from TypeLookup

TypeLookup::TYPE_FORMAT

Instance Attribute Summary

Attributes inherited from Virtus::Attribute

#coercer, #default_value, #options, #primitive, #type

Class Method Summary collapse

Methods inherited from Virtus::Attribute

build, coerce, #coerce, #coercible?, #define_accessor_methods, #finalize, #finalized?, #initialize, #lazy?, merge_options!, #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

Class Method Details

.build_coercer(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.



54
55
56
57
58
59
60
61
62
# File 'lib/virtus/attribute/embedded_value.rb', line 54

def self.build_coercer(type, _options)
  primitive = type.primitive

  if primitive < Virtus || primitive < Model::Constructor || primitive <= OpenStruct
    FromOpenStruct.new(type)
  elsif primitive < Struct
    FromStruct.new(type)
  end
end

.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.



49
50
51
# File 'lib/virtus/attribute/embedded_value.rb', line 49

def self.build_type(definition)
  Axiom::Types::Object.new { primitive definition.primitive }
end

.handles?(klass) ⇒ 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.

Returns:



44
45
46
# File 'lib/virtus/attribute/embedded_value.rb', line 44

def self.handles?(klass)
  klass.is_a?(Class) && TYPES.any? { |type| klass <= type }
end