Sha256: 34e022fad77442d34f69d023effbdb642f63a39be59fa807e50ebe37824a7dc8
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require 'vedeu/support/common' module Vedeu # Provides means to convert attributes into the correct model. # module Coercions include Vedeu::Common # Produces new objects of the correct class from the value, ignores objects # that have already been coerced. def coerce(value) if value.is_a?(self) value elsif value.nil? new else new(value) end end # 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 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. # # @param receiver [Class] The class in which this module is included. # @return [void] def self.included(receiver) receiver.extend(self) end end # Coercions end # Vedeu
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.4.3 | lib/vedeu/support/coercions.rb |