object_inspector 0.6.1 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +32 -25
- data/lib/object_inspector/conversions.rb +17 -17
- data/lib/object_inspector/formatters/base_formatter.rb +57 -59
- data/lib/object_inspector/formatters/combining_formatter.rb +44 -46
- data/lib/object_inspector/formatters/templating_formatter.rb +168 -202
- data/lib/object_inspector/inspector.rb +165 -161
- data/lib/object_inspector/inspectors_helper.rb +10 -12
- data/lib/object_inspector/object_interrogator.rb +35 -33
- data/lib/object_inspector/scope.rb +115 -106
- data/lib/object_inspector/version.rb +2 -1
- data/lib/object_inspector.rb +6 -0
- metadata +36 -30
- data/.gitignore +0 -11
- data/.rubocop +0 -4
- data/.rubocop.yml +0 -158
- data/.travis.yml +0 -21
- data/CHANGELOG.md +0 -45
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -97
- data/Rakefile +0 -12
- data/bin/console +0 -16
- data/bin/setup +0 -8
- data/object_inspector.gemspec +0 -47
- data/scripts/benchmarking/formatters.rb +0 -118
- data/scripts/benchmarking/object_inspector.rb +0 -74
@@ -1,243 +1,209 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@flags_and_info_template ||= "<%s(%s) %s>"
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.flags_and_issues_template
|
39
|
-
@flags_and_issues_template ||= "<%s(%s) !!%s!!>"
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.issues_and_info_template
|
43
|
-
@issues_and_info_template ||= "<%s !!%s!! %s>"
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.flags_and_issues_and_info_template
|
47
|
-
@flags_and_issues_and_info_template ||= "<%s(%s) !!%s!! %s>"
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.flags_and_issues_and_name_template
|
51
|
-
@flags_and_issues_and_name_template ||= "<%s(%s) !!%s!! :: %s>"
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.flags_and_info_and_name_template
|
55
|
-
@flags_and_info_and_name_template ||= "<%s(%s) %s :: %s>"
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.flags_and_issues_and_info_and_name_template
|
59
|
-
@flags_and_issues_and_info_and_name_template ||=
|
60
|
-
"<%s(%s) !!%s!! %s :: %s>"
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.flags_template
|
64
|
-
@flags_template ||= "<%s(%s)>"
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.issues_template
|
68
|
-
@issues_template ||= "<%s !!%s!!>"
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.info_template
|
72
|
-
@info_template ||= "<%s %s>"
|
73
|
-
end
|
3
|
+
# :reek:RepeatedConditional
|
4
|
+
# :reek:TooManyMethods
|
5
|
+
# rubocop:disable Metrics/ClassLength
|
6
|
+
|
7
|
+
# ObjectInspector::TemplatingFormatter specializes on
|
8
|
+
# {ObjectInspector::BaseFormatter} to return the standard/default inspect
|
9
|
+
# output format via String templates.
|
10
|
+
#
|
11
|
+
# @attr (see BaseFormatter)
|
12
|
+
class ObjectInspector::TemplatingFormatter < ObjectInspector::BaseFormatter
|
13
|
+
# Named String templates. Used by the build_* methods, these templates
|
14
|
+
# determine the format of the built output Strings.
|
15
|
+
def self.templates
|
16
|
+
@templates ||= {
|
17
|
+
base: "<%s>",
|
18
|
+
name: "<%s :: %s>",
|
19
|
+
issues_and_name: "<%s !!%s!! :: %s>",
|
20
|
+
flags_and_name: "<%s(%s) :: %s>",
|
21
|
+
info_and_name: "<%s %s :: %s>",
|
22
|
+
issues_and_info_and_name: "<%s !!%s!! %s :: %s>",
|
23
|
+
flags_and_info: "<%s(%s) %s>",
|
24
|
+
flags_and_issues: "<%s(%s) !!%s!!>",
|
25
|
+
issues_and_info: "<%s !!%s!! %s>",
|
26
|
+
flags_and_issues_and_info: "<%s(%s) !!%s!! %s>",
|
27
|
+
flags_and_issues_and_name: "<%s(%s) !!%s!! :: %s>",
|
28
|
+
flags_and_info_and_name: "<%s(%s) %s :: %s>",
|
29
|
+
flags_and_issues_and_info_and_name: "<%s(%s) !!%s!! %s :: %s>",
|
30
|
+
flags: "<%s(%s)>",
|
31
|
+
issues: "<%s !!%s!!>",
|
32
|
+
info: "<%s %s>",
|
33
|
+
}.freeze
|
34
|
+
end
|
74
35
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
36
|
+
# Perform the formatting routine.
|
37
|
+
#
|
38
|
+
# @return [String]
|
39
|
+
def call
|
40
|
+
if wrapped_object_inspection_result
|
41
|
+
build_wrapped_object_string
|
42
|
+
else
|
43
|
+
build_string
|
84
44
|
end
|
45
|
+
end
|
85
46
|
|
86
|
-
|
47
|
+
private
|
87
48
|
|
88
|
-
|
89
|
-
|
49
|
+
def build_wrapped_object_string
|
50
|
+
"#{build_string} "\
|
90
51
|
"#{ObjectInspector.configuration.presented_object_separator} "\
|
91
52
|
"#{wrapped_object_inspection_result}"
|
92
|
-
|
53
|
+
end
|
93
54
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
55
|
+
# rubocop:disable Metrics/MethodLength
|
56
|
+
def build_string
|
57
|
+
if flags
|
58
|
+
build_string_with_flags_and_maybe_issues_and_info_and_name
|
59
|
+
elsif issues
|
60
|
+
build_string_with_issues_and_maybe_info_and_name
|
61
|
+
elsif info
|
62
|
+
build_string_with_info_and_maybe_name
|
63
|
+
elsif name
|
64
|
+
build_string_with_name
|
65
|
+
else
|
66
|
+
build_base_string
|
107
67
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
68
|
+
end
|
69
|
+
# rubocop:enable Metrics/MethodLength
|
70
|
+
|
71
|
+
def build_string_with_flags_and_maybe_issues_and_info_and_name
|
72
|
+
if issues
|
73
|
+
build_string_with_flags_and_issues_and_maybe_info_and_name
|
74
|
+
elsif info
|
75
|
+
build_string_with_flags_and_info_and_maybe_name
|
76
|
+
elsif name
|
77
|
+
build_string_with_flags_and_name
|
78
|
+
else
|
79
|
+
build_string_with_flags
|
120
80
|
end
|
81
|
+
end
|
121
82
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
83
|
+
def build_string_with_flags_and_issues_and_maybe_info_and_name
|
84
|
+
if info
|
85
|
+
build_string_with_flags_and_issues_and_info_and_maybe_name
|
86
|
+
elsif name
|
87
|
+
build_string_with_flags_and_issues_and_name
|
88
|
+
else
|
89
|
+
build_string_with_flags_and_issues
|
130
90
|
end
|
91
|
+
end
|
131
92
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
93
|
+
def build_string_with_flags_and_issues_and_info_and_maybe_name
|
94
|
+
if name
|
95
|
+
build_string_with_flags_and_issues_and_info_and_name
|
96
|
+
else
|
97
|
+
build_string_with_flags_and_issues_and_info
|
138
98
|
end
|
99
|
+
end
|
139
100
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
101
|
+
def build_string_with_issues_and_maybe_info_and_name
|
102
|
+
if info
|
103
|
+
build_string_with_issues_and_info_and_maybe_name
|
104
|
+
elsif name
|
105
|
+
build_string_with_issues_and_name
|
106
|
+
else
|
107
|
+
build_string_with_issues
|
148
108
|
end
|
109
|
+
end
|
149
110
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
111
|
+
def build_string_with_issues_and_info_and_maybe_name
|
112
|
+
if name
|
113
|
+
build_string_with_issues_and_info_and_name
|
114
|
+
else
|
115
|
+
build_string_with_issues_and_info
|
156
116
|
end
|
117
|
+
end
|
157
118
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
119
|
+
def build_string_with_flags_and_info_and_maybe_name
|
120
|
+
if name
|
121
|
+
build_string_with_flags_and_info_and_name
|
122
|
+
else
|
123
|
+
build_string_with_flags_and_info
|
164
124
|
end
|
125
|
+
end
|
165
126
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
127
|
+
def build_string_with_info_and_maybe_name
|
128
|
+
if name
|
129
|
+
build_string_with_info_and_name
|
130
|
+
else
|
131
|
+
build_string_with_info
|
172
132
|
end
|
133
|
+
end
|
173
134
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
135
|
+
def build_string_with_flags_and_issues_and_info_and_name
|
136
|
+
template_for(:flags_and_issues_and_info_and_name) %
|
137
|
+
[identification, flags, issues, info, name]
|
138
|
+
end
|
178
139
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
140
|
+
def build_string_with_flags_and_issues_and_name
|
141
|
+
template_for(:flags_and_issues_and_name) %
|
142
|
+
[identification, flags, issues, name]
|
143
|
+
end
|
183
144
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
145
|
+
def build_string_with_flags_and_info_and_name
|
146
|
+
template_for(:flags_and_info_and_name) %
|
147
|
+
[identification, flags, info, name]
|
148
|
+
end
|
188
149
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
150
|
+
def build_string_with_issues_and_info_and_name
|
151
|
+
template_for(:issues_and_info_and_name) %
|
152
|
+
[identification, issues, info, name]
|
153
|
+
end
|
193
154
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
155
|
+
def build_string_with_flags_and_issues_and_info
|
156
|
+
template_for(:flags_and_issues_and_info) %
|
157
|
+
[identification, flags, issues, info]
|
158
|
+
end
|
198
159
|
|
199
|
-
|
200
|
-
|
201
|
-
|
160
|
+
def build_string_with_flags_and_issues
|
161
|
+
template_for(:flags_and_issues) % [identification, flags, issues]
|
162
|
+
end
|
202
163
|
|
203
|
-
|
204
|
-
|
205
|
-
|
164
|
+
def build_string_with_flags_and_info
|
165
|
+
template_for(:flags_and_info) % [identification, flags, info]
|
166
|
+
end
|
206
167
|
|
207
|
-
|
208
|
-
|
209
|
-
|
168
|
+
def build_string_with_flags_and_name
|
169
|
+
template_for(:flags_and_name) % [identification, flags, name]
|
170
|
+
end
|
210
171
|
|
211
|
-
|
212
|
-
|
213
|
-
|
172
|
+
def build_string_with_issues_and_info
|
173
|
+
template_for(:issues_and_info) % [identification, issues, info]
|
174
|
+
end
|
214
175
|
|
215
|
-
|
216
|
-
|
217
|
-
|
176
|
+
def build_string_with_issues_and_name
|
177
|
+
template_for(:issues_and_name) % [identification, issues, name]
|
178
|
+
end
|
218
179
|
|
219
|
-
|
220
|
-
|
221
|
-
|
180
|
+
def build_string_with_info_and_name
|
181
|
+
template_for(:info_and_name) % [identification, info, name]
|
182
|
+
end
|
222
183
|
|
223
|
-
|
224
|
-
|
225
|
-
|
184
|
+
def build_string_with_flags
|
185
|
+
template_for(:flags) % [identification, flags]
|
186
|
+
end
|
226
187
|
|
227
|
-
|
228
|
-
|
229
|
-
|
188
|
+
def build_string_with_issues
|
189
|
+
template_for(:issues) % [identification, issues]
|
190
|
+
end
|
230
191
|
|
231
|
-
|
232
|
-
|
233
|
-
|
192
|
+
def build_string_with_info
|
193
|
+
template_for(:info) % [identification, info]
|
194
|
+
end
|
234
195
|
|
235
|
-
|
236
|
-
|
237
|
-
|
196
|
+
def build_string_with_name
|
197
|
+
template_for(:name) % [identification, name]
|
198
|
+
end
|
238
199
|
|
239
|
-
|
240
|
-
|
241
|
-
|
200
|
+
def build_base_string
|
201
|
+
template_for(:base) % [identification]
|
202
|
+
end
|
203
|
+
|
204
|
+
def template_for(name)
|
205
|
+
self.class.templates.fetch(name)
|
242
206
|
end
|
243
207
|
end
|
208
|
+
|
209
|
+
# rubocop:enable Metrics/ClassLength
|