pretty_inspect 1.2.0 → 1.3.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/pretty_inspect.rb +11 -11
- 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: 80337a7d5553943cd4634450b52fe1626df09808
|
4
|
+
data.tar.gz: 8e130f287f236bc2090d710ed6b36f7cff8880f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5ed5da780d310463a49270c9dab5155a9bd4dcbb8facea9613302c40f0dd96037b59066efddfba5d9f6a3feef61902ac3a8b00c1d093a1324fe05b66927b374
|
7
|
+
data.tar.gz: bbc8859088bbe3de343feaea3e89b8d5d31721abd87ee5fb137fff1480b0de1671245631872245599abecdac6bc6f931e63465baebbd914ab87402feff8b41c0
|
data/lib/pretty_inspect.rb
CHANGED
@@ -31,19 +31,18 @@ class Object
|
|
31
31
|
# => nil
|
32
32
|
# irb>
|
33
33
|
|
34
|
-
def pretty_inspect(max_level=999)
|
35
|
-
@max_level = (max_level-1)
|
34
|
+
def pretty_inspect(max_level=999, is_activerecord=false)
|
36
35
|
object_ids = []
|
37
|
-
pretty_inspect_core("", self, 0, "", object_ids)
|
36
|
+
pretty_inspect_core("", self, 0, "", object_ids, max_level-1, is_activerecord)
|
38
37
|
end
|
39
38
|
|
40
39
|
private
|
41
40
|
|
42
|
-
def pretty_inspect_core(name, values, level, output, object_ids)
|
41
|
+
def pretty_inspect_core(name, values, level, output, object_ids, max_level, is_activerecord)
|
43
42
|
case values
|
44
43
|
when Array
|
45
44
|
output << "[\n"
|
46
|
-
if (level>>1) >
|
45
|
+
if (level>>1) > max_level
|
47
46
|
output << " "*(level+2)
|
48
47
|
output << "et.al.\n"
|
49
48
|
else
|
@@ -54,7 +53,7 @@ private
|
|
54
53
|
output << "[%s ...]"%name
|
55
54
|
else
|
56
55
|
object_ids.push(value.object_id)
|
57
|
-
pretty_inspect_core(name, value,level+2,output,object_ids)
|
56
|
+
pretty_inspect_core(name, value,level+2,output,object_ids, max_level-1, is_activerecord)
|
58
57
|
object_ids.pop
|
59
58
|
end
|
60
59
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
@@ -64,7 +63,7 @@ private
|
|
64
63
|
output << "]"
|
65
64
|
when Hash
|
66
65
|
output << "{\n"
|
67
|
-
if (level>>1) >
|
66
|
+
if (level>>1) > max_level
|
68
67
|
output << " "*(level+2)
|
69
68
|
output << "et.al.\n"
|
70
69
|
else
|
@@ -75,7 +74,7 @@ private
|
|
75
74
|
output << "{@%s ...}"%key
|
76
75
|
else
|
77
76
|
object_ids.push(value.object_id)
|
78
|
-
pretty_inspect_core(key, value,level+2,output,object_ids)
|
77
|
+
pretty_inspect_core(key, value,level+2,output,object_ids, max_level-1, is_activerecord)
|
79
78
|
object_ids.pop
|
80
79
|
end
|
81
80
|
output << (if (count -= 1) > 0 then ",\n" else "\n" end)
|
@@ -89,11 +88,12 @@ private
|
|
89
88
|
output << values.inspect
|
90
89
|
else
|
91
90
|
output << "<%s:%d\n"%[values.class.name,values.object_id]
|
92
|
-
if (level>>1) >
|
91
|
+
if (level>>1) > max_level
|
93
92
|
output << " "*(level+2)
|
94
93
|
output << "et.al.\n"
|
95
94
|
else
|
96
|
-
values.instance_variables.
|
95
|
+
items = if is_activerecord && values.instance_variables.index(:@attributes) then [:@attributes] else values.instance_variables end
|
96
|
+
items.each do |item|
|
97
97
|
value = values.instance_variable_get(item)
|
98
98
|
output << " "*(level+2)
|
99
99
|
case value
|
@@ -105,7 +105,7 @@ private
|
|
105
105
|
output << "<%s ...>"%item
|
106
106
|
else
|
107
107
|
object_ids.push(value.object_id)
|
108
|
-
pretty_inspect_core(item,value,level+2,output,object_ids)
|
108
|
+
pretty_inspect_core(item,value,level+2,output,object_ids, max_level-1, is_activerecord)
|
109
109
|
object_ids.pop
|
110
110
|
end
|
111
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael J. Welch, Ph.D.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Pretty Inspect can be used anywhere Object::inspect can be used, and produces a more human readable representation of the object.
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.0.7
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Pretty Inspect (pretty_inspect) is an extension to Object::inspect.
|