Sha256: e701edae14f4be7740d9454f0b69f63581676e5955712ab7b3e52c0e8d47dd31
Contents?: true
Size: 1.32 KB
Versions: 18
Compression:
Stored size: 1.32 KB
Contents
module Krikri::MappingDSL ## # Returns a proc that can be run to add values for the property to # Passes value(s) through a block, if given. # @return [Proc] a proc that can be used to generate a value for the named # property. class ChildDeclaration < PropertyDeclaration def initialize(name, target_class, opts = {}, &block) @name = name @target_class = target_class @block = block @each = opts.delete(:each) @as = opts.delete(:as) end def to_proc block = @block if @block target_class = @target_class each_val = @each as_sym = @as lambda do |target, record| if each_val iter = each_val.respond_to?(:call) ? each_val.call(record) : each_val iter.each do |value| map = ::Krikri::Mapping.new(target_class) map.define_singleton_method(as_sym) do each_val.dup.select do |v| v = v.value if v.respond_to? :value v == value end end map.instance_eval(&block) target.send(name) << map.process_record(record) end else map = ::Krikri::Mapping.new(target_class) map.instance_eval(&block) target.send(setter, map.process_record(record)) end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems