lib/supernova/criteria.rb in supernova-0.1.1 vs lib/supernova/criteria.rb in supernova-0.2.0
- old
+ new
@@ -1,6 +1,9 @@
class Supernova::Criteria
+ DEFAULT_PER_PAGE = 25
+ FIRST_PAGE = 1
+
attr_accessor :filters, :search_options, :clazz
class << self
def method_missing(*args)
scope = self.new
@@ -108,9 +111,21 @@
implement_in_subclass
end
def to_a
implement_in_subclass
+ end
+
+ def current_page
+ pagination_attribute_when_greater_zero(:page) || 1
+ end
+
+ def per_page
+ pagination_attribute_when_greater_zero(:per_page) || DEFAULT_PER_PAGE
+ end
+
+ def pagination_attribute_when_greater_zero(attribute)
+ self.search_options[:pagination][attribute] if self.search_options[:pagination] && self.search_options[:pagination][attribute].to_i > 0
end
def implement_in_subclass
raise "implement in subclass"
end
\ No newline at end of file