lhs 5.4.0 → 5.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -5
- data/lib/lhs/concerns/record/chainable.rb +10 -7
- data/lib/lhs/version.rb +1 -1
- data/spec/record/immutable_chains_spec.rb +20 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24363abbc61959e5dfb50fcaa161fdaa317472e6
|
4
|
+
data.tar.gz: 5f39eab662c51ce10d43ef3fe2acb2b03b9de7e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 804ebde5bc541230d27e6dfacb0ea6bade3898635f2203317ffa73516e5008d0d75db8800620f9dc540fc2b9063d22ee7b27628e42b540208e8ecdebcb157cb6
|
7
|
+
data.tar.gz: 468a884356c6c09757bc9d7defc8fcbfd3a78353d59a77430da317a4fae1850dad16caeeac4c777df5d5ce2272fcfc9686059acdcfa59e9fde3e879e8e719006
|
data/README.md
CHANGED
@@ -126,9 +126,6 @@ The example would fetch records with the following parameters: `{color: blue, vi
|
|
126
126
|
|
127
127
|
If no record is found an error is raised.
|
128
128
|
|
129
|
-
## Proxy
|
130
|
-
Instead of mapping data when it arrives from the service, the proxy makes data accessible when you access it, not when you fetch it. The proxy is used to access data and it is divided in `Collection` and `Item`.
|
131
|
-
|
132
129
|
`find` can also be used to find a single uniqe record with parameters:
|
133
130
|
|
134
131
|
```ruby
|
@@ -304,8 +301,8 @@ The implementation is heavily influenced by [http://guides.rubyonrails.org/activ
|
|
304
301
|
claims = Claims.includes(:localch_account).where(place_id: 'huU90mB_6vAfUdVz_uDoyA')
|
305
302
|
claims.first.localch_account.email # 'test@email.com'
|
306
303
|
```
|
307
|
-
* [see the JSON without include](examples/claim_no_include.json)
|
308
|
-
* [see the JSON with include](examples/claim_with_include.json)
|
304
|
+
* [see the JSON without include](docs/examples/claim_no_include.json)
|
305
|
+
* [see the JSON with include](docs/examples/claim_with_include.json)
|
309
306
|
|
310
307
|
### Two-Level `includes`
|
311
308
|
|
@@ -63,13 +63,15 @@ class LHS::Record
|
|
63
63
|
class Chain
|
64
64
|
|
65
65
|
# Instance exec is required for scope chains
|
66
|
-
delegated_methods = Object.instance_methods - [:instance_exec]
|
66
|
+
delegated_methods = Object.instance_methods - [:instance_exec, :clone]
|
67
67
|
delegate(*delegated_methods, to: :resolve)
|
68
68
|
|
69
|
+
attr_accessor :_links
|
70
|
+
|
69
71
|
def initialize(record_class, link, record = nil)
|
70
72
|
@record_class = record_class
|
71
73
|
@record = record
|
72
|
-
|
74
|
+
self._links = [link].compact
|
73
75
|
end
|
74
76
|
|
75
77
|
def create(data = {})
|
@@ -180,20 +182,21 @@ class LHS::Record
|
|
180
182
|
private
|
181
183
|
|
182
184
|
def push(link)
|
183
|
-
|
184
|
-
|
185
|
+
clone = self.clone
|
186
|
+
clone._links = _links + [link].compact
|
187
|
+
clone
|
185
188
|
end
|
186
189
|
|
187
190
|
def chain_parameters
|
188
|
-
merge_links
|
191
|
+
merge_links _links.select { |link| link.is_a? Parameter }
|
189
192
|
end
|
190
193
|
|
191
194
|
def chain_options
|
192
|
-
merge_links
|
195
|
+
merge_links _links.select { |link| link.is_a? Option }
|
193
196
|
end
|
194
197
|
|
195
198
|
def chain_pagination
|
196
|
-
resolve_pagination
|
199
|
+
resolve_pagination _links.select { |link| link.is_a? Pagination }
|
197
200
|
end
|
198
201
|
|
199
202
|
def resolve_pagination(links)
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
before(:each) do
|
5
|
+
class Record < LHS::Record
|
6
|
+
endpoint 'http://local.ch/v2/records'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'always returns a new chain and does not mutate the original' do
|
11
|
+
blue_request = stub_request(:get, "http://local.ch/v2/records?color=blue").to_return(body: [].to_json)
|
12
|
+
blue_records = Record.where(color: 'blue')
|
13
|
+
blue_active_request = stub_request(:get, "http://local.ch/v2/records?color=blue&active=true").to_return(body: [].to_json)
|
14
|
+
active_blue_records = blue_records.where(active: true)
|
15
|
+
blue_records.first
|
16
|
+
active_blue_records.first
|
17
|
+
assert_requested(blue_request)
|
18
|
+
assert_requested(blue_active_request)
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.4.
|
4
|
+
version: 5.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -297,6 +297,7 @@ files:
|
|
297
297
|
- spec/record/find_in_batches_spec.rb
|
298
298
|
- spec/record/find_spec.rb
|
299
299
|
- spec/record/first_spec.rb
|
300
|
+
- spec/record/immutable_chains_spec.rb
|
300
301
|
- spec/record/includes_spec.rb
|
301
302
|
- spec/record/loading_twice_spec.rb
|
302
303
|
- spec/record/mapping_spec.rb
|
@@ -435,6 +436,7 @@ test_files:
|
|
435
436
|
- spec/record/find_in_batches_spec.rb
|
436
437
|
- spec/record/find_spec.rb
|
437
438
|
- spec/record/first_spec.rb
|
439
|
+
- spec/record/immutable_chains_spec.rb
|
438
440
|
- spec/record/includes_spec.rb
|
439
441
|
- spec/record/loading_twice_spec.rb
|
440
442
|
- spec/record/mapping_spec.rb
|