Class: Lutaml::Hal::Page
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
#first ⇒ Object
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
79
80
81
|
# File 'lib/lutaml/hal/page.rb', line 79
def first?
!links.first.nil?
end
|
#first_page ⇒ Object
95
96
97
|
# File 'lib/lutaml/hal/page.rb', line 95
def first_page
links.first
end
|
#last ⇒ Object
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
83
84
85
|
# File 'lib/lutaml/hal/page.rb', line 83
def last?
!links.last.nil?
end
|
#last_page ⇒ Object
99
100
101
|
# File 'lib/lutaml/hal/page.rb', line 99
def last_page
links.last
end
|
#next ⇒ Object
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
71
72
73
|
# File 'lib/lutaml/hal/page.rb', line 71
def next?
!links.next.nil?
end
|
#next_page ⇒ Object
87
88
89
|
# File 'lib/lutaml/hal/page.rb', line 87
def next_page
links.next
end
|
#prev ⇒ Object
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
75
76
77
|
# File 'lib/lutaml/hal/page.rb', line 75
def prev?
!links.prev.nil?
end
|
#prev_page ⇒ Object
91
92
93
|
# File 'lib/lutaml/hal/page.rb', line 91
def prev_page
links.prev
end
|
#total_pages ⇒ Object
67
68
69
|
# File 'lib/lutaml/hal/page.rb', line 67
def total_pages
pages
end
|