lib/cistern/collection.rb in cistern-2.2.3 vs lib/cistern/collection.rb in cistern-2.2.4

- old
+ new

@@ -1,7 +1,6 @@ module Cistern::Collection - 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: @@ -15,35 +14,35 @@ end attr_accessor :records, :loaded, :service module ClassMethods - def model(new_model=nil) + def model(new_model = nil) @_model ||= new_model end - def service_method(name=nil) + def service_method(name = nil) @_service_method ||= name end end - alias build initialize + alias_method :build, :initialize def initialize(attributes = {}) merge_attributes(attributes) end - def all(_={}) - raise NotImplementedError + def all(_ = {}) + fail NotImplementedError end - def create(attributes={}) - self.new(attributes).save + def create(attributes = {}) + new(attributes).save end - def get(identity) - raise NotImplementedError + def get(_identity) + fail NotImplementedError end def clear self.loaded = false records && records.clear @@ -56,11 +55,11 @@ end end # @api private def load_records - self.all unless self.loaded + all unless loaded end # Should be called within #all to load records into the collection # @param [Array<Hash>] objects list of record attributes to be loaded # @return self @@ -74,16 +73,16 @@ self.class.model end def new(attributes = {}) unless attributes.is_a?(::Hash) - raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}")) + fail(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}")) end model.new( { - :collection => self, - :service => service, + collection: self, + service: service }.merge(attributes) ) end def reload @@ -92,20 +91,20 @@ self end def to_a load_records - self.records || [] + records || [] end def respond_to?(method, include_private = false) super || array_delegable?(method) end def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.is_a?(self.class) && - comparison_object.to_a == self.to_a) + comparison_object.to_a == to_a) end protected def array_delegable?(method)