lhs 15.2.5 → 15.3.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 +23 -0
- data/lib/lhs/concerns/record/relations.rb +4 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/record/has_many_spec.rb +55 -18
- 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: 0ece53bf6cdb9d5fb129509f6e58645d8fcc7968
|
4
|
+
data.tar.gz: a033797e5a4628d2e941eae1888655d1d4c4ff96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61b7f46eeadf281ce482235359e3acb68912b29248dd62e35d48c2dece6c6ce855be8bf1ee8a986827855a8cb9127dc8135ad693611360f3f75f19b0b58744d0
|
7
|
+
data.tar.gz: 7e1c04893c60eb3bad787ba72eaa8257ee9fdda6c5c3c2aa1510bda29d2c2c1f61b5e0f7e47bead0a1e6c0c1579fb64d04a47dd767566c701b9659a382b180a7
|
data/README.md
CHANGED
@@ -326,6 +326,29 @@ Location.find(1).listings.first.supported? # true
|
|
326
326
|
|
327
327
|
```
|
328
328
|
|
329
|
+
### Options
|
330
|
+
|
331
|
+
In case you have to configure relations, the following relation options are available:
|
332
|
+
|
333
|
+
`class_name`: Specify the class name of the relation. Use it only if that name can't be inferred from the relation name. So has_many :photos will by default be linked to the Photo class, but if the real class name is e.g. UberallPhoto or namespaced Uberall::Photo, you'll have to specify it with this option.
|
334
|
+
|
335
|
+
e.g.
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
module Uberall
|
339
|
+
class Location < LHS::Record
|
340
|
+
endpoint 'http://uberall/locations'
|
341
|
+
endpoint 'http://uberall/locations/:id'
|
342
|
+
|
343
|
+
has_many :photos, class_name: 'Uberall::Photo'
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
module Uberall
|
348
|
+
class Photo < LHS::Record
|
349
|
+
end
|
350
|
+
end
|
351
|
+
```
|
329
352
|
|
330
353
|
## Request based options
|
331
354
|
|
@@ -12,8 +12,10 @@ class LHS::Record
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
-
def has_many(
|
16
|
-
|
15
|
+
def has_many(*options)
|
16
|
+
name = options[0]
|
17
|
+
options = options[1] || {}
|
18
|
+
_relations[name] = { record_class_name: options.fetch(:class_name, name.to_s.singularize.classify) }
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -1,36 +1,73 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHS::Record do
|
4
|
+
|
5
|
+
let(:listing) { location.listings.first }
|
6
|
+
|
4
7
|
before(:each) do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
stub_request(:get, 'http://uberall/locations/1')
|
9
|
+
.to_return(body: {
|
10
|
+
listings: [{
|
11
|
+
directory: { name: 'Instagram' }
|
12
|
+
}]
|
13
|
+
}.to_json)
|
14
|
+
end
|
10
15
|
|
11
|
-
|
16
|
+
context 'has_many' do
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
before(:each) do
|
19
|
+
class Location < LHS::Record
|
20
|
+
endpoint 'http://uberall/locations'
|
21
|
+
endpoint 'http://uberall/locations/{id}'
|
22
|
+
has_many :listings
|
23
|
+
end
|
24
|
+
|
25
|
+
class Listing < LHS::Record
|
26
|
+
|
27
|
+
def supported?
|
28
|
+
true
|
29
|
+
end
|
15
30
|
end
|
16
31
|
end
|
17
|
-
end
|
18
32
|
|
19
|
-
context 'has_many' do
|
20
33
|
let(:location) { Location.find(1) }
|
21
|
-
|
34
|
+
|
35
|
+
it 'casts the relation into the correct type' do
|
36
|
+
expect(listing).to be_kind_of(Listing)
|
37
|
+
expect(listing.supported?).to eq true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'keeps hirachy when casting it to another class on access' do
|
41
|
+
expect(listing._root._raw).to eq location._raw
|
42
|
+
expect(listing.parent.parent._raw).to eq location._raw
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'custom class_name' do
|
22
47
|
|
23
48
|
before(:each) do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
49
|
+
module Uberall
|
50
|
+
class Location < LHS::Record
|
51
|
+
endpoint 'http://uberall/locations'
|
52
|
+
endpoint 'http://uberall/locations/{id}'
|
53
|
+
has_many :listings, class_name: 'Uberall::Listing'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module Uberall
|
58
|
+
class Listing < LHS::Record
|
59
|
+
|
60
|
+
def supported?
|
61
|
+
true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
30
65
|
end
|
31
66
|
|
67
|
+
let(:location) { Uberall::Location.find(1) }
|
68
|
+
|
32
69
|
it 'casts the relation into the correct type' do
|
33
|
-
expect(listing).to be_kind_of(Listing)
|
70
|
+
expect(listing).to be_kind_of(Uberall::Listing)
|
34
71
|
expect(listing.supported?).to eq true
|
35
72
|
end
|
36
73
|
|
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: 15.
|
4
|
+
version: 15.3.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: 2018-06-
|
11
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|