object_identifier 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -33
- data/lib/core_ext/object.rb +0 -8
- data/lib/object_identifier/formatters/string_formatter.rb +6 -6
- data/lib/object_identifier/version.rb +1 -1
- data/lib/object_identifier.rb +0 -3
- metadata +2 -5
- data/lib/core_ext/big_decimal.rb +0 -17
- data/lib/core_ext/string.rb +0 -17
- data/lib/core_ext/symbol.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '094534f4602cabb611358d4935e2ea86b9f5904537d63ca7cee56e5fad764211'
|
4
|
+
data.tar.gz: 033ba507ffe4a2ff276b7bd41a8f69dd84c610b13bba7a6427e3033f7904792e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e782bac889af1fc3c4db0f65b43a00386553e992bd0c8b90d2a705d56507d72a0f7367edbd6e051f4b49e1a97265a783815775bad51b92fd08d55f140d9c2cdf
|
7
|
+
data.tar.gz: 65da82e615b7ce4b1e4c53007c2e659df7e68fe5d968e8bc4b7f616629319400b015284d53624ce43c5611ed84eb722e2b5002f800fa4832131fb06817ef6be7
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/github/v/release/pdobb/object_identifier)](https://img.shields.io/github/v/release/pdobb/object_identifier)
|
4
4
|
[![CI Actions](https://github.com/pdobb/object_identifier/actions/workflows/ci.yml/badge.svg)](https://github.com/pdobb/object_identifier/actions)
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/0b737a72d16ec755c1ff/maintainability)](https://codeclimate.com/github/pdobb/object_identifier/maintainability)
|
6
5
|
|
7
6
|
Object Identifier allows quick, easy, and uniform identification of an object by inspecting its class name and outputting any desirable attributes/methods. It is great for logging, sending descriptive notification messages, etc.
|
8
7
|
|
@@ -133,36 +132,6 @@ The number of results that will be identified from a collection can be truncated
|
|
133
132
|
{}.identify # => [no objects]
|
134
133
|
```
|
135
134
|
|
136
|
-
## Custom Object Identifiers
|
137
|
-
|
138
|
-
Internally, Object Identifier calls `inspect_lit` to return a "literally-inspected" string representation of an object. This works because Object, itself, is monkey-patched to define `inspect_lit` which just returns `inspect`. This is sufficient for most objects, but some objects will benefit from defining special output from `inspect_lit`.
|
139
|
-
|
140
|
-
Object Identifier defines `inspect_lit` on three other core objects: String, Symbol, and BigDecimal.
|
141
|
-
|
142
|
-
```ruby
|
143
|
-
"a_string".inspect_lit # => "\"a_string\""
|
144
|
-
:a_symbol.inspect_lit # => ":\"a_symbol\""
|
145
|
-
BigDecimal(1.99, 3).inspect_lit # => "<BD:1.99>"
|
146
|
-
```
|
147
|
-
|
148
|
-
To identify an object in a special way, just define `inspect_lit` to return a custom String.
|
149
|
-
|
150
|
-
```ruby
|
151
|
-
class MyValueObject
|
152
|
-
def initialize(val)
|
153
|
-
@val = val
|
154
|
-
end
|
155
|
-
|
156
|
-
def inspect_lit
|
157
|
-
"#{@val} Meters"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
my_value_object = MyValueObject.new(42)
|
162
|
-
OpenStruct.new(my_value: my_value_object).identify(:my_value)
|
163
|
-
# => "OpenStruct[my_value:42 Meters]"
|
164
|
-
```
|
165
|
-
|
166
135
|
## Supporting Gems
|
167
136
|
|
168
137
|
Object Identifier works great with the [Object Inspector](https://github.com/pdobb/object_inspector) gem.
|
@@ -191,7 +160,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
191
160
|
|
192
161
|
### Testing
|
193
162
|
|
194
|
-
To test this gem
|
163
|
+
To test this gem:
|
195
164
|
|
196
165
|
```bash
|
197
166
|
rake
|
@@ -210,7 +179,7 @@ npx prettier . --write
|
|
210
179
|
|
211
180
|
### Releases
|
212
181
|
|
213
|
-
To release a new version of
|
182
|
+
To release a new version of this gem to RubyGems:
|
214
183
|
|
215
184
|
1. Update the version number in `version.rb`
|
216
185
|
2. Update `CHANGELOG.md`
|
data/lib/core_ext/object.rb
CHANGED
@@ -2,14 +2,6 @@
|
|
2
2
|
|
3
3
|
# Reopen the core Object class to add {#identify} to all objects.
|
4
4
|
class Object
|
5
|
-
# Standard #inspect for any object that doesn't override this method. This
|
6
|
-
# method is meant to make an object's type inherently obvious inspected.
|
7
|
-
#
|
8
|
-
# @return [String] a String-literal representation of this object
|
9
|
-
def inspect_lit
|
10
|
-
inspect
|
11
|
-
end
|
12
|
-
|
13
5
|
# Instance method for constructing a self-identifying string for any given
|
14
6
|
# object or list of objects.
|
15
7
|
#
|
@@ -23,14 +23,14 @@ class ObjectIdentifier::StringFormatter < ObjectIdentifier::BaseFormatter
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
def format_collection
|
27
|
-
Collection.new(objects, parameters).call
|
28
|
-
end
|
29
|
-
|
30
26
|
def format_item(object = objects.first)
|
31
27
|
Item.new(object, parameters).call
|
32
28
|
end
|
33
29
|
|
30
|
+
def format_collection
|
31
|
+
Collection.new(objects, parameters).call
|
32
|
+
end
|
33
|
+
|
34
34
|
# ObjectIdentifier::StringFormatter::Collection formats a collection-specific
|
35
35
|
# identification String, which will also necessarily be composed of
|
36
36
|
# {ObjectIdentifier::StringFormatter::Item} identification Strings.
|
@@ -122,9 +122,9 @@ class ObjectIdentifier::StringFormatter < ObjectIdentifier::BaseFormatter
|
|
122
122
|
def attributes_formatter
|
123
123
|
@attributes_formatter ||=
|
124
124
|
if attributes_hash.one?
|
125
|
-
->(_key, value) { value.
|
125
|
+
->(_key, value) { value.inspect }
|
126
126
|
else # attributes_hash.size > 1
|
127
|
-
->(key, value) { "#{key}:#{value.
|
127
|
+
->(key, value) { "#{key}:#{value.inspect}" }
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
data/lib/object_identifier.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_identifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul DobbinSchmaltz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -63,10 +63,7 @@ extra_rdoc_files: []
|
|
63
63
|
files:
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
|
-
- lib/core_ext/big_decimal.rb
|
67
66
|
- lib/core_ext/object.rb
|
68
|
-
- lib/core_ext/string.rb
|
69
|
-
- lib/core_ext/symbol.rb
|
70
67
|
- lib/object_identifier.rb
|
71
68
|
- lib/object_identifier/array_wrap.rb
|
72
69
|
- lib/object_identifier/configuration.rb
|
data/lib/core_ext/big_decimal.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "bigdecimal"
|
4
|
-
|
5
|
-
# Reopen the core BigDecimal class to represent {#inspect_lit}.
|
6
|
-
class BigDecimal
|
7
|
-
# Formats this BigDecimal as an object-type-revealing String.
|
8
|
-
#
|
9
|
-
# @return [String] a String representation of this BigDecimal object
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
# BigDecimal.new(1).inspect_lit # => "<BD:1.0>"
|
13
|
-
# BigDecimal.new(99.999, 5).inspect_lit # => "<BD:99.999>"
|
14
|
-
def inspect_lit
|
15
|
-
"<BD:#{self}>"
|
16
|
-
end
|
17
|
-
end
|
data/lib/core_ext/string.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Reopen the core String class to represent {#inspect_lit}.
|
4
|
-
class String
|
5
|
-
# Formats self to look like a String literal so that object type will be
|
6
|
-
# inherently obvious when inspected.
|
7
|
-
#
|
8
|
-
# @return [String] a String-literal representation of this object
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# "test".inspect_lit # => "\"test\"" (i.e. '"test"')
|
12
|
-
# "1".inspect_lit # => "\"1\"" (i.e. '"1"')
|
13
|
-
# "12.3".inspect_lit # => "\"12.3\"" (i.e. '"12.3"')
|
14
|
-
def inspect_lit
|
15
|
-
%("#{self}")
|
16
|
-
end
|
17
|
-
end
|
data/lib/core_ext/symbol.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Reopen the core Symbol class to represent {#inspect_lit}.
|
4
|
-
class Symbol
|
5
|
-
# Formats this symbol to look like a symbol literal so that object type will
|
6
|
-
# be inherently obvious when used in logging methods, etc.
|
7
|
-
#
|
8
|
-
# @return [String] a symbol literal representation of this object
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# :test.inspect_lit # => ":\"test\"" (or ':"test"')
|
12
|
-
# :"ta-da!".inspect_lit # => ":\"ta-da!\"" (or ':"ta-da!"')
|
13
|
-
def inspect_lit
|
14
|
-
%(:"#{self}")
|
15
|
-
end
|
16
|
-
end
|