lhs 2.0.4 → 2.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 583ea8a5785e4d78e732150986bcb5a05f5f8397
4
- data.tar.gz: a488798e7c906e0806d8d0d78ea3e4b5be8c87e1
3
+ metadata.gz: bf11afeed9a8a7a43f2c594ad95dd909e1a12f0d
4
+ data.tar.gz: 885dacb37539493c398957242a4fba4c20e13a4f
5
5
  SHA512:
6
- metadata.gz: a0251caac24d2fd88395ac78af1a0e044b6f887f3750ff84fe1ccc9aa43ca42bf4dd80cbc11c450a793b9ee902bfdc621b7e3dba84fc938de38495c24de37282
7
- data.tar.gz: d7ca3bcc747f89051c5ad59294dc8046b5a2553ad50a6243110ecebf44d9e65ddb551a5a782da5025cda4cd16fec520a0258c0b70da82d07261e81b65361546c
6
+ metadata.gz: e854348297280962ce9553f22112b0f014462263f94eef3d18f870e4602524ac658679427927827230977c1052234d7dda39e6350b54bd1676599a1af83163c1
7
+ data.tar.gz: 760777a4f2e23e6a31509aa436417ce5abcff5a60805b5ec56a81fbe75594ac7b5562738179c16418b6c4203ae3563127e3729de94763924b392be4dcdd28506
@@ -45,39 +45,33 @@ class LHS::Service
45
45
  end
46
46
  end
47
47
 
48
- def handle_includes(data)
48
+ def handle_includes(includes, data)
49
49
  if includes.is_a? Hash
50
- includes.keys.each { |key| handle_include(data, key) }
50
+ includes.each { |_include, sub_includes| handle_include(_include, data, sub_includes) }
51
51
  elsif includes.is_a? Array
52
- includes.each { |key| handle_include(data, key) }
52
+ includes.each { |_include| handle_includes(_include, data) }
53
53
  else
54
- handle_include(data, includes)
54
+ handle_include(includes, data)
55
55
  end
56
56
  end
57
57
 
58
- def handle_include(data, key)
58
+ def handle_include(_include, data, sub_includes = nil)
59
59
  return unless data.present?
60
60
  options = if data._proxy.is_a? LHS::Collection
61
- options_for_multiple(data, key)
61
+ options_for_multiple(data, _include)
62
62
  else
63
- url_option_for(data, key)
63
+ url_option_for(data, _include)
64
64
  end
65
- addition = load_include(includes, options, key, data)
66
- extend(data, addition, key)
65
+ addition = load_include(options, data, sub_includes)
66
+ extend(data, addition, _include)
67
67
  end
68
68
 
69
69
  # Load additional resources that are requested with include
70
- def load_include(includes, options, key, data)
70
+ def load_include(options, data, sub_includes)
71
71
  service = service_for_options(options) || self
72
72
  options = convert_options_to_endpoints(options) if service_for_options(options)
73
- further_keys = includes.fetch(key, nil) if includes.is_a? Hash
74
- service_class = if further_keys
75
- service.class.includes(further_keys)
76
- else
77
- service.class.includes(nil)
78
- end
79
73
  begin
80
- service_class.instance.request(options)
74
+ service.class.includes(sub_includes).instance.request(options)
81
75
  rescue LHC::NotFound
82
76
  LHS::Data.new({}, data, service)
83
77
  end
@@ -96,7 +90,7 @@ class LHS::Service
96
90
  responses = LHC.request(options)
97
91
  data = responses.map{ |response| LHS::Data.new(response.body, nil, self.class, response.request) }
98
92
  data = LHS::Data.new(data, nil, self.class)
99
- handle_includes(data) if includes
93
+ handle_includes(includes, data) if includes
100
94
  data
101
95
  end
102
96
 
@@ -136,7 +130,7 @@ class LHS::Service
136
130
  def single_request(options)
137
131
  response = LHC.request(process_options(options))
138
132
  data = LHS::Data.new(response.body, nil, self.class, response.request)
139
- handle_includes(data) if includes
133
+ handle_includes(includes, data) if includes
140
134
  data
141
135
  end
142
136
 
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "2.0.4"
2
+ VERSION = "2.0.5"
3
3
  end
@@ -120,6 +120,21 @@ describe LHS::Service do
120
120
  expect(feedbacks.campaign.user.name).to eq 'Mario'
121
121
  end
122
122
 
123
+ it 'includes list of linked resources while fetching a single resource from one service' do
124
+
125
+ stub_request(:get, "#{datastore}/feedbacks/123")
126
+ .to_return(status: 200, body: {
127
+ 'href' => "#{datastore}/feedbacks/-Sc4_pYNpqfsudzhtivfkA",
128
+ 'campaign' => { 'href' => "#{datastore}/content-ads/51dfc5690cf271c375c5a12d" },
129
+ 'user' => { 'href' => "#{datastore}/users/lakj35asdflkj1203va" }
130
+ }.to_json)
131
+
132
+ feedbacks = Feedback.includes(:user, campaign: [:entry, :user]).find(123)
133
+ expect(feedbacks.campaign.entry.name).to eq 'Casa Ferlin'
134
+ expect(feedbacks.campaign.user.name).to eq 'Mario'
135
+ expect(feedbacks.user.name).to eq 'Mario'
136
+ end
137
+
123
138
  context 'include objects from known services' do
124
139
 
125
140
  let(:stub_feedback_request) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch