lhs 11.0.1 → 11.0.2
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/lhs.gemspec +1 -1
- data/lib/lhs/concerns/proxy/accessors.rb +31 -14
- data/lib/lhs/concerns/record/configuration.rb +3 -1
- data/lib/lhs/concerns/record/request.rb +12 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/proxy/record_identification_spec.rb +33 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43edcbb95ff9fac3487269d82e907074ebd34c77
|
4
|
+
data.tar.gz: 4c0b1606d84502bcbf2868cf0bacef57d6d189d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2a9cd34ef7a3cb2967590b19e950e9925c71d1d9f9208d72a9a032bc2cdca061ce787ca2ab8447bfe5f3ea31fc971eed87f91fa24e1880b486b0016e897a57e
|
7
|
+
data.tar.gz: c1b547a13121304b67706163dbb5124cee91d9e4107e16e1dd1bf57abe55fc05c1a35e243b8fd0c9c401d3d92ae34f5baeb57c01e0a3bfac10676a1637ff1c3b
|
data/lhs.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.requirements << 'Ruby >= 2.0.0'
|
21
21
|
s.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
|
-
s.add_dependency 'lhc', '>= 5.0.
|
23
|
+
s.add_dependency 'lhc', '>= 5.0.3'
|
24
24
|
s.add_dependency 'activesupport', '> 4.2'
|
25
25
|
|
26
26
|
s.add_development_dependency 'rspec-rails', '>= 3.0.0'
|
@@ -23,9 +23,24 @@ class LHS::Proxy
|
|
23
23
|
value = _data._raw[name.to_s.classify.to_sym] if value.nil?
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
record = LHS::Record.for_url(value[:href]) if value.is_a?(Hash) && value[:href]
|
27
|
+
|
28
|
+
access_item(value, record) ||
|
29
|
+
access_collection(value, record) ||
|
30
|
+
convert(value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def accessing_item?(value, record)
|
34
|
+
return false unless value.is_a?(Hash)
|
35
|
+
return false if record && value[record.items_key].present?
|
36
|
+
return false if !record && value[LHS::Record::Configuration::DEFAULT_ITEMS_KEY].present?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def accessing_collection?(value, record)
|
41
|
+
return true if value.is_a?(Array)
|
42
|
+
return true if value.is_a?(Hash) && record && value[record.items_key].present?
|
43
|
+
return true if value.is_a?(Hash) && !record && value[LHS::Record::Configuration::DEFAULT_ITEMS_KEY].present?
|
29
44
|
end
|
30
45
|
|
31
46
|
def convert(value)
|
@@ -39,20 +54,22 @@ class LHS::Proxy
|
|
39
54
|
end
|
40
55
|
end
|
41
56
|
|
42
|
-
def access_item(value)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
def access_item(value, record)
|
58
|
+
return unless accessing_item?(value, record)
|
59
|
+
wrap_return(value, record)
|
60
|
+
end
|
61
|
+
|
62
|
+
def access_collection(value, record)
|
63
|
+
return unless accessing_collection?(value, record)
|
64
|
+
collection_data = LHS::Data.new(value, _data)
|
65
|
+
collection = LHS::Collection.new(collection_data)
|
66
|
+
wrap_return(collection, record)
|
50
67
|
end
|
51
68
|
|
52
|
-
def
|
69
|
+
def wrap_return(value, record)
|
53
70
|
data = LHS::Data.new(value, _data)
|
54
|
-
|
55
|
-
|
71
|
+
return record.new(data) if record
|
72
|
+
data
|
56
73
|
end
|
57
74
|
|
58
75
|
def date?(value)
|
@@ -7,6 +7,8 @@ class LHS::Record
|
|
7
7
|
module Configuration
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
+
DEFAULT_ITEMS_KEY = :items
|
11
|
+
|
10
12
|
mattr_accessor :configuration
|
11
13
|
|
12
14
|
module ClassMethods
|
@@ -15,7 +17,7 @@ class LHS::Record
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def items_key
|
18
|
-
(@configuration.try(:[], :items_key) ||
|
20
|
+
(@configuration.try(:[], :items_key) || DEFAULT_ITEMS_KEY).to_sym
|
19
21
|
end
|
20
22
|
|
21
23
|
def limit_key
|
@@ -49,11 +49,22 @@ class LHS::Record
|
|
49
49
|
endpoint = LHS::Endpoint.for_url(url)
|
50
50
|
return unless endpoint
|
51
51
|
template = endpoint.url
|
52
|
-
new_options = options.deep_merge(
|
52
|
+
new_options = options.deep_merge(
|
53
|
+
params: LHC::Endpoint.values_as_params(template, url).merge(values_from_get_params(url))
|
54
|
+
)
|
53
55
|
new_options[:url] = template
|
54
56
|
new_options
|
55
57
|
end
|
56
58
|
|
59
|
+
# Extracts values from url's get parameters
|
60
|
+
# and return them as a ruby hash
|
61
|
+
def values_from_get_params(url)
|
62
|
+
uri = URI.parse(url)
|
63
|
+
return {} unless uri.query.present?
|
64
|
+
params = Rack::Utils.parse_nested_query(uri.query)
|
65
|
+
params
|
66
|
+
end
|
67
|
+
|
57
68
|
# Extends existing raw data with additionaly fetched data
|
58
69
|
def extend_raw_data!(data, addition, key)
|
59
70
|
if data.collection?
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Proxy do
|
4
|
+
before(:each) do
|
5
|
+
class Search < LHS::Record
|
6
|
+
endpoint 'http://search/results', items_key: :docs
|
7
|
+
end
|
8
|
+
|
9
|
+
class Feedback < LHS::Record
|
10
|
+
endpoint 'http://datastore/places/:place_id/feedbacks'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'identifying records' do
|
15
|
+
it 'identifies records correctly even if parent record has another configuration set' do
|
16
|
+
stub_request(:get, "http://search/results?what=Blumen")
|
17
|
+
.to_return(body: {
|
18
|
+
place: { href: 'http://datastore/places/1' }
|
19
|
+
}.to_json)
|
20
|
+
stub_request(:get, "http://datastore/places/1")
|
21
|
+
.to_return(body: {
|
22
|
+
feedbacks: { href: 'http://datastore/places/1/feedbacks?limit=10&offset=0' }
|
23
|
+
}.to_json)
|
24
|
+
stub_request(:get, "http://datastore/places/1/feedbacks?limit=10&offset=0")
|
25
|
+
.to_return(body: {
|
26
|
+
items: [{ review: 'Nice restaurant' }]
|
27
|
+
}.to_json)
|
28
|
+
result = Search.where(what: 'Blumen').includes(place: :feedbacks)
|
29
|
+
expect(result.place.feedbacks).to be_kind_of Feedback
|
30
|
+
expect(result.place.feedbacks.first.review).to eq 'Nice restaurant'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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: 11.0.
|
4
|
+
version: 11.0.2
|
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: 2017-05-
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.0.
|
19
|
+
version: 5.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.0.
|
26
|
+
version: 5.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -308,6 +308,7 @@ files:
|
|
308
308
|
- spec/pagination/pages_left_spec.rb
|
309
309
|
- spec/proxy/create_sub_resource_spec.rb
|
310
310
|
- spec/proxy/load_spec.rb
|
311
|
+
- spec/proxy/record_identification_spec.rb
|
311
312
|
- spec/rails_helper.rb
|
312
313
|
- spec/record/all_spec.rb
|
313
314
|
- spec/record/build_spec.rb
|
@@ -469,6 +470,7 @@ test_files:
|
|
469
470
|
- spec/pagination/pages_left_spec.rb
|
470
471
|
- spec/proxy/create_sub_resource_spec.rb
|
471
472
|
- spec/proxy/load_spec.rb
|
473
|
+
- spec/proxy/record_identification_spec.rb
|
472
474
|
- spec/rails_helper.rb
|
473
475
|
- spec/record/all_spec.rb
|
474
476
|
- spec/record/build_spec.rb
|