lhs 6.3.0 → 6.3.1
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/lib/lhs/record.rb +8 -15
- data/lib/lhs/version.rb +1 -1
- data/spec/record/create_spec.rb +1 -1
- data/spec/record/endpoint_misconfiguration_spec.rb +3 -2
- data/spec/record/inspect_spec.rb +28 -9
- data/spec/record/new_spec.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9f38d7e7d79b9099b282d29cdd8c126d9ec2a97
|
|
4
|
+
data.tar.gz: b01e749df675ef68f1a13923a7d73b2317a58614
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac30a7cd582675b6ba8d7b02748563b64ee6c572858102dcccd9be8db7e70213575dc5a35ded169449d738c78d6a79636df1eb35b0ffe48f068814038c59be93
|
|
7
|
+
data.tar.gz: 8eb224deb70fa275b5ea13722854ee1d4a971f9ffa509c468aafd74dbf7684edc2a0d37551ff876733d87137b82386cd50c41b18cb9797f07217495b43ca5b68
|
data/lib/lhs/record.rb
CHANGED
|
@@ -25,7 +25,7 @@ class LHS::Record
|
|
|
25
25
|
data = LHS::Data.new({}, nil, self.class) unless data
|
|
26
26
|
data = LHS::Data.new(data, nil, self.class) unless data.is_a?(LHS::Data)
|
|
27
27
|
define_singleton_method(:_data) { data }
|
|
28
|
-
|
|
28
|
+
apply_custom_setters!
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def as_json(options = nil)
|
|
@@ -48,20 +48,13 @@ class LHS::Record
|
|
|
48
48
|
|
|
49
49
|
private
|
|
50
50
|
|
|
51
|
-
def
|
|
52
|
-
return if !
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def instance_data
|
|
61
|
-
if _data._proxy.is_a?(LHS::Collection) && _data._raw.is_a?(Hash)
|
|
62
|
-
_data._raw.fetch(:items, [])
|
|
63
|
-
else
|
|
64
|
-
_data._raw
|
|
51
|
+
def apply_custom_setters!
|
|
52
|
+
return if !_data.item? || !_data._raw.respond_to?(:keys)
|
|
53
|
+
raw = _data._raw
|
|
54
|
+
custom_setters = raw.keys.find_all { |key| public_methods.include?("#{key}=".to_sym) }
|
|
55
|
+
custom_setters.each do |setter|
|
|
56
|
+
value = raw.delete(setter)
|
|
57
|
+
send("#{setter}=", value)
|
|
65
58
|
end
|
|
66
59
|
end
|
|
67
60
|
end
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/create_spec.rb
CHANGED
|
@@ -10,7 +10,8 @@ describe LHS::Record do
|
|
|
10
10
|
endpoint ':datastore/v2/reviews'
|
|
11
11
|
end
|
|
12
12
|
}
|
|
13
|
-
).to raise_error
|
|
13
|
+
).to raise_error(/Clashing endpoints/)
|
|
14
|
+
|
|
14
15
|
expect(
|
|
15
16
|
lambda {
|
|
16
17
|
class Record < LHS::Record
|
|
@@ -18,7 +19,7 @@ describe LHS::Record do
|
|
|
18
19
|
endpoint ':datastore/v2/:campaign_id/reviews'
|
|
19
20
|
end
|
|
20
21
|
}
|
|
21
|
-
).to raise_error
|
|
22
|
+
).to raise_error(/Clashing endpoints/)
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
end
|
data/spec/record/inspect_spec.rb
CHANGED
|
@@ -6,21 +6,40 @@ describe LHS::Record do
|
|
|
6
6
|
endpoint 'http://datastore/records/:id'
|
|
7
7
|
end
|
|
8
8
|
stub_request(:get, "http://datastore/records/1")
|
|
9
|
-
.to_return(body:
|
|
10
|
-
name: 'Steve',
|
|
11
|
-
kind: {
|
|
12
|
-
animal: {
|
|
13
|
-
type: 'Monkey'
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}.to_json)
|
|
9
|
+
.to_return(body: attrbitutes.to_json)
|
|
17
10
|
end
|
|
18
11
|
|
|
19
12
|
let(:record) { Record.find(1) }
|
|
13
|
+
let(:attrbitutes) do
|
|
14
|
+
{
|
|
15
|
+
name: 'Steve',
|
|
16
|
+
kind: {
|
|
17
|
+
animal: {
|
|
18
|
+
type: 'Monkey'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:output) { "Record##{record.object_id}\n:name => \"Steve\"\n:kind => {:animal=>{:type=>\"Monkey\"}}" }
|
|
20
25
|
|
|
21
26
|
context 'inspect' do
|
|
22
27
|
it 'prints the record on the terminal: each attrbitute on a new line' do
|
|
23
|
-
expect(record.inspect).to eq
|
|
28
|
+
expect(record.inspect).to eq(output)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'with custom setters that do no touch raw data' do
|
|
32
|
+
before do
|
|
33
|
+
class Record
|
|
34
|
+
attr_accessor :listing
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
let(:record) { Record.new(attrbitutes.merge(listing: double('listing'))) }
|
|
39
|
+
|
|
40
|
+
it 'does not print what is not in raw' do
|
|
41
|
+
expect(record.inspect).to eq(output)
|
|
42
|
+
end
|
|
24
43
|
end
|
|
25
44
|
end
|
|
26
45
|
end
|
data/spec/record/new_spec.rb
CHANGED
|
@@ -65,6 +65,26 @@ describe LHS::Record do
|
|
|
65
65
|
expect(feedback.ratings.first.name).to eq :z
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
context 'that do not affect raw data' do
|
|
69
|
+
before(:each) do
|
|
70
|
+
class Rating
|
|
71
|
+
attr_accessor :listing
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
let(:listing) { double('listing') }
|
|
76
|
+
|
|
77
|
+
it 'are used by initializer' do
|
|
78
|
+
feedback = Rating.new(listing: listing)
|
|
79
|
+
expect(feedback.listing).to eq(listing)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'do not set raw data' do
|
|
83
|
+
feedback = Rating.new(listing: listing)
|
|
84
|
+
expect(feedback._raw[:listing]).to be_nil
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
68
88
|
context 'and custom getters' do
|
|
69
89
|
before(:each) do
|
|
70
90
|
class Rating
|
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: 6.3.
|
|
4
|
+
version: 6.3.1
|
|
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-08-
|
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lhc
|
|
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
351
351
|
requirements:
|
|
352
352
|
- Ruby >= 2.0.0
|
|
353
353
|
rubyforge_project:
|
|
354
|
-
rubygems_version: 2.
|
|
354
|
+
rubygems_version: 2.6.5
|
|
355
355
|
signing_key:
|
|
356
356
|
specification_version: 4
|
|
357
357
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|