Class: Lutaml::Hal::Page

Inherits:
Resource
  • Object
show all
Defined in:
lib/lutaml/hal/page.rb

Instance Attribute Summary

Attributes inherited from Resource

#_global_register_id, #embedded_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

create_link_class, create_link_set_class, from_embedded, #get_embedded, get_link_set_class, hal_link, #has_embedded?, init_links_definition

Class Method Details

.inherited(subclass) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lutaml/hal/page.rb', line 18

def self.inherited(subclass)
  super

  return unless subclass.name

  page_links_symbols = %i[self next prev first last up]
  subclass_name = subclass.name
  subclass.class_eval do
    page_links_symbols.each do |link_symbol|
      hal_link link_symbol, key: link_symbol.to_s, realize_class: subclass_name
    end
  end
end

Instance Method Details

#firstObject



55
56
57
58
59
# File 'lib/lutaml/hal/page.rb', line 55

def first
  return nil unless links.first

  links.first.realize
end

#first?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/lutaml/hal/page.rb', line 79

def first?
  !links.first.nil?
end

#first_pageObject



95
96
97
# File 'lib/lutaml/hal/page.rb', line 95

def first_page
  links.first
end

#lastObject



61
62
63
64
65
# File 'lib/lutaml/hal/page.rb', line 61

def last
  return nil unless links.last

  links.last.realize
end

#last?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/lutaml/hal/page.rb', line 83

def last?
  !links.last.nil?
end

#last_pageObject



99
100
101
# File 'lib/lutaml/hal/page.rb', line 99

def last_page
  links.last
end

#nextObject



32
33
34
35
36
# File 'lib/lutaml/hal/page.rb', line 32

def next
  return nil unless links.next

  links.next.realize
end

#next?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/lutaml/hal/page.rb', line 71

def next?
  !links.next.nil?
end

#next_pageObject



87
88
89
# File 'lib/lutaml/hal/page.rb', line 87

def next_page
  links.next
end

#prevObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lutaml/hal/page.rb', line 38

def prev
  return links.prev.realize if links.prev

  return nil if page <= 1

  prev_page_url = construct_page_url(page - 1)
  return nil unless prev_page_url

  register_name = _global_register_id
  return nil unless register_name

  hal_register = GlobalRegister.instance.get(register_name)
  return nil unless hal_register

  hal_register.resolve_and_cast(nil, prev_page_url)
end

#prev?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/lutaml/hal/page.rb', line 75

def prev?
  !links.prev.nil?
end

#prev_pageObject



91
92
93
# File 'lib/lutaml/hal/page.rb', line 91

def prev_page
  links.prev
end

#total_pagesObject



67
68
69
# File 'lib/lutaml/hal/page.rb', line 67

def total_pages
  pages
end