Class: Travis::Client::Collection
- Inherits:
-
Entity
- Object
- Entity
- Travis::Client::Collection
show all
- Includes:
- Enumerable
- Defined in:
- lib/travis/client/collection.rb
Direct Known Subclasses
BetaFeatures, Branches, Broadcasts, Builds, Travis::Crons, EnvVars, Jobs, Organizations, Repositories, Requests, Settings
Instance Attribute Summary
Attributes inherited from Entity
#session
Instance Method Summary
collapse
Methods inherited from Entity
#[], add_action, add_attribute, add_related_action, for_session, #initialize, #inspect, #merge!, #permission?, #to_entity, #to_h
Instance Method Details
#collection_key ⇒ Object
26
27
28
29
30
31
|
# File 'lib/travis/client/collection.rb', line 26
def collection_key
@collection_key ||= begin
session.fetch(@href) if @payload.keys.all? { |k| k.start_with? '@' }
@payload.keys.detect { |k| !k.start_with?('@') and self[k].is_a? Array }
end
end
|
#each(&block) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/travis/client/collection.rb', line 55
def each(&block)
return enum_for(:each) unless block
on_page.each(&block)
next_page&.each(&block)
self
end
|
#first_page ⇒ Object
45
46
47
48
|
# File 'lib/travis/client/collection.rb', line 45
def first_page
return self if first_page?
['first']&.fetch
end
|
#first_page? ⇒ Boolean
22
23
24
|
# File 'lib/travis/client/collection.rb', line 22
def first_page?
.fetch('is_first', true)
end
|
#last_page ⇒ Object
50
51
52
53
|
# File 'lib/travis/client/collection.rb', line 50
def last_page
return self if last_page?
['last']&.fetch
end
|
#last_page? ⇒ Boolean
18
19
20
|
# File 'lib/travis/client/collection.rb', line 18
def last_page?
.fetch('is_last', true)
end
|
#next_page ⇒ Object
37
38
39
|
# File 'lib/travis/client/collection.rb', line 37
def next_page
['next']&.fetch
end
|
#offset ⇒ Object
10
11
12
|
# File 'lib/travis/client/collection.rb', line 10
def offset
['offset'] || 0
end
|
#on_page ⇒ Object
14
15
16
|
# File 'lib/travis/client/collection.rb', line 14
def on_page
@on_page ||= Array(@payload[collection_key])
end
|
#paginates? ⇒ Boolean
6
7
8
|
# File 'lib/travis/client/collection.rb', line 6
def paginates?
!!@payload['@pagination']
end
|
62
63
64
|
# File 'lib/travis/client/collection.rb', line 62
def
@pagination_info ||= @payload['@pagination'] || {}
end
|
#previous_page ⇒ Object
41
42
43
|
# File 'lib/travis/client/collection.rb', line 41
def previous_page
['prev']&.fetch
end
|
#size ⇒ Object
33
34
35
|
# File 'lib/travis/client/collection.rb', line 33
def size
['count'] || on_page.size
end
|