object_json_mapper 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/bin/console +2 -5
- data/lib/object_json_mapper/extensions/kaminari.rb +4 -1
- data/lib/object_json_mapper/relation.rb +17 -0
- data/lib/object_json_mapper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b3e97045388fd419fa219271f937a53514006a6
|
4
|
+
data.tar.gz: d128b678abc5556cd20dbec389f77ca74cfff33a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c81b255d975f4e7047a40dcd001145d5c281a3eb16dd9a866c68d23d5d2e44514ea84760a08f86efe11dce00f79effc6d9bbf38acc5eeb06040252a17b1f0c
|
7
|
+
data.tar.gz: 5f283647096da6fe777adf6bde7f0ae21bfb4e2a4deafdfa94e6e4ce1bdb61778a4b08cf7217e0f83ebe40fec2d8eb10ca0941dcbe096084582670870c41ec5a
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
* [Pluck](#pluck)
|
21
21
|
* [None](#none)
|
22
22
|
* [Root](#root)
|
23
|
+
* [Paginate](#paginate)
|
23
24
|
* [Configure](#configure)
|
24
25
|
|
25
26
|
## Installation
|
@@ -219,6 +220,19 @@ User.root('people').where(name: 'Name')
|
|
219
220
|
# => GET http://localhost:3000/people?name=Name
|
220
221
|
```
|
221
222
|
|
223
|
+
## Paginate
|
224
|
+
|
225
|
+
*`Kaminari` required.*
|
226
|
+
|
227
|
+
Yields all pages.
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
User.where(name: 'Name').paginate { |user| hello(user) }
|
231
|
+
# => GET http://localhost:3000/people?name=Name?page=1
|
232
|
+
# => GET http://localhost:3000/people?name=Name?page=2
|
233
|
+
# => GET http://localhost:3000/people?name=Name?page=3
|
234
|
+
```
|
235
|
+
|
222
236
|
## Configure
|
223
237
|
|
224
238
|
Available options:
|
data/bin/console
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
|
+
require 'kaminari'
|
4
5
|
require 'object_json_mapper'
|
5
6
|
require 'pry'
|
6
7
|
# require 'irb'
|
@@ -8,7 +9,7 @@ require 'pry'
|
|
8
9
|
ObjectJSONMapper.configure do |config|
|
9
10
|
config.base_url = 'http://localhost:3000/v1/'
|
10
11
|
config.headers = {
|
11
|
-
'Authorization-Consumer' => '
|
12
|
+
'Authorization-Consumer' => '00000000-0000-0000-0000-000000000000'
|
12
13
|
}
|
13
14
|
end
|
14
15
|
|
@@ -20,10 +21,6 @@ class User < ObjectJSONMapper::Base
|
|
20
21
|
has_many :subscriptions
|
21
22
|
|
22
23
|
scope :qwe, -> { where(id: 1) }
|
23
|
-
|
24
|
-
configure do |c|
|
25
|
-
c.root_url = 'children'
|
26
|
-
end
|
27
24
|
end
|
28
25
|
|
29
26
|
class Subscription < ObjectJSONMapper::Base
|
@@ -4,9 +4,12 @@ module Kaminari
|
|
4
4
|
include Kaminari::ConfigurationMethods
|
5
5
|
|
6
6
|
def self.included(base)
|
7
|
-
|
7
|
+
page = lambda do |num|
|
8
8
|
where(page: num, per_page: Kaminari.config.default_per_page)
|
9
9
|
end
|
10
|
+
|
11
|
+
base.define_singleton_method(Kaminari.config.page_method_name, &page)
|
12
|
+
base.send(:define_method, Kaminari.config.page_method_name, &page)
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
@@ -62,6 +62,23 @@ module ObjectJSONMapper
|
|
62
62
|
.map { |attributes| klass.persist(attributes) }
|
63
63
|
end
|
64
64
|
|
65
|
+
# @yield [ObjectJSONMapper::Relation] with next page until last page reached.
|
66
|
+
def paginate
|
67
|
+
i = 1
|
68
|
+
|
69
|
+
loop do
|
70
|
+
chunk = page(i)
|
71
|
+
|
72
|
+
break if chunk.out_of_range?
|
73
|
+
|
74
|
+
yield chunk if block_given?
|
75
|
+
|
76
|
+
break if chunk.last_page?
|
77
|
+
|
78
|
+
i += 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
65
82
|
def deep_clone
|
66
83
|
clone.tap do |object|
|
67
84
|
object.conditions = conditions.clone
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_json_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- droptheplot
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|