object_inspector 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -21
- data/lib/object_inspector/inspector.rb +4 -3
- data/lib/object_inspector/version.rb +1 -1
- data/lib/object_inspector.rb +18 -8
- data/object_inspector.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 050243c72935e87527820175e0eb7e5907ad45a25886aa36dd91ff72d5847578
|
4
|
+
data.tar.gz: e2c0975976e9e1c381412e04245486666bfa82c2d6aa547767957e0e9be3ba27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4670b2a2bcc06df1d1f37b6ded1c54da00e800a23a7326776af2785e1e4ae93967df61fc39685c1b62aa37c8872fd26c177f410123eed6c0d2240fb6d9ad177
|
7
|
+
data.tar.gz: 3b4f78ff90cc91e836356a1a76a6d21f0f63c69f40d66f9dfc07b554ba872e2357a67b8007486df5847fd28f593496358762a70bc0ce23f1749b651b4787d269
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.3.1 - 2018-04-15
|
2
|
+
- Add ObjectInspector::Configuration#formatter_class setting for overriding the default Formatter.
|
3
|
+
|
4
|
+
|
1
5
|
### 0.3.0 - 2018-04-14
|
2
6
|
|
3
7
|
- Remove optional dependency on ActiveSupport::StringInquirer. [Scopes are now objects](https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/scope.rb) that act like ActiveSupport::StringInquirer objects.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,11 @@
|
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/34e821263d9e0c33d536/test_coverage)](https://codeclimate.com/github/pdobb/object_inspector/test_coverage)
|
6
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/34e821263d9e0c33d536/maintainability)](https://codeclimate.com/github/pdobb/object_inspector/maintainability)
|
7
7
|
|
8
|
-
ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with an optional self-definable scope option to
|
8
|
+
ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with an optional, self-definable scope option to represents objects. Great for the console, logging, etc.
|
9
|
+
|
10
|
+
Because object inspection code should be easy to write and its output should be easy to read!
|
11
|
+
|
12
|
+
If you'd like to just jump into an example: [Full Example](#full-example).
|
9
13
|
|
10
14
|
|
11
15
|
## Installation
|
@@ -44,6 +48,8 @@ _Note: In a Rails app, the following would go in e.g. `config/initializers/objec
|
|
44
48
|
```ruby
|
45
49
|
# Default values are shown.
|
46
50
|
ObjectInspector.configure do |config|
|
51
|
+
config.formatter_class = ObjectInspector::TemplatingFormatter
|
52
|
+
config.inspect_method_prefix = "inspect"
|
47
53
|
config.wild_card_scope = "all"
|
48
54
|
config.out_of_scope_placeholder = "*"
|
49
55
|
config.flags_separator = " / "
|
@@ -87,7 +93,7 @@ end
|
|
87
93
|
MyObject.new.inspect # => "<My Object(FLAG1 / FLAG2) INFO :: NAME>"
|
88
94
|
```
|
89
95
|
|
90
|
-
Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and `inspect_name` as either public or private methods on Object.
|
96
|
+
Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) as either public or private methods on Object.
|
91
97
|
|
92
98
|
```ruby
|
93
99
|
class MyObject
|
@@ -100,7 +106,7 @@ private
|
|
100
106
|
def inspect_identification; "My Object" end
|
101
107
|
def inspect_flags; "FLAG1 / FLAG2" end
|
102
108
|
def inspect_info; "INFO" end
|
103
|
-
def inspect_name; "NAME" end
|
109
|
+
def inspect_name; "NAME" end # Or: def display_name; "NAME" end
|
104
110
|
end
|
105
111
|
|
106
112
|
MyObject.new.inspect # => "<My Object(FLAG1 / FLAG2) INFO :: NAME>"
|
@@ -136,7 +142,7 @@ end
|
|
136
142
|
MyObject.new.inspect # => "<My Object(FLAG1) INFO :: NAME>"
|
137
143
|
```
|
138
144
|
|
139
|
-
Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and `inspect_name` (or `display_name`) in Object.
|
145
|
+
Or, define `inspect_identification`, `inspect_flags`, `inspect_info`, and/or `inspect_name` (or `display_name`) in Object.
|
140
146
|
|
141
147
|
```ruby
|
142
148
|
class MyObject
|
@@ -232,22 +238,6 @@ scope.join_info([1, 2, 3]) # => "1 | 2 | 3"
|
|
232
238
|
```
|
233
239
|
|
234
240
|
|
235
|
-
### Conversion to ObjectInspector::Scope
|
236
|
-
|
237
|
-
ObjectInspector::Conversions.Scope() is available for proper conversion to ObjectInspector::Scope objects. Though this should rarely be necessary as conversion is performed automatically when calling `<my_object>.inspect(scope: <scope_name>)`.
|
238
|
-
|
239
|
-
```ruby
|
240
|
-
ObjectInspector::Conversions.Scope(:self)
|
241
|
-
# => #<ObjectInspector::Scope:0x007ff78ab8e7f8 @name="self">
|
242
|
-
|
243
|
-
scope = ObjectInspector::Scope.new(:verbose)
|
244
|
-
result = ObjectInspector::Conversions.Scope(scope)
|
245
|
-
# => #<ObjectInspector::Scope:0x007ff78ac9c140 @name="verbose">
|
246
|
-
|
247
|
-
scope.object_id == result.object_id # => true
|
248
|
-
```
|
249
|
-
|
250
|
-
|
251
241
|
## Full Example
|
252
242
|
|
253
243
|
```ruby
|
@@ -378,7 +368,7 @@ MyObject.new.inspect # => "<MyObject my_method2>"
|
|
378
368
|
|
379
369
|
## Custom Formatters
|
380
370
|
|
381
|
-
A custom inspect formatter can be defined by implementing the interface defined by [ObjectInspector::BaseFormatter](https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/base_formatter.rb)
|
371
|
+
A custom inspect formatter can be defined by implementing the interface defined by [ObjectInspector::BaseFormatter](https://github.com/pdobb/object_inspector/blob/master/lib/object_inspector/formatters/base_formatter.rb). Then, either override the ObjectInspector::Configuration#formatter_class value (see [Configuration](#configuration)) or just pass your custom class name into ObjectInspector::Inspector.new.
|
382
372
|
|
383
373
|
```ruby
|
384
374
|
class MyCustomFormatter < ObjectInspector::BaseFormatter
|
@@ -7,7 +7,8 @@ module ObjectInspector
|
|
7
7
|
# @attr scope [Symbol] Object inspection type. For example:
|
8
8
|
# :self (default) -- Means: Only interrogate self. Don't visit neighbors.
|
9
9
|
# <custom> -- Anything else that makes sense for {#object} to key on
|
10
|
-
# @attr formatter [ObjectInspector::BaseFormatter]
|
10
|
+
# @attr formatter [ObjectInspector::BaseFormatter]
|
11
|
+
# (ObjectInspector.configuration.formatter) the formatter object type
|
11
12
|
# to use for formatting the inspect String
|
12
13
|
# @attr kargs [Hash] options to be sent to {#object} via the
|
13
14
|
# {ObjectInspector::ObjectInterrogator} when calling the `inspect_*` methods
|
@@ -28,11 +29,11 @@ module ObjectInspector
|
|
28
29
|
def initialize(
|
29
30
|
object,
|
30
31
|
scope: :self,
|
31
|
-
formatter:
|
32
|
+
formatter: ObjectInspector.configuration.formatter_class,
|
32
33
|
**kargs)
|
33
34
|
@object = object
|
34
|
-
@formatter_klass = formatter
|
35
35
|
@scope = Conversions.Scope(scope)
|
36
|
+
@formatter_klass = formatter
|
36
37
|
@kargs = kargs
|
37
38
|
end
|
38
39
|
|
data/lib/object_inspector.rb
CHANGED
@@ -18,18 +18,32 @@ module ObjectInspector
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Configuration
|
21
|
-
attr_reader :
|
21
|
+
attr_reader :formatter_class,
|
22
|
+
:inspect_method_prefix,
|
23
|
+
:wild_card_scope,
|
22
24
|
:out_of_scope_placeholder,
|
23
25
|
:flags_separator,
|
24
|
-
:info_separator
|
25
|
-
:inspect_method_prefix
|
26
|
+
:info_separator
|
26
27
|
|
27
28
|
def initialize
|
29
|
+
@formatter_class = TemplatingFormatter
|
30
|
+
@inspect_method_prefix = "inspect".freeze
|
28
31
|
@wild_card_scope = "all".freeze
|
29
32
|
@out_of_scope_placeholder = "*".freeze
|
30
33
|
@flags_separator = " / ".freeze
|
31
34
|
@info_separator = " | ".freeze
|
32
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
def formatter_class=(value)
|
38
|
+
unless value.is_a?(Class)
|
39
|
+
raise TypeError, "Formatter must be a Class constant"
|
40
|
+
end
|
41
|
+
|
42
|
+
@formatter_class = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def inspect_method_prefix=(value)
|
46
|
+
@inspect_method_prefix = value.to_s.freeze
|
33
47
|
end
|
34
48
|
|
35
49
|
def wild_card_scope=(value)
|
@@ -47,10 +61,6 @@ module ObjectInspector
|
|
47
61
|
def info_separator=(value)
|
48
62
|
@info_separator = value.to_s.freeze
|
49
63
|
end
|
50
|
-
|
51
|
-
def inspect_method_prefix=(value)
|
52
|
-
@inspect_method_prefix = value.to_s.freeze
|
53
|
-
end
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
data/object_inspector.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["paul.dobbins@icloud.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{ObjectInspector generates uniformly formatted inspect output with customizable amounts of detail.}
|
13
|
-
spec.description = %q{ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with an optional self-definable scope option to
|
13
|
+
spec.description = %q{ObjectInspector takes Object#inspect to the next level. Specify any combination of identification attributes, flags, info, and/or a name along with an optional, self-definable scope option to represents objects. Great for the console, logging, etc.}
|
14
14
|
spec.homepage = "https://github.com/pdobb/object_inspector"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Dobbins
|
@@ -151,8 +151,9 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0.1'
|
153
153
|
description: ObjectInspector takes Object#inspect to the next level. Specify any combination
|
154
|
-
of identification attributes, flags, info, and/or a name along with an optional
|
155
|
-
self-definable scope option to
|
154
|
+
of identification attributes, flags, info, and/or a name along with an optional,
|
155
|
+
self-definable scope option to represents objects. Great for the console, logging,
|
156
|
+
etc.
|
156
157
|
email:
|
157
158
|
- paul.dobbins@icloud.com
|
158
159
|
executables: []
|