lib/virtus/attribute/embedded_value.rb in virtus-1.0.0.rc2 vs lib/virtus/attribute/embedded_value.rb in virtus-1.0.0

- old
+ new

@@ -4,27 +4,15 @@ # EmbeddedValue handles virtus-like objects, OpenStruct and Struct # 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 + class FromStruct < Virtus::Coercer # @api public def call(input) if input.kind_of?(primitive) input @@ -37,11 +25,11 @@ # Builds OpenStruct-like instance with attributes passed to the constructor # as a hash # # @private - class FromOpenStruct < Coercer + class FromOpenStruct < Virtus::Coercer # @api public def call(input) if input.kind_of?(primitive) input @@ -65,12 +53,12 @@ # @api private def self.build_coercer(type, _options) primitive = type.primitive if primitive < Virtus || primitive < Model::Constructor || primitive <= OpenStruct - FromOpenStruct.new(primitive) + FromOpenStruct.new(type) elsif primitive < Struct - FromStruct.new(primitive) + FromStruct.new(type) end end end # class EmbeddedValue