lib/cistern/collection.rb in cistern-0.11.2.pre2 vs lib/cistern/collection.rb in cistern-0.11.2

- old
+ new

@@ -1,28 +1,22 @@ -module Cistern::Collection +class Cistern::Collection + extend Cistern::Attributes::ClassMethods + include Cistern::Attributes::InstanceMethods BLACKLISTED_ARRAY_METHODS = [ :compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!, :shuffle!, :slice!, :sort!, :sort_by!, :delete_if, :keep_if, :pop, :shift, :delete_at, :compact ].to_set # :nodoc: - def self.service_collection(service, klass) - plural_name = Cistern::String.underscore(Cistern::String.demodulize(klass.name)) + attr_accessor :records, :loaded, :connection - service.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__ - def #{plural_name}(attributes={}) - #{klass.name}.new(attributes.merge(service: self)) - end - EOS - end - - attr_accessor :records, :loaded, :service - - module ClassMethods - def model(new_model=nil) - @model ||= new_model + def self.model(new_model=nil) + if new_model == nil + @model + else + @model = new_model end end alias build initialize @@ -77,10 +71,10 @@ raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}")) end model.new( { :collection => self, - :service => service, + :connection => connection, }.merge(attributes) ) end def reload