Sha256: e792fbf78d04b4c0e2eca59c7144971594c06165415c32e3add8d0eaf7cf125a

Contents?: true

Size: 806 Bytes

Versions: 2

Compression:

Stored size: 806 Bytes

Contents

module Vedeu

  # Provides means to convert attributes into the correct model.
  #
  # @api private
  module Coercions

    include Vedeu::Common

    # Produces new objects of the correct class from attributes hashes,
    # ignores objects that have already been coerced.
    #
    # @param values [Array|Hash]
    # @return [Array]
    def coercer(values)
      return [] unless defined_value?(values)

      [values].flatten.map do |value|
        if value.is_a?(self)
          value

        else
          self.new(value)

        end
      end
    end

    # Whenever this module {Vedeu::Coercions} is included in another class or
    # module, make its methods into class methods, so they may be called
    # directly.
    def self.included(receiver)
      receiver.extend(self)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.2 lib/vedeu/models/attributes/coercions.rb
vedeu-0.2.1 lib/vedeu/models/attributes/coercions.rb