lib/morpheus/mixins/finders.rb in morpheus-0.4.0 vs lib/morpheus/mixins/finders.rb in morpheus-0.5.0
- old
+ new
@@ -1,65 +1,67 @@
module Morpheus
- module Finders
+ module Mixins
+ module Finders
- def self.included(base)
- base.extend(ClassMethods)
- end
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
- module ClassMethods
+ module ClassMethods
- def find(*args)
- options = args.extract_options!
- if args.length == 1
- case args.first
- when Integer, String
- attributes = [UrlBuilder.find_one(self, args.first.to_i), nil, { :id => args.first.to_i }]
- get(*attributes)
- when Array
- attributes = UrlBuilder.find_some(self, args.first.sort).push({ :ids => args.first })
- get(*attributes)
+ def find(*args)
+ options = args.extract_options!
+ if args.length == 1
+ case args.first
+ when Integer, String
+ attributes = [UrlBuilder.find_one(self, args.first.to_i), nil, { :id => args.first.to_i }]
+ get(*attributes)
+ when Array
+ attributes = UrlBuilder.find_some(self, args.first.sort).push({ :ids => args.first })
+ get(*attributes)
+ else
+ raise ArgumentError, "Unrecognized argument (#{args.first.inspect})."
+ end
else
- raise ArgumentError, "Unrecognized argument (#{args.first.inspect})."
+ attributes = UrlBuilder.find_some(self, args.sort).push({ :ids => args })
+ get(*attributes)
end
- else
- attributes = UrlBuilder.find_some(self, args.sort).push({ :ids => args })
+ end
+
+ def scoped
+ Relation.new(self)
+ end
+
+ def all
+ attributes = [UrlBuilder.find_all(self), nil, {}]
get(*attributes)
end
- end
- def scoped
- Relation.new(self)
- end
+ def first
+ limit(1).first
+ end
- def all
- attributes = [UrlBuilder.find_all(self), nil, {}]
- get(*attributes)
- end
+ def where(query_attributes)
+ Relation.new(self).where(query_attributes)
+ end
- def first
- limit(1).first
- end
+ def limit(amount)
+ Relation.new(self).limit(amount)
+ end
- def where(query_attributes)
- Relation.new(self).where(query_attributes)
- end
+ def page(page_number)
+ Relation.new(self).page(page_number)
+ end
- def limit(amount)
- Relation.new(self).limit(amount)
- end
+ def results_per_page
+ @results_per_page || 10
+ end
- def page(page_number)
- Relation.new(self).page(page_number)
- end
+ def results_per_page=(_results_per_page)
+ @results_per_page = _results_per_page
+ end
- def results_per_page
- @results_per_page || 10
end
- def results_per_page=(_results_per_page)
- @results_per_page = _results_per_page
- end
-
end
-
end
end