object_inspector 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,243 +1,209 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectInspector
4
- # ObjectInspector::TemplatingFormatter implements
5
- # {ObjectInspector::BaseFormatter} to return the standard/default inspect
6
- # output format via String templates.
7
- #
8
- # @attr (see BaseFormatter)
9
- class TemplatingFormatter < BaseFormatter
10
- def self.base_template
11
- @base_template ||= "<%s>"
12
- end
13
-
14
- def self.name_template
15
- @name_template ||= "<%s :: %s>"
16
- end
17
-
18
- def self.issues_and_name_template
19
- @issues_and_name_template ||= "<%s !!%s!! :: %s>"
20
- end
21
-
22
- def self.flags_and_name_template
23
- @flags_and_name_template ||= "<%s(%s) :: %s>"
24
- end
25
-
26
- def self.info_and_name_template
27
- @info_and_name_template ||= "<%s %s :: %s>"
28
- end
29
-
30
- def self.issues_and_info_and_name_template
31
- @issues_and_info_and_name_template ||= "<%s !!%s!! %s :: %s>"
32
- end
33
-
34
- def self.flags_and_info_template
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
- # Perform the formatting routine.
76
- #
77
- # @return [String]
78
- def call
79
- if wrapped_object_inspection_result
80
- build_wrapped_object_string
81
- else
82
- build_string
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
- private
47
+ private
87
48
 
88
- def build_wrapped_object_string
89
- "#{build_string} "\
49
+ def build_wrapped_object_string
50
+ "#{build_string} "\
90
51
  "#{ObjectInspector.configuration.presented_object_separator} "\
91
52
  "#{wrapped_object_inspection_result}"
92
- end
53
+ end
93
54
 
94
- # rubocop:disable Metrics/MethodLength
95
- def build_string
96
- if flags
97
- build_string_with_flags_and_maybe_issues_and_info_and_name
98
- elsif issues
99
- build_string_with_issues_and_maybe_info_and_name
100
- elsif info
101
- build_string_with_info_and_maybe_name
102
- elsif name
103
- build_string_with_name
104
- else
105
- build_base_string
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
- # rubocop:enable Metrics/MethodLength
109
-
110
- def build_string_with_flags_and_maybe_issues_and_info_and_name
111
- if issues
112
- build_string_with_flags_and_issues_and_maybe_info_and_name
113
- elsif info
114
- build_string_with_flags_and_info_and_maybe_name
115
- elsif name
116
- build_string_with_flags_and_name
117
- else
118
- build_string_with_flags
119
- end
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
- def build_string_with_flags_and_issues_and_maybe_info_and_name
123
- if info
124
- build_string_with_flags_and_issues_and_info_and_maybe_name
125
- elsif name
126
- build_string_with_flags_and_issues_and_name
127
- else
128
- build_string_with_flags_and_issues
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
- def build_string_with_flags_and_issues_and_info_and_maybe_name
133
- if name
134
- build_string_with_flags_and_issues_and_info_and_name
135
- else
136
- build_string_with_flags_and_issues_and_info
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
- def build_string_with_issues_and_maybe_info_and_name
141
- if info
142
- build_string_with_issues_and_info_and_maybe_name
143
- elsif name
144
- build_string_with_issues_and_name
145
- else
146
- build_string_with_issues
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
- def build_string_with_issues_and_info_and_maybe_name
151
- if name
152
- build_string_with_issues_and_info_and_name
153
- else
154
- build_string_with_issues_and_info
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
- def build_string_with_flags_and_info_and_maybe_name
159
- if name
160
- build_string_with_flags_and_info_and_name
161
- else
162
- build_string_with_flags_and_info
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
- def build_string_with_info_and_maybe_name
167
- if name
168
- build_string_with_info_and_name
169
- else
170
- build_string_with_info
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
- def build_string_with_flags_and_issues_and_info_and_name
175
- self.class.flags_and_issues_and_info_and_name_template %
176
- [identification, flags, issues, info, name]
177
- end
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
- def build_string_with_flags_and_issues_and_name
180
- self.class.flags_and_issues_and_name_template %
181
- [identification, flags, issues, name]
182
- end
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
- def build_string_with_flags_and_info_and_name
185
- self.class.flags_and_info_and_name_template %
186
- [identification, flags, info, name]
187
- end
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
- def build_string_with_issues_and_info_and_name
190
- self.class.issues_and_info_and_name_template %
191
- [identification, issues, info, name]
192
- end
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
- def build_string_with_flags_and_issues_and_info
195
- self.class.flags_and_issues_and_info_template %
196
- [identification, flags, issues, info]
197
- end
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
- def build_string_with_flags_and_issues
200
- self.class.flags_and_issues_template % [identification, flags, issues]
201
- end
160
+ def build_string_with_flags_and_issues
161
+ template_for(:flags_and_issues) % [identification, flags, issues]
162
+ end
202
163
 
203
- def build_string_with_flags_and_info
204
- self.class.flags_and_info_template % [identification, flags, info]
205
- end
164
+ def build_string_with_flags_and_info
165
+ template_for(:flags_and_info) % [identification, flags, info]
166
+ end
206
167
 
207
- def build_string_with_flags_and_name
208
- self.class.flags_and_name_template % [identification, flags, name]
209
- end
168
+ def build_string_with_flags_and_name
169
+ template_for(:flags_and_name) % [identification, flags, name]
170
+ end
210
171
 
211
- def build_string_with_issues_and_info
212
- self.class.issues_and_info_template % [identification, issues, info]
213
- end
172
+ def build_string_with_issues_and_info
173
+ template_for(:issues_and_info) % [identification, issues, info]
174
+ end
214
175
 
215
- def build_string_with_issues_and_name
216
- self.class.issues_and_name_template % [identification, issues, name]
217
- end
176
+ def build_string_with_issues_and_name
177
+ template_for(:issues_and_name) % [identification, issues, name]
178
+ end
218
179
 
219
- def build_string_with_info_and_name
220
- self.class.info_and_name_template % [identification, info, name]
221
- end
180
+ def build_string_with_info_and_name
181
+ template_for(:info_and_name) % [identification, info, name]
182
+ end
222
183
 
223
- def build_string_with_flags
224
- self.class.flags_template % [identification, flags]
225
- end
184
+ def build_string_with_flags
185
+ template_for(:flags) % [identification, flags]
186
+ end
226
187
 
227
- def build_string_with_issues
228
- self.class.issues_template % [identification, issues]
229
- end
188
+ def build_string_with_issues
189
+ template_for(:issues) % [identification, issues]
190
+ end
230
191
 
231
- def build_string_with_info
232
- self.class.info_template % [identification, info]
233
- end
192
+ def build_string_with_info
193
+ template_for(:info) % [identification, info]
194
+ end
234
195
 
235
- def build_string_with_name
236
- self.class.name_template % [identification, name]
237
- end
196
+ def build_string_with_name
197
+ template_for(:name) % [identification, name]
198
+ end
238
199
 
239
- def build_base_string
240
- self.class.base_template % [identification]
241
- end
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