lhs 15.2.5 → 15.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74a7df6c84bd30e35e9a0d4fe14bd0d4023c71e0
4
- data.tar.gz: 899c8e3029fbee1bc9f42b68022eb0fd38d4fc5a
3
+ metadata.gz: 0ece53bf6cdb9d5fb129509f6e58645d8fcc7968
4
+ data.tar.gz: a033797e5a4628d2e941eae1888655d1d4c4ff96
5
5
  SHA512:
6
- metadata.gz: 2dba61e4adcd12cd589c585bdf3d4fc96647b015c331d3b8ff55a681089019fe3f19f4f68860fb2b4a224332a3af447b701c1f05de7b59ead1f4459cc8cc60a5
7
- data.tar.gz: 94e90e2cb651d2518b138cf76691f6dbc8c544ab14e619cb23c1dd1fc67e29680d3b93ac16e8471ce019ff4457de5fd1e4d60b2fa29fd2fa0fe392bec20f1bee
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(name)
16
- _relations[name] = { record_class_name: name.to_s.singularize.classify }
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
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '15.2.5'
2
+ VERSION = '15.3.0'
3
3
  end
@@ -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
- class Location < LHS::Record
6
- endpoint 'http://uberall/locations'
7
- endpoint 'http://uberall/locations/{id}'
8
- has_many :listings
9
- end
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
- class Listing < LHS::Record
16
+ context 'has_many' do
12
17
 
13
- def supported?
14
- true
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
- let(:listing) { location.listings.first }
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
- stub_request(:get, 'http://uberall/locations/1')
25
- .to_return(body: {
26
- listings: [{
27
- directory: { name: 'Instagram' }
28
- }]
29
- }.to_json)
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.2.5
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-06 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc