Sha256: 9d5319c93d0069657ed10ec4158b0560d80192b7a50bd4dcb5b257a77f7e7be5
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
require 'vedeu/support/common' 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 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.4.2 | lib/vedeu/support/coercions.rb |
vedeu-0.4.1 | lib/vedeu/support/coercions.rb |
vedeu-0.4.0 | lib/vedeu/support/coercions.rb |
vedeu-0.3.5 | lib/vedeu/support/coercions.rb |