Sha256: f31d86d8dc728d140640954470928e956ceed3841c2699e4f1f7152b9ad42cd3
Contents?: true
Size: 981 Bytes
Versions: 13
Compression:
Stored size: 981 Bytes
Contents
require 'toy/proxies/embedded_list' module Toy class EmbeddedList include Toy::Collection def after_initialize create_accessors end private def create_accessors model.class_eval """ def #{name} #{instance_variable} ||= self.class.#{list_method}[:#{name}].new_proxy(self) end def #{name}=(records) #{name}.replace(records) end def #{name.to_s.singularize}_attributes=(attrs) self.#{name} = attrs.map do |value| value = value.is_a?(Hash) ? value : value[1] #{type}.new(value) end end def #{name.to_s.singularize}_attributes #{name}.map(&:attributes) end """ type.class_eval { attr_accessor :parent_reference } end def proxy_class Toy::Proxies::EmbeddedList end def list_method :embedded_lists end end end
Version data entries
13 entries across 13 versions & 1 rubygems