Class: ATDIS::Models::Page

Inherits:
ATDIS::Model show all
Defined in:
lib/atdis/models/page.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

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_presentObject

If some of the pagination fields are present all of the required ones should be present



24
25
26
27
28
# File 'lib/atdis/models/page.rb', line 24

def all_pagination_is_present
  if pagination && count.nil?
    errors.add(:count, ErrorMessage["should be present if pagination is being used", "6.4"])
  end
end

#count_is_consistentObject



30
31
32
33
34
35
# File 'lib/atdis/models/page.rb', line 30

def count_is_consistent
  if count
    errors.add(:count, ErrorMessage["is not the same as the number of applications returned", "6.4"]) if count != response.count
    errors.add(:count, ErrorMessage["should not be larger than the number of results per page", "6.4"]) if count > pagination.per_page
  end
end

#next_pageObject



51
52
53
# File 'lib/atdis/models/page.rb', line 51

def next_page
  Page.read_url(next_url) if next_url
end

#next_urlObject



42
43
44
45
# File 'lib/atdis/models/page.rb', line 42

def next_url
  raise "Can't use next_url when loaded with read_json" if url.nil?
  ATDIS::SeparatedURL.merge(url, page: pagination.next) if pagination && pagination.next
end

#previous_pageObject



47
48
49
# File 'lib/atdis/models/page.rb', line 47

def previous_page
  Page.read_url(previous_url) if previous_url
end

#previous_urlObject



37
38
39
40
# File 'lib/atdis/models/page.rb', line 37

def previous_url
  raise "Can't use previous_url when loaded with read_json" if url.nil?
  ATDIS::SeparatedURL.merge(url, page: pagination.previous) if pagination && pagination.previous
end