Class: Productive::Base
- Inherits:
-
JsonApiClient::Resource
- Object
- JsonApiClient::Resource
- Productive::Base
show all
- Defined in:
- lib/productive/resources/base.rb
Defined Under Namespace
Classes: BaseItems, LazyItems
Constant Summary
collapse
- PER_PAGE =
1000
Class Method Summary
collapse
Class Method Details
.all(args = {}) ⇒ Object
52
53
54
|
# File 'lib/productive/resources/base.rb', line 52
def self.all(args = {})
depaginate(BaseItems.new([]), args).items
end
|
.connection_object ⇒ Object
21
22
23
|
# File 'lib/productive/resources/base.rb', line 21
def self.connection_object
RequestStore.store[:json_api_client_base_connection_object]
end
|
.connection_object=(connection) ⇒ Object
25
26
27
|
# File 'lib/productive/resources/base.rb', line 25
def self.connection_object=(connection)
RequestStore.store[:json_api_client_base_connection_object] = connection
end
|
.connection_options ⇒ Object
13
14
15
|
# File 'lib/productive/resources/base.rb', line 13
def self.connection_options
RequestStore.store[:json_api_client_base_connection_options]
end
|
.connection_options=(options) ⇒ Object
17
18
19
|
# File 'lib/productive/resources/base.rb', line 17
def self.connection_options=(options)
RequestStore.store[:json_api_client_base_connection_options] = options
end
|
.connection_options_setup(config) ⇒ Object
40
41
42
|
# File 'lib/productive/resources/base.rb', line 40
def self.connection_options_setup(config)
self.connection_options = { headers: { 'X-Auth-Token' => config.api_key } }
end
|
.depaginate(items, args) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/productive/resources/base.rb', line 62
def self.depaginate(items, args)
page = paginate(per_page: PER_PAGE).find(args)
items.append(page)
loop do
page = page.pages.next
raise StopIteration if page.nil?
items.append(page)
end
items
end
|
.lazy_all(args = {}) ⇒ Object
56
57
58
59
60
|
# File 'lib/productive/resources/base.rb', line 56
def self.lazy_all(args = {})
Enumerator.new do |yielder|
depaginate(LazyItems.new(yielder), args)
end.lazy
end
|
.paginator_setup(config) ⇒ Object
44
45
46
|
# File 'lib/productive/resources/base.rb', line 44
def self.paginator_setup(config)
self.paginator = config.paginator
end
|
.reset_connection ⇒ Object
48
49
50
|
# File 'lib/productive/resources/base.rb', line 48
def self.reset_connection
self.connection(rebuild: true)
end
|
.setup(config) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/productive/resources/base.rb', line 29
def self.setup(config)
site_setup config
connection_options_setup config
paginator_setup config
reset_connection
end
|
.site ⇒ Object
5
6
7
|
# File 'lib/productive/resources/base.rb', line 5
def self.site
RequestStore.store[:json_api_client_base_site]
end
|
.site=(site) ⇒ Object
9
10
11
|
# File 'lib/productive/resources/base.rb', line 9
def self.site=(site)
RequestStore.store[:json_api_client_base_site] = site
end
|
.site_setup(config) ⇒ Object
36
37
38
|
# File 'lib/productive/resources/base.rb', line 36
def self.site_setup(config)
self.site = File.join config.base_url, '/'
end
|