Sha256: e638200c0eb07ae3bed19254b5e04d81d154eb68eabfd701233b262f89dac929
Contents?: true
Size: 881 Bytes
Versions: 13
Compression:
Stored size: 881 Bytes
Contents
require 'toy/proxies/list' module Toy class List include Toy::Collection def after_initialize model.attribute(key, Array) create_accessors end def key @key ||= :"#{name.to_s.singularize}_ids" end private def proxy_class Toy::Proxies::List end def list_method :lists end 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 """ if options[:dependent] model.class_eval """ after_destroy :destroy_#{name} def destroy_#{name} #{name}.each { |o| o.destroy } end """ end end end end
Version data entries
13 entries across 13 versions & 1 rubygems