Sha256: 26b713a9eba85e0bad323e024b1038417a6650e6a2821263f71c4858e653fb9c
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
module Toy module Collection extend ActiveSupport::Concern included do attr_accessor :model, :name, :options end def initialize(model, name, *args, &block) @model = model @name = name.to_sym @options = args.extract_options! @type = args.shift model.send(list_method)[name] = self options[:extensions] = modularized_extensions(block, options[:extensions]) after_initialize end def type @type ||= name.to_s.classify.constantize end def instance_variable @instance_variable ||= :"@_#{name}" end def new_proxy(owner) proxy_class.new(self, owner) end def extensions options[:extensions] end def eql?(other) self.class.eql?(other.class) && model == other.model && name == other.name end alias :== :eql? private def proxy_class raise('Not Implemented') end def modularized_extensions(*extensions) extensions.flatten.compact.map do |extension| Proc === extension ? Module.new(&extension) : extension end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
toystore-0.10.1 | lib/toy/collection.rb |
toystore-0.10.0 | lib/toy/collection.rb |
toystore-0.9.0 | lib/toy/collection.rb |