lhs 7.0.3 → 7.1.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/lib/lhs/concerns/inspect.rb +37 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/data/inspect_spec.rb +55 -1
- metadata +3 -5
- data/spec/record/inspect_spec.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1020f5e98607e2dc01ebebe52f23961c9e9a4034
|
4
|
+
data.tar.gz: b15fddb284dcdca4254c155e07d09075a5dacfe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0106d5e6468c5a81a60e3fe216406225fa937364884def8a8e1d5c6ce6065259c306909f7e25bea56eee9f8fbcf67df42490974ee672b2596dd23803c2e938f
|
7
|
+
data.tar.gz: 5a22af86fa15061d27946df81439b75a8dde9773be8d8ff7c7bceda700f50c632a3d1f75678408875ce6b916a7fbecaf40a331322cb68ad3c426a5657cfa9c80
|
data/lib/lhs/concerns/inspect.rb
CHANGED
@@ -5,13 +5,49 @@ module Inspect
|
|
5
5
|
|
6
6
|
def inspect
|
7
7
|
[
|
8
|
-
|
8
|
+
[
|
9
|
+
[
|
10
|
+
[
|
11
|
+
to_s.match('LHS::Data') ? 'Data of ' : nil,
|
12
|
+
self.class
|
13
|
+
].join,
|
14
|
+
_inspect_id
|
15
|
+
].join(' '),
|
16
|
+
_inspect_path
|
17
|
+
].compact.join("\n"),
|
9
18
|
pretty_raw
|
10
19
|
].compact.join("\n")
|
11
20
|
end
|
12
21
|
|
13
22
|
private
|
14
23
|
|
24
|
+
def _inspect_id
|
25
|
+
_root.href || (_root.item? ? _root.id : nil) || object_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def _inspect_path
|
29
|
+
current = self
|
30
|
+
path = []
|
31
|
+
_collect_parents_for_inspect!(path, current)
|
32
|
+
return unless path.present?
|
33
|
+
"> #{path.reverse.join(' > ')}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def _collect_parents_for_inspect!(path, current)
|
37
|
+
return unless current.parent
|
38
|
+
parent_raw = current.parent._raw
|
39
|
+
if parent_raw.is_a?(Array)
|
40
|
+
parent_raw.each_with_index do |element, index|
|
41
|
+
path.push(index) if element == current._raw
|
42
|
+
end
|
43
|
+
elsif parent_raw.is_a?(Hash)
|
44
|
+
parent_raw.each do |key, value|
|
45
|
+
path.push(key) if value == current._raw
|
46
|
+
end
|
47
|
+
end
|
48
|
+
_collect_parents_for_inspect!(path, current.parent)
|
49
|
+
end
|
50
|
+
|
15
51
|
def pretty_raw
|
16
52
|
return if _raw.blank?
|
17
53
|
if _raw.is_a?(Array)
|
data/lib/lhs/version.rb
CHANGED
data/spec/data/inspect_spec.rb
CHANGED
@@ -2,9 +2,14 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe LHS::Data do
|
4
4
|
context 'inspect' do
|
5
|
+
def expect_inspect_to_look_like(data, string)
|
6
|
+
expect(data.inspect).to eq string.gsub(/ +/, '').strip
|
7
|
+
end
|
8
|
+
|
5
9
|
before(:each) do
|
6
10
|
class Record < LHS::Record
|
7
11
|
endpoint 'http://local.ch/records'
|
12
|
+
endpoint 'http://local.ch/records/:id'
|
8
13
|
end
|
9
14
|
end
|
10
15
|
|
@@ -21,12 +26,61 @@ describe LHS::Data do
|
|
21
26
|
] }
|
22
27
|
end
|
23
28
|
|
29
|
+
let(:record) do
|
30
|
+
stub_request(:get, 'http://local.ch/records/1').to_return(body: raw.to_json)
|
31
|
+
Record.find(1)
|
32
|
+
end
|
33
|
+
|
24
34
|
let(:data) do
|
25
35
|
LHS::Data.new(raw, nil, Record).pets.first
|
26
36
|
end
|
27
37
|
|
28
38
|
it 'prints inspected data on multiple lines' do
|
29
|
-
|
39
|
+
expect_inspect_to_look_like data, %Q{
|
40
|
+
Data of Record #{data.object_id}
|
41
|
+
> pets > 0
|
42
|
+
:name => \"Steve\"
|
43
|
+
:kind => {:animal=>{:type=>\"Monkey\"}}
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'breadcrumb' do
|
48
|
+
let(:data) { record.pets.first.kind.animal }
|
49
|
+
|
50
|
+
it 'prints the breadcrumb that shows you the current location within the main record' do
|
51
|
+
expect_inspect_to_look_like data, %Q{
|
52
|
+
Data of Record #{data.object_id}
|
53
|
+
> pets > 0 > kind > animal
|
54
|
+
:type => \"Monkey\"
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'href as id' do
|
60
|
+
let(:href) { 'http://datastore/places/1' }
|
61
|
+
let(:raw) { { href: href, items: [{ name: 'Steve' }] } }
|
62
|
+
let(:data) { record.first }
|
63
|
+
|
64
|
+
it 'prints href as object id' do
|
65
|
+
expect_inspect_to_look_like data, %Q{
|
66
|
+
Record #{href}
|
67
|
+
:name => \"Steve\"
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'id attribute as id' do
|
73
|
+
let(:id) { 1 }
|
74
|
+
let(:raw) { { id: id, name: 'Steve' } }
|
75
|
+
let(:data) { record }
|
76
|
+
|
77
|
+
it 'prints id attribute as object id' do
|
78
|
+
expect_inspect_to_look_like data, %Q{
|
79
|
+
Record #{id}
|
80
|
+
:id => 1
|
81
|
+
:name => \"Steve\"
|
82
|
+
}
|
83
|
+
end
|
30
84
|
end
|
31
85
|
end
|
32
86
|
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: 7.0
|
4
|
+
version: 7.1.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: 2016-12-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -325,7 +325,6 @@ files:
|
|
325
325
|
- spec/record/first_spec.rb
|
326
326
|
- spec/record/immutable_chains_spec.rb
|
327
327
|
- spec/record/includes_spec.rb
|
328
|
-
- spec/record/inspect_spec.rb
|
329
328
|
- spec/record/loading_twice_spec.rb
|
330
329
|
- spec/record/mapping_spec.rb
|
331
330
|
- spec/record/model_name_spec.rb
|
@@ -374,7 +373,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
374
373
|
requirements:
|
375
374
|
- Ruby >= 2.0.0
|
376
375
|
rubyforge_project:
|
377
|
-
rubygems_version: 2.
|
376
|
+
rubygems_version: 2.6.8
|
378
377
|
signing_key:
|
379
378
|
specification_version: 4
|
380
379
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|
@@ -476,7 +475,6 @@ test_files:
|
|
476
475
|
- spec/record/first_spec.rb
|
477
476
|
- spec/record/immutable_chains_spec.rb
|
478
477
|
- spec/record/includes_spec.rb
|
479
|
-
- spec/record/inspect_spec.rb
|
480
478
|
- spec/record/loading_twice_spec.rb
|
481
479
|
- spec/record/mapping_spec.rb
|
482
480
|
- spec/record/model_name_spec.rb
|
data/spec/record/inspect_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe LHS::Record do
|
4
|
-
before(:each) do
|
5
|
-
class Record < LHS::Record
|
6
|
-
endpoint 'http://datastore/records/:id'
|
7
|
-
end
|
8
|
-
stub_request(:get, "http://datastore/records/1")
|
9
|
-
.to_return(body: attrbitutes.to_json)
|
10
|
-
end
|
11
|
-
|
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\"}}" }
|
25
|
-
|
26
|
-
context 'inspect' do
|
27
|
-
it 'prints the record on the terminal: each attrbitute on a new line' do
|
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
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|