Class: ATDIS::Models::Pagination
- Inherits:
-
ATDIS::Model
- Object
- ATDIS::Model
- ATDIS::Models::Pagination
- Defined in:
- lib/atdis/models/pagination.rb
Instance Attribute Summary
Attributes inherited from ATDIS::Model
#attributes, #attributes_before_type_cast, #json_left_overs, #json_load_error, #url
Instance Method Summary collapse
-
#all_pagination_is_present ⇒ Object
If some of the pagination fields are present all of the required ones should be present.
- #count_is_consistent ⇒ Object
- #current_is_consistent ⇒ Object
- #next_is_consistent ⇒ Object
- #previous_is_consistent ⇒ Object
Methods inherited from ATDIS::Model
attribute_keys, attribute_names, cast, #initialize, interpret, #json_errors, #json_errors_in_children, #json_errors_local, #json_left_overs_is_empty, #json_loaded_correctly!, partition_by_used, read_json, read_url, #used_attribute?
Constructor Details
This class inherits a constructor from ATDIS::Model
Instance Method Details
#all_pagination_is_present ⇒ Object
If some of the pagination fields are present all of the required ones should be present
18 19 20 21 22 23 |
# File 'lib/atdis/models/pagination.rb', line 18 def all_pagination_is_present errors.add(:current, ErrorMessage["should be present if pagination is being used", "6.4"]) if current.nil? errors.add(:per_page, ErrorMessage["should be present if pagination is being used", "6.4"]) if per_page.nil? errors.add(:count, ErrorMessage["should be present if pagination is being used", "6.4"]) if count.nil? errors.add(:pages, ErrorMessage["should be present if pagination is being used", "6.4"]) if pages.nil? end |
#count_is_consistent ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/atdis/models/pagination.rb', line 58 def count_is_consistent if pages && per_page && count && count > pages * per_page errors.add(:count, ErrorMessage["is larger than can be retrieved through paging", "6.4"]) end if pages && per_page && count && count <= (pages - 1) * per_page errors.add(:count, ErrorMessage["could fit into a smaller number of pages", "6.4"]) end end |
#current_is_consistent ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/atdis/models/pagination.rb', line 49 def current_is_consistent if current && pages && current > pages errors.add(:current, ErrorMessage["is larger than the number of pages", "6.4"]) end if current && current < 1 errors.add(:current, ErrorMessage["can not be less than 1", "6.4"]) end end |
#next_is_consistent ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/atdis/models/pagination.rb', line 37 def next_is_consistent if self.next && current && self.next != current + 1 errors.add(:next, ErrorMessage["should be one greater than current page number or null if last page", "6.4"]) end if self.next.nil? && current != pages errors.add(:next, ErrorMessage["can't be null if not on the last page", "6.4"]) end if self.next && current == pages errors.add(:next, ErrorMessage["should be null if on the last page", "6.4"]) end end |
#previous_is_consistent ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/atdis/models/pagination.rb', line 25 def previous_is_consistent if previous && current && previous != current - 1 errors.add(:previous, ErrorMessage["should be one less than current page number or null if first page", "6.4"]) end if previous && current && current == 1 errors.add(:previous, ErrorMessage["should be null if on the first page", "6.4"]) end if previous.nil? && current && current > 1 errors.add(:previous, ErrorMessage["can't be null if not on the first page", "6.4"]) end end |