lib/virtus/attribute/embedded_value.rb in virtus-1.0.0.beta8 vs lib/virtus/attribute/embedded_value.rb in virtus-1.0.0.rc1

- old
+ new

@@ -23,19 +23,26 @@ # :street => 'Street 1/2', :zipcode => '12345', :city => 'NYC' }) # class EmbeddedValue < Attribute TYPES = [Struct, OpenStruct, Virtus, Model::Constructor].freeze + # Abstract EV coercer class + # + # @private class Coercer attr_reader :primitive def initialize(primitive) @primitive = primitive end end # Coercer + # Builds Struct-like instance with attributes passed to the constructor as + # a list of args rather than a hash + # + # @private class FromStruct < Coercer # @api public def call(input) if input.kind_of?(primitive) @@ -45,10 +52,14 @@ end end end # FromStruct + # Builds OpenStruct-like instance with attributes passed to the constructor + # as a hash + # + # @private class FromOpenStruct < Coercer # @api public def call(input) if input.kind_of?(primitive) @@ -65,12 +76,11 @@ klass.is_a?(Class) && TYPES.any? { |type| klass <= type } end # @api private def self.build_type(definition) - klass = definition.primitive.is_a?(Class) ? definition.primitive : definition.type - Axiom::Types::Object.new { primitive klass } + Axiom::Types::Object.new { primitive definition.primitive } end # @api private def self.build_coercer(type, _options) primitive = type.primitive @@ -78,14 +88,9 @@ if primitive < Virtus || primitive < Model::Constructor || primitive <= OpenStruct FromOpenStruct.new(primitive) elsif primitive < Struct FromStruct.new(primitive) end - end - - # @api public - def primitive - type.primitive end end # class EmbeddedValue end # class Attribute