lhs 6.1.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/concerns/inspect.rb +30 -0
- data/lib/lhs/data.rb +1 -5
- data/lib/lhs/record.rb +1 -4
- data/lib/lhs/version.rb +1 -1
- data/spec/data/inspect_spec.rb +14 -6
- data/spec/record/inspect_spec.rb +26 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caf31c361c00c17b98b17004fc597f5c89bfece9
|
4
|
+
data.tar.gz: 54d832a896d135a0a5a7e84818cffb2aae0adcae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 416221fb3dc29dd39925000e38cb7a8549712eff5a33cb45a74d1a5f3d54a3060a8d384154d526a82bad2e42b59b8ba92d661c5dffac10cdbce5919669c4f082
|
7
|
+
data.tar.gz: c07cf8c431c91fcb11fd17e852032693547526b1b018a527920d28dddac661ec3e576a034e6441092082a0ec0d0e36dba6658207b46262d70a87fffb6370e32e
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Inspect
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def inspect
|
7
|
+
[
|
8
|
+
"#{to_s.match('LHS::Data') ? 'Data of ' : nil}#{self.class}##{object_id}",
|
9
|
+
pretty_raw
|
10
|
+
].compact.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def pretty_raw
|
16
|
+
return if _raw.blank?
|
17
|
+
if _raw.is_a?(Array)
|
18
|
+
_raw
|
19
|
+
else
|
20
|
+
_raw.to_a.map do |key, value|
|
21
|
+
":#{key} => " +
|
22
|
+
if value.is_a? String
|
23
|
+
"\"#{value}\""
|
24
|
+
else
|
25
|
+
value.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end.join("\n")
|
29
|
+
end
|
30
|
+
end
|
data/lib/lhs/data.rb
CHANGED
@@ -6,6 +6,7 @@ class LHS::Data
|
|
6
6
|
include Equality
|
7
7
|
include Json
|
8
8
|
include ToHash
|
9
|
+
include Inspect
|
9
10
|
|
10
11
|
delegate :instance_methods, :items_key, :limit_key, :total_key, :pagination_key, to: :class
|
11
12
|
|
@@ -75,11 +76,6 @@ class LHS::Data
|
|
75
76
|
_proxy.respond_to?(name, include_all)
|
76
77
|
end
|
77
78
|
|
78
|
-
def inspect_with_focus
|
79
|
-
_raw
|
80
|
-
end
|
81
|
-
alias_method_chain :inspect, :focus
|
82
|
-
|
83
79
|
private
|
84
80
|
|
85
81
|
def collection_proxy?(input)
|
data/lib/lhs/record.rb
CHANGED
@@ -12,6 +12,7 @@ class LHS::Record
|
|
12
12
|
include FindBy
|
13
13
|
include First
|
14
14
|
include Includes
|
15
|
+
include Inspect
|
15
16
|
include Mapping
|
16
17
|
include Model
|
17
18
|
include Pagination
|
@@ -35,10 +36,6 @@ class LHS::Record
|
|
35
36
|
new(data)
|
36
37
|
end
|
37
38
|
|
38
|
-
def inspect
|
39
|
-
"<#{self.class}#{_data._raw}>"
|
40
|
-
end
|
41
|
-
|
42
39
|
protected
|
43
40
|
|
44
41
|
def method_missing(name, *args, &block)
|
data/lib/lhs/version.rb
CHANGED
data/spec/data/inspect_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHS::Data do
|
4
|
-
context '
|
4
|
+
context 'inspect' do
|
5
5
|
before(:each) do
|
6
6
|
class Record < LHS::Record
|
7
7
|
endpoint 'http://local.ch/records'
|
@@ -9,16 +9,24 @@ describe LHS::Data do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:raw) do
|
12
|
-
{
|
12
|
+
{ pets: [
|
13
|
+
{
|
14
|
+
name: 'Steve',
|
15
|
+
kind: {
|
16
|
+
animal: {
|
17
|
+
type: 'Monkey'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
] }
|
13
22
|
end
|
14
23
|
|
15
24
|
let(:data) do
|
16
|
-
LHS::Data.new(raw, nil, Record)
|
25
|
+
LHS::Data.new(raw, nil, Record).pets.first
|
17
26
|
end
|
18
27
|
|
19
|
-
it '
|
20
|
-
expect(data.inspect).to eq
|
21
|
-
expect(data.inspect_without_focus).to include 'LHS::Data'
|
28
|
+
it 'prints inspected data on multiple lines' do
|
29
|
+
expect(data.inspect).to eq "Data of Record##{data.object_id}\n:name => \"Steve\"\n:kind => {:animal=>{:type=>\"Monkey\"}}"
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -0,0 +1,26 @@
|
|
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: {
|
10
|
+
name: 'Steve',
|
11
|
+
kind: {
|
12
|
+
animal: {
|
13
|
+
type: 'Monkey'
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}.to_json)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:record) { Record.find(1) }
|
20
|
+
|
21
|
+
context 'inspect' do
|
22
|
+
it 'prints the record on the terminal: each attrbitute on a new line' do
|
23
|
+
expect(record.inspect).to eq "Record##{record.object_id}\n:name => \"Steve\"\n:kind => {:animal=>{:type=>\"Monkey\"}}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
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: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- lib/lhs/concerns/data/equality.rb
|
181
181
|
- lib/lhs/concerns/data/json.rb
|
182
182
|
- lib/lhs/concerns/data/to_hash.rb
|
183
|
+
- lib/lhs/concerns/inspect.rb
|
183
184
|
- lib/lhs/concerns/item/destroy.rb
|
184
185
|
- lib/lhs/concerns/item/save.rb
|
185
186
|
- lib/lhs/concerns/item/update.rb
|
@@ -300,6 +301,7 @@ files:
|
|
300
301
|
- spec/record/first_spec.rb
|
301
302
|
- spec/record/immutable_chains_spec.rb
|
302
303
|
- spec/record/includes_spec.rb
|
304
|
+
- spec/record/inspect_spec.rb
|
303
305
|
- spec/record/loading_twice_spec.rb
|
304
306
|
- spec/record/mapping_spec.rb
|
305
307
|
- spec/record/model_name_spec.rb
|
@@ -443,6 +445,7 @@ test_files:
|
|
443
445
|
- spec/record/first_spec.rb
|
444
446
|
- spec/record/immutable_chains_spec.rb
|
445
447
|
- spec/record/includes_spec.rb
|
448
|
+
- spec/record/inspect_spec.rb
|
446
449
|
- spec/record/loading_twice_spec.rb
|
447
450
|
- spec/record/mapping_spec.rb
|
448
451
|
- spec/record/model_name_spec.rb
|