lhs 5.1.0 → 5.2.0
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 +12 -0
- data/lib/lhs/collection.rb +4 -0
- data/lib/lhs/concerns/data/equality.rb +12 -0
- data/lib/lhs/concerns/record/equality.rb +12 -0
- data/lib/lhs/data.rb +17 -0
- data/lib/lhs/item.rb +4 -0
- data/lib/lhs/record.rb +3 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/data/equality_spec.rb +21 -0
- data/spec/data/is_item_or_collection_spec.rb +37 -0
- data/spec/data/parent_spec.rb +36 -0
- data/spec/record/equality_spec.rb +25 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f49d74b6cae3f84139b46895b5defb5454c184
|
4
|
+
data.tar.gz: 9232b8df9672d9caa11e3f0a3a36f2474ba3386e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fbeecfceee4e4c6ebb5f125d427d98cbc1ece337469fb3ae8070de018616e33e5c8923df319863c835367cfcbda6581cc24f22512d3d3b11899bd8531aa801a
|
7
|
+
data.tar.gz: 36520b86b942ac32f0c01191a7e6f418100122f18724b760a0d7f4c7ef630b8c32c3974fa49c714bf6631dc044b5e8448bf8a87ef6be26e7a6f1bb552537d059
|
data/README.md
CHANGED
@@ -156,6 +156,18 @@ If no record is found, `nil` is returned.
|
|
156
156
|
|
157
157
|
`first!` raises LHC::NotFound if nothing was found.
|
158
158
|
|
159
|
+
## Navigate data
|
160
|
+
|
161
|
+
After fetching [single](#find-single-records) or [multiple](#find-multiple-records) records you can navigate the received data with ease.
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
records = Record.where(color: 'blue')
|
165
|
+
records.collection? # true
|
166
|
+
record = records.first
|
167
|
+
record.item? # true
|
168
|
+
record.parent == records # true
|
169
|
+
```
|
170
|
+
|
159
171
|
## Request based options
|
160
172
|
|
161
173
|
You can apply options to the request chain. Those options will be forwarded to the request perfomed by the chain/query.
|
data/lib/lhs/collection.rb
CHANGED
data/lib/lhs/data.rb
CHANGED
@@ -3,6 +3,7 @@ Dir[File.dirname(__FILE__) + '/concerns/data/*.rb'].each { |file| require file }
|
|
3
3
|
|
4
4
|
# Data provides functionalities to accesses information
|
5
5
|
class LHS::Data
|
6
|
+
include Equality
|
6
7
|
include Json
|
7
8
|
|
8
9
|
delegate :instance_methods, :items_key, :limit_key, :total_key, :pagination_key, to: :class
|
@@ -32,6 +33,14 @@ class LHS::Data
|
|
32
33
|
root
|
33
34
|
end
|
34
35
|
|
36
|
+
def parent
|
37
|
+
if _parent && _parent._record
|
38
|
+
_parent._record.new(_parent)
|
39
|
+
else
|
40
|
+
_parent
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
35
44
|
def class
|
36
45
|
_root._record
|
37
46
|
end
|
@@ -46,6 +55,14 @@ class LHS::Data
|
|
46
55
|
root_item == self
|
47
56
|
end
|
48
57
|
|
58
|
+
def collection?
|
59
|
+
_proxy.is_a? LHS::Collection
|
60
|
+
end
|
61
|
+
|
62
|
+
def item?
|
63
|
+
_proxy.is_a? LHS::Item
|
64
|
+
end
|
65
|
+
|
49
66
|
protected
|
50
67
|
|
51
68
|
def method_missing(name, *args, &block)
|
data/lib/lhs/item.rb
CHANGED
data/lib/lhs/record.rb
CHANGED
@@ -6,6 +6,7 @@ class LHS::Record
|
|
6
6
|
include Chainable
|
7
7
|
include Configuration
|
8
8
|
include Create
|
9
|
+
include Equality
|
9
10
|
include Endpoints
|
10
11
|
include Find
|
11
12
|
include FindBy
|
@@ -19,6 +20,7 @@ class LHS::Record
|
|
19
20
|
|
20
21
|
delegate :_proxy, to: :_data
|
21
22
|
delegate :_endpoint, to: :_data
|
23
|
+
delegate :select, to: :_data
|
22
24
|
|
23
25
|
def initialize(data = nil)
|
24
26
|
data = LHS::Data.new({}, nil, self.class) unless data
|
@@ -42,7 +44,7 @@ class LHS::Record
|
|
42
44
|
protected
|
43
45
|
|
44
46
|
def method_missing(name, *args, &block)
|
45
|
-
_data.
|
47
|
+
_data.send(name, *args, &block)
|
46
48
|
end
|
47
49
|
|
48
50
|
def respond_to_missing?(name, include_all = false)
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Data do
|
4
|
+
context 'equality' do
|
5
|
+
before(:each) do
|
6
|
+
class Record < LHS::Record
|
7
|
+
endpoint 'http://local.ch/records'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:raw) do
|
12
|
+
{ name: 'Steve' }
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is equal when two data objects share the same raw data' do
|
16
|
+
expect(
|
17
|
+
LHS::Data.new(raw, nil, Record)
|
18
|
+
).to eq LHS::Data.new(raw, nil, Record)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Data do
|
4
|
+
before(:each) do
|
5
|
+
class Record < LHS::Record
|
6
|
+
endpoint 'http://local.ch/records'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:item) do
|
11
|
+
{
|
12
|
+
customer: {
|
13
|
+
addresses: [
|
14
|
+
{
|
15
|
+
first_line: 'Bachstr. 6'
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:data) do
|
23
|
+
LHS::Data.new(
|
24
|
+
{
|
25
|
+
href: 'http://local.ch/records',
|
26
|
+
items: [item]
|
27
|
+
}, nil, Record)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'provides the information which type of proxy data ist' do
|
31
|
+
expect(data.collection?).to eq true
|
32
|
+
expect(data.first.item?).to eq true
|
33
|
+
expect(data.first.customer.item?).to eq true
|
34
|
+
expect(data.first.customer.addresses.collection?).to eq true
|
35
|
+
expect(data.first.customer.addresses.first.item?).to eq true
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Data do
|
4
|
+
before(:each) do
|
5
|
+
class Record < LHS::Record
|
6
|
+
endpoint 'http://local.ch/records'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:item) do
|
11
|
+
{
|
12
|
+
customer: {
|
13
|
+
address: {
|
14
|
+
first_line: 'Bachstr. 6'
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:data) do
|
21
|
+
LHS::Data.new(
|
22
|
+
{
|
23
|
+
href: 'http://local.ch/records',
|
24
|
+
items: [item]
|
25
|
+
}, nil, Record)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'possible to navigate the parent' do
|
29
|
+
expect(
|
30
|
+
data.first.customer.address.parent
|
31
|
+
).to eq data.first.customer
|
32
|
+
expect(
|
33
|
+
data.first.customer.address.parent.parent
|
34
|
+
).to eq data.first
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
context 'equality' do
|
5
|
+
before(:each) do
|
6
|
+
class Record < LHS::Record
|
7
|
+
endpoint 'http://local.ch/records'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:raw) do
|
12
|
+
{ name: 'Steve' }
|
13
|
+
end
|
14
|
+
|
15
|
+
def record
|
16
|
+
LHS::Record.new LHS::Data.new(raw, nil, Record)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is equal when two data objects share the same raw data' do
|
20
|
+
expect(
|
21
|
+
record
|
22
|
+
).to eq record
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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
|
+
version: 5.2.0
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/lhs.rb
|
180
180
|
- lib/lhs/collection.rb
|
181
181
|
- lib/lhs/concerns/collection/internal_collection.rb
|
182
|
+
- lib/lhs/concerns/data/equality.rb
|
182
183
|
- lib/lhs/concerns/data/json.rb
|
183
184
|
- lib/lhs/concerns/item/destroy.rb
|
184
185
|
- lib/lhs/concerns/item/save.rb
|
@@ -190,6 +191,7 @@ files:
|
|
190
191
|
- lib/lhs/concerns/record/configuration.rb
|
191
192
|
- lib/lhs/concerns/record/create.rb
|
192
193
|
- lib/lhs/concerns/record/endpoints.rb
|
194
|
+
- lib/lhs/concerns/record/equality.rb
|
193
195
|
- lib/lhs/concerns/record/find.rb
|
194
196
|
- lib/lhs/concerns/record/find_by.rb
|
195
197
|
- lib/lhs/concerns/record/first.rb
|
@@ -217,8 +219,11 @@ files:
|
|
217
219
|
- spec/collection/respond_to_spec.rb
|
218
220
|
- spec/collection/without_object_items_spec.rb
|
219
221
|
- spec/data/collection_spec.rb
|
222
|
+
- spec/data/equality_spec.rb
|
223
|
+
- spec/data/is_item_or_collection_spec.rb
|
220
224
|
- spec/data/item_spec.rb
|
221
225
|
- spec/data/merge_spec.rb
|
226
|
+
- spec/data/parent_spec.rb
|
222
227
|
- spec/data/raw_spec.rb
|
223
228
|
- spec/data/respond_to_spec.rb
|
224
229
|
- spec/data/root_spec.rb
|
@@ -286,6 +291,7 @@ files:
|
|
286
291
|
- spec/record/endpoint_misconfiguration_spec.rb
|
287
292
|
- spec/record/endpoint_options_spec.rb
|
288
293
|
- spec/record/endpoints_spec.rb
|
294
|
+
- spec/record/equality_spec.rb
|
289
295
|
- spec/record/find_by_spec.rb
|
290
296
|
- spec/record/find_each_spec.rb
|
291
297
|
- spec/record/find_in_batches_spec.rb
|
@@ -350,8 +356,11 @@ test_files:
|
|
350
356
|
- spec/collection/respond_to_spec.rb
|
351
357
|
- spec/collection/without_object_items_spec.rb
|
352
358
|
- spec/data/collection_spec.rb
|
359
|
+
- spec/data/equality_spec.rb
|
360
|
+
- spec/data/is_item_or_collection_spec.rb
|
353
361
|
- spec/data/item_spec.rb
|
354
362
|
- spec/data/merge_spec.rb
|
363
|
+
- spec/data/parent_spec.rb
|
355
364
|
- spec/data/raw_spec.rb
|
356
365
|
- spec/data/respond_to_spec.rb
|
357
366
|
- spec/data/root_spec.rb
|
@@ -419,6 +428,7 @@ test_files:
|
|
419
428
|
- spec/record/endpoint_misconfiguration_spec.rb
|
420
429
|
- spec/record/endpoint_options_spec.rb
|
421
430
|
- spec/record/endpoints_spec.rb
|
431
|
+
- spec/record/equality_spec.rb
|
422
432
|
- spec/record/find_by_spec.rb
|
423
433
|
- spec/record/find_each_spec.rb
|
424
434
|
- spec/record/find_in_batches_spec.rb
|