object_identifier 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop +4 -0
- data/.rubocop.yml +105 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +17 -6
- data/Gemfile +2 -0
- data/Gemfile.lock +56 -30
- data/README.md +20 -18
- data/Rakefile +3 -1
- data/bin/console +2 -0
- data/lib/{object_identifier/core_ext → core_ext}/big_decimal.rb +3 -0
- data/lib/{object_identifier/core_ext → core_ext}/object.rb +5 -2
- data/lib/{object_identifier/core_ext → core_ext}/string.rb +4 -1
- data/lib/{object_identifier/core_ext → core_ext}/symbol.rb +4 -1
- data/lib/object_identifier.rb +9 -4
- data/lib/object_identifier/identifier.rb +41 -12
- data/lib/object_identifier/version.rb +3 -1
- data/object_identifier.gemspec +16 -11
- metadata +79 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbab525606ca826781627ff66be0e57229d14be19e2d19d562f5f73d7b2b7a5d
|
4
|
+
data.tar.gz: b266c154b7c283721b335d752b40705b3ba9000ad46d0ad8689a1f7654249c54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b83e5d96392c489dd19a32d265602161069db563c7bda67a4aa88eb28eca6ea26ffdf3641b52a060482493717c1f652b190b6545547b6ae4cadfa1cee3360451
|
7
|
+
data.tar.gz: 26f3c65910cd39d01e51af199b57f5a8fee3d1ddbe79f67b69552b0abf9c5f9da9752e8947afa0f663aa53e84f0968940cae59d9735a9f5c3745329ad778839d
|
data/.rubocop
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
AllCops:
|
2
|
+
UseCache: true
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
ExtraDetails: false
|
6
|
+
TargetRubyVersion: 2.4.0
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Layout/DotPosition:
|
10
|
+
EnforcedStyle: trailing
|
11
|
+
|
12
|
+
Layout/EndOfLine:
|
13
|
+
EnforcedStyle: lf
|
14
|
+
|
15
|
+
Layout/FirstArgumentIndentation:
|
16
|
+
EnforcedStyle: consistent_relative_to_receiver
|
17
|
+
|
18
|
+
Layout/FirstArrayElementIndentation:
|
19
|
+
EnforcedStyle: consistent
|
20
|
+
|
21
|
+
Layout/FirstHashElementIndentation:
|
22
|
+
EnforcedStyle: consistent
|
23
|
+
|
24
|
+
Layout/FirstParameterIndentation:
|
25
|
+
Enabled: false # Revisit if more settings become available.
|
26
|
+
|
27
|
+
Layout/MultilineMethodCallBraceLayout:
|
28
|
+
EnforcedStyle: same_line
|
29
|
+
|
30
|
+
Layout/MultilineMethodCallIndentation:
|
31
|
+
EnforcedStyle: indented_relative_to_receiver
|
32
|
+
|
33
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
34
|
+
EnforcedStyle: same_line
|
35
|
+
|
36
|
+
Layout/MultilineOperationIndentation:
|
37
|
+
Enabled: false # Waiting for e.g. `indented_relative_to_receiver`.
|
38
|
+
|
39
|
+
Lint/AmbiguousOperator:
|
40
|
+
Enabled: false # Conflicts with other rules.
|
41
|
+
|
42
|
+
Lint/AmbiguousRegexpLiteral:
|
43
|
+
Enabled: false # Conflicts with other rules.
|
44
|
+
|
45
|
+
Lint/Void:
|
46
|
+
CheckForMethodsWithNoSideEffects: true
|
47
|
+
|
48
|
+
Metrics/BlockLength:
|
49
|
+
ExcludedMethods:
|
50
|
+
- describe
|
51
|
+
- context
|
52
|
+
- ips # Benchmarking
|
53
|
+
|
54
|
+
Metrics/ClassLength:
|
55
|
+
Exclude:
|
56
|
+
- "test/**/*"
|
57
|
+
|
58
|
+
Metrics/LineLength:
|
59
|
+
Max: 80
|
60
|
+
Exclude:
|
61
|
+
- "object_identifier.gemspec"
|
62
|
+
|
63
|
+
Naming/MethodParameterName:
|
64
|
+
AllowedNames:
|
65
|
+
- a
|
66
|
+
- b
|
67
|
+
|
68
|
+
Style/Alias:
|
69
|
+
EnforcedStyle: prefer_alias_method
|
70
|
+
|
71
|
+
Style/BlockDelimiters:
|
72
|
+
Enabled: false # Reconsider later.
|
73
|
+
|
74
|
+
Style/EmptyElse:
|
75
|
+
# It"s helpful to show intent by including a comment in an else block.
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/EmptyMethod:
|
79
|
+
EnforcedStyle: expanded
|
80
|
+
|
81
|
+
Style/ExpandPathArguments:
|
82
|
+
Exclude:
|
83
|
+
- "object_inspector.gemspec"
|
84
|
+
|
85
|
+
Style/FormatString:
|
86
|
+
Enabled: false # % notation with an Array just reads better sometimes.
|
87
|
+
|
88
|
+
Style/Lambda:
|
89
|
+
EnforcedStyle: literal
|
90
|
+
|
91
|
+
Style/RegexpLiteral:
|
92
|
+
EnforcedStyle: mixed
|
93
|
+
|
94
|
+
Style/RescueStandardError:
|
95
|
+
EnforcedStyle: implicit
|
96
|
+
|
97
|
+
Style/SingleLineMethods:
|
98
|
+
Exclude:
|
99
|
+
- "test/**/*_test.rb"
|
100
|
+
|
101
|
+
Style/StringLiterals:
|
102
|
+
EnforcedStyle: double_quotes
|
103
|
+
|
104
|
+
Style/StringLiteralsInInterpolation:
|
105
|
+
EnforcedStyle: double_quotes
|
data/.travis.yml
CHANGED
@@ -4,14 +4,12 @@ env:
|
|
4
4
|
sudo: false
|
5
5
|
language: ruby
|
6
6
|
rvm:
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- 2.5.1
|
11
|
-
- ruby-head
|
7
|
+
- 2.4.9
|
8
|
+
- 2.5.8
|
9
|
+
- 2.6.6
|
12
10
|
notifications:
|
13
11
|
email: false
|
14
|
-
before_install: gem install bundler -v 1.
|
12
|
+
before_install: gem install bundler -v 2.1.4
|
15
13
|
cache: bundler
|
16
14
|
before_script:
|
17
15
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
-
### 0.
|
1
|
+
### 0.4.0 - 2020-09-01
|
2
|
+
- [#4](https://github.com/pdobb/object_identifier/pull/4) Only show attribute names if identifying more than one attribute.
|
3
|
+
- Update development dependencies.
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
* Now returns "[no objects]" even if given a :klass option
|
5
|
+
#### BREAKING
|
6
|
+
- Drop support for Ruby 2.3.
|
6
7
|
|
8
|
+
### 0.3.0 - 2019-06-27
|
9
|
+
- Fix identification of objects that implement `to_a`, such as Struct.
|
10
|
+
|
11
|
+
### 0.2.1 - 2019-02-24
|
12
|
+
- Add ability to identify instance vars.
|
13
|
+
|
14
|
+
### 0.1.0 - 2018-04-14
|
15
|
+
- Revamp gem.
|
16
|
+
- Update gem dependencies.
|
17
|
+
- Now returns "[no objects]" even if given a :klass option.
|
7
18
|
|
8
|
-
### 0.0.6 - 2016-02-06
|
9
19
|
|
10
|
-
|
20
|
+
### 0.0.6 - 2016-02-06
|
21
|
+
- Fix: identify method now supports private & protected methods.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,51 +1,77 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
object_identifier (0.
|
4
|
+
object_identifier (0.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ansi (1.5.0)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
minitest
|
10
|
+
ast (2.4.1)
|
11
|
+
builder (3.2.4)
|
12
|
+
byebug (11.1.3)
|
13
|
+
coderay (1.1.3)
|
14
|
+
docile (1.3.2)
|
15
|
+
kwalify (0.7.2)
|
16
|
+
method_source (1.0.0)
|
17
|
+
minitest (5.14.2)
|
18
|
+
minitest-reporters (1.4.2)
|
18
19
|
ansi
|
19
20
|
builder
|
20
21
|
minitest (>= 5.0)
|
21
22
|
ruby-progressbar
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
pry
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
parallel (1.19.2)
|
24
|
+
parser (2.7.1.4)
|
25
|
+
ast (~> 2.4.1)
|
26
|
+
pry (0.13.1)
|
27
|
+
coderay (~> 1.1)
|
28
|
+
method_source (~> 1.0)
|
29
|
+
pry-byebug (3.9.0)
|
30
|
+
byebug (~> 11.0)
|
31
|
+
pry (~> 0.13.0)
|
32
|
+
psych (3.1.0)
|
33
|
+
rainbow (3.0.0)
|
34
|
+
rake (13.0.1)
|
35
|
+
reek (6.0.1)
|
36
|
+
kwalify (~> 0.7.0)
|
37
|
+
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
|
38
|
+
psych (~> 3.1.0)
|
39
|
+
rainbow (>= 2.0, < 4.0)
|
40
|
+
regexp_parser (1.7.1)
|
41
|
+
rexml (3.2.4)
|
42
|
+
rubocop (0.90.0)
|
43
|
+
parallel (~> 1.10)
|
44
|
+
parser (>= 2.7.1.1)
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
46
|
+
regexp_parser (>= 1.7)
|
47
|
+
rexml
|
48
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
49
|
+
ruby-progressbar (~> 1.7)
|
50
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
51
|
+
rubocop-ast (0.3.0)
|
52
|
+
parser (>= 2.7.1.4)
|
53
|
+
ruby-progressbar (1.10.1)
|
54
|
+
simplecov (0.19.0)
|
31
55
|
docile (~> 1.1)
|
32
|
-
|
33
|
-
|
34
|
-
|
56
|
+
simplecov-html (~> 0.11)
|
57
|
+
simplecov-html (0.12.2)
|
58
|
+
unicode-display_width (1.7.0)
|
35
59
|
|
36
60
|
PLATFORMS
|
37
61
|
ruby
|
38
62
|
|
39
63
|
DEPENDENCIES
|
40
|
-
bundler
|
41
|
-
byebug
|
42
|
-
minitest
|
43
|
-
minitest-reporters
|
64
|
+
bundler
|
65
|
+
byebug
|
66
|
+
minitest
|
67
|
+
minitest-reporters
|
44
68
|
object_identifier!
|
45
|
-
pry
|
46
|
-
pry-byebug
|
47
|
-
rake
|
48
|
-
|
69
|
+
pry
|
70
|
+
pry-byebug
|
71
|
+
rake
|
72
|
+
reek
|
73
|
+
rubocop
|
74
|
+
simplecov
|
49
75
|
|
50
76
|
BUNDLED WITH
|
51
|
-
1.
|
77
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Object Identifier
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/object_identifier.
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/object_identifier.svg)](https://badge.fury.io/rb/object_identifier)
|
4
4
|
[![Build Status](https://travis-ci.org/pdobb/object_identifier.svg?branch=master)](https://travis-ci.org/pdobb/object_identifier)
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/0b737a72d16ec755c1ff/test_coverage)](https://codeclimate.com/github/pdobb/object_identifier/test_coverage)
|
6
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/0b737a72d16ec755c1ff/maintainability)](https://codeclimate.com/github/pdobb/object_identifier/maintainability)
|
7
7
|
|
8
|
-
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
|
8
|
+
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.
|
9
9
|
|
10
10
|
For example:
|
11
11
|
|
@@ -16,7 +16,7 @@ some_object.identify(:id, :name)
|
|
16
16
|
Which is the same as:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
"#{some_object.class.name}[id:#{some_object.id}, name
|
19
|
+
"#{some_object.class.name}[id:#{some_object.id}, name:\"#{some_object.name}\"]"
|
20
20
|
```
|
21
21
|
|
22
22
|
|
@@ -40,11 +40,9 @@ Or install it yourself as:
|
|
40
40
|
## Compatibility
|
41
41
|
|
42
42
|
Tested MRI Ruby Versions:
|
43
|
-
* 2.
|
44
|
-
* 2.
|
45
|
-
* 2.
|
46
|
-
* 2.5.1
|
47
|
-
* edge
|
43
|
+
* 2.4.9
|
44
|
+
* 2.5.8
|
45
|
+
* 2.6.6
|
48
46
|
|
49
47
|
|
50
48
|
## Usage
|
@@ -54,33 +52,38 @@ Tested MRI Ruby Versions:
|
|
54
52
|
`identify` outputs the `id` of the receiving object by default, if it exists and no other attributes/methods are specified.
|
55
53
|
|
56
54
|
```ruby
|
57
|
-
my_movie.identify
|
58
|
-
my_movie.identify(:rating) # => Movie[rating:"7/10"]
|
55
|
+
my_movie.identify # => Movie[1]
|
59
56
|
```
|
60
57
|
|
61
|
-
|
58
|
+
`identify` doesn't output labels if only identifying a single attribute/method. It includes labels when two or more attributes/methods are being identified.
|
62
59
|
|
63
60
|
```ruby
|
64
|
-
my_movie.identify(:
|
61
|
+
my_movie.identify(:id) # => Movie[1]
|
62
|
+
my_movie.identify(:rating) # => Movie["7/10"]
|
63
|
+
my_movie.identify(:id, :rating) # => Movie[id:1, rating:"7/10"]
|
65
64
|
```
|
66
65
|
|
66
|
+
Private methods can be identified just the same as public methods.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
my_movie.identify(:my_private_method) # => Movie["Shh"]
|
70
|
+
```
|
67
71
|
|
68
72
|
### Unknown Attributes/Methods
|
69
73
|
|
70
74
|
If the object doesn't respond to a specified attribute/method it is simply ignored:
|
71
75
|
|
72
76
|
```ruby
|
73
|
-
my_movie.identify(:
|
77
|
+
my_movie.identify(:id, :rating, :other) # => Movie[id:1, rating:"7/10"]
|
74
78
|
```
|
75
79
|
|
76
80
|
### Overriding Class Names
|
77
81
|
|
78
82
|
```ruby
|
79
|
-
my_delayed_job.identify(klass: "Delayed::Job") # => Delayed::Job[
|
80
|
-
my_movie.identify(klass: nil) # => [
|
83
|
+
my_delayed_job.identify(klass: "Delayed::Job") # => Delayed::Job[1]
|
84
|
+
my_movie.identify(klass: nil) # => [1]
|
81
85
|
```
|
82
86
|
|
83
|
-
|
84
87
|
### Identifying Nil
|
85
88
|
|
86
89
|
```ruby
|
@@ -88,7 +91,6 @@ nil.identify(:id, :name) # => [no objects]
|
|
88
91
|
nil.identify(:id, :name, klass: "Nope") # => [no objects]
|
89
92
|
```
|
90
93
|
|
91
|
-
|
92
94
|
### Collections
|
93
95
|
|
94
96
|
Collections of objects are each identified in turn.
|
@@ -101,7 +103,7 @@ Collections of objects are each identified in turn.
|
|
101
103
|
The number of results that will be identified from a collection can be truncated by specifying the `limit` option.
|
102
104
|
|
103
105
|
```ruby
|
104
|
-
[my_movie,
|
106
|
+
[my_movie, my_user].identify(:id, :name, limit: 1)
|
105
107
|
# => Movie[id:1, name:"Pi"], ... (1 more)
|
106
108
|
```
|
107
109
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "bundler/setup"
|
4
5
|
require "object_identifier"
|
6
|
+
require "ostruct"
|
5
7
|
|
6
8
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
9
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Reopen the core Object class to add {#identify} to all objects.
|
1
4
|
class Object
|
2
5
|
# Standard #inspect for any object that doesn't override this method. This
|
3
6
|
# method is meant to make an object's type inherently obvious inspected.
|
@@ -31,8 +34,8 @@ class Object
|
|
31
34
|
# 1.identify(:to_s) # => "Integer[to_s:\"1\"]"
|
32
35
|
# nil.identify # => "[no objects]"
|
33
36
|
#
|
34
|
-
# %w(1 2
|
35
|
-
# # => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0]
|
37
|
+
# %w(1 2).identify(:to_i, :to_f)
|
38
|
+
# # => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0]"
|
36
39
|
#
|
37
40
|
# (1..10).to_a.identify(:to_f, limit: 2)
|
38
41
|
# # => "Integer[to_f:1.0], Integer[to_f:2.0], ... (8 more)"
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Reopen the core String class to represent {#inspect_lit}.
|
1
4
|
class String
|
2
5
|
# Formats self to look like a String literal so that object type will be
|
3
6
|
# inherently obvious when inspected.
|
@@ -9,6 +12,6 @@ class String
|
|
9
12
|
# "1".inspect_lit # => "\"1\"" (i.e. '"1"')
|
10
13
|
# "12.3".inspect_lit # => "\"12.3\"" (i.e. '"12.3"')
|
11
14
|
def inspect_lit
|
12
|
-
%("#{
|
15
|
+
%("#{self}")
|
13
16
|
end
|
14
17
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Reopen the core Symbol class to represent {#inspect_lit}.
|
1
4
|
class Symbol
|
2
5
|
# Formats this symbol to look like a symbol literal so that object type will
|
3
6
|
# be inherently obvious when used in logging methods, etc.
|
@@ -8,6 +11,6 @@ class Symbol
|
|
8
11
|
# :test.inspect_lit # => ":\"test\"" (or ':"test"')
|
9
12
|
# :"ta-da!".inspect_lit # => ":\"ta-da!\"" (or ':"ta-da!"')
|
10
13
|
def inspect_lit
|
11
|
-
%(:"#{
|
14
|
+
%(:"#{self}")
|
12
15
|
end
|
13
16
|
end
|
data/lib/object_identifier.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ObjectIdentifier is the base namespace for all modules/classes related to the
|
4
|
+
# object_identifier gem.
|
1
5
|
module ObjectIdentifier
|
2
6
|
end
|
3
7
|
|
8
|
+
require "object_identifier/version"
|
4
9
|
require "object_identifier/identifier"
|
5
|
-
require "
|
6
|
-
require "
|
7
|
-
require "
|
8
|
-
require "
|
10
|
+
require "core_ext/object"
|
11
|
+
require "core_ext/string"
|
12
|
+
require "core_ext/symbol"
|
13
|
+
require "core_ext/big_decimal"
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ObjectIdentifier
|
4
|
+
# ObjectIdentifier::Identifier manages construction of the inspect String.
|
2
5
|
class Identifier
|
3
|
-
NO_OBJECTS_INDICATOR = "[no objects]"
|
6
|
+
NO_OBJECTS_INDICATOR = "[no objects]"
|
4
7
|
|
5
8
|
# Class method for constructing a self-identifying string for any given
|
6
9
|
# object or collection of objects.
|
@@ -26,8 +29,10 @@ module ObjectIdentifier
|
|
26
29
|
# OpenStruct.new(a: 1, b: '2', c: :"3"), :a, :b, :c)
|
27
30
|
# # => "OpenStruct[a:1, b:\"2\", c::\"3\"]"
|
28
31
|
#
|
29
|
-
# ObjectIdentifier::Identifier.identify(1, :to_s)
|
30
|
-
#
|
32
|
+
# ObjectIdentifier::Identifier.identify(1, :to_s)
|
33
|
+
# # => "Integer[to_s:\"1\"]"
|
34
|
+
# ObjectIdentifier::Identifier.identify(nil)
|
35
|
+
# # => "[no objects]"
|
31
36
|
#
|
32
37
|
# ObjectIdentifier::Identifier.identify(%w(1 2), :to_i, :to_f)
|
33
38
|
# # => "String[to_i:1, to_f:1.0], String[to_i:2, to_f:2.0]"
|
@@ -39,7 +44,7 @@ module ObjectIdentifier
|
|
39
44
|
end
|
40
45
|
|
41
46
|
def initialize(objects, *args, limit: nil, klass: :not_given)
|
42
|
-
@objects =
|
47
|
+
@objects = ArrayWrap.call(objects)
|
43
48
|
@attributes = args.empty? ? [:id] : args
|
44
49
|
@limit = (limit || @objects.size).to_i
|
45
50
|
@klass = klass
|
@@ -59,15 +64,13 @@ module ObjectIdentifier
|
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
62
|
-
|
67
|
+
private
|
63
68
|
|
64
69
|
def format_multiple_objects
|
65
70
|
objects =
|
66
71
|
@objects.first(@limit).map { |obj| format(obj) }
|
67
72
|
|
68
|
-
if truncated?
|
69
|
-
objects << "... (#{truncated_objects_count} more)"
|
70
|
-
end
|
73
|
+
objects << "... (#{truncated_objects_count} more)" if truncated?
|
71
74
|
|
72
75
|
objects.join(", ")
|
73
76
|
end
|
@@ -87,9 +90,17 @@ module ObjectIdentifier
|
|
87
90
|
def format_attributes(attributes_hash)
|
88
91
|
return if attributes_hash.empty?
|
89
92
|
|
90
|
-
attributes_hash.
|
91
|
-
|
92
|
-
|
93
|
+
attributes_hash.
|
94
|
+
map(&format_attributes_map_block(attributes_hash)).
|
95
|
+
join(", ")
|
96
|
+
end
|
97
|
+
|
98
|
+
def format_attributes_map_block(attributes_hash)
|
99
|
+
if attributes_hash.one?
|
100
|
+
->(_key, value) { value.inspect_lit }
|
101
|
+
else
|
102
|
+
->(key, value) { "#{key}:#{value.inspect_lit}" }
|
103
|
+
end
|
93
104
|
end
|
94
105
|
|
95
106
|
# @return [Hash]
|
@@ -97,6 +108,8 @@ module ObjectIdentifier
|
|
97
108
|
@attributes.each_with_object({}) { |key, acc|
|
98
109
|
if object.respond_to?(key, :include_private)
|
99
110
|
acc[key] = object.send(key)
|
111
|
+
elsif key.to_s.start_with?("@")
|
112
|
+
acc[key] = object.instance_variable_get(key)
|
100
113
|
end
|
101
114
|
}
|
102
115
|
end
|
@@ -126,7 +139,23 @@ module ObjectIdentifier
|
|
126
139
|
end
|
127
140
|
|
128
141
|
def truncated?
|
129
|
-
truncated_objects_count
|
142
|
+
truncated_objects_count.positive?
|
143
|
+
end
|
144
|
+
|
145
|
+
# ObjectIdentifier::Identifier::ArrayWrap mirrors the implementation of
|
146
|
+
# Rails' {Array.wrap} method. This allows us to get around objects that
|
147
|
+
# respond to `to_a` (such as Struct) and, instead, utilize either `to_ary`
|
148
|
+
# or just actually wrapping the object in an Array.
|
149
|
+
class ArrayWrap
|
150
|
+
def self.call(object)
|
151
|
+
if object.nil?
|
152
|
+
[]
|
153
|
+
elsif object.respond_to?(:to_ary)
|
154
|
+
object.to_ary || [object]
|
155
|
+
else
|
156
|
+
[object]
|
157
|
+
end
|
158
|
+
end
|
130
159
|
end
|
131
160
|
end
|
132
161
|
end
|
data/object_identifier.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require "object_identifier/version"
|
4
6
|
|
@@ -7,9 +9,10 @@ Gem::Specification.new do |spec|
|
|
7
9
|
spec.version = ObjectIdentifier::VERSION
|
8
10
|
spec.authors = ["Paul Dobbins", "Evan Sherwood"]
|
9
11
|
spec.email = ["paul.dobbins@icloud.com"]
|
12
|
+
spec.required_ruby_version = ">= 2.4.0"
|
10
13
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
14
|
+
spec.summary = "ObjectIdentifier identifies an object by its class name and attributes."
|
15
|
+
spec.description = "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."
|
13
16
|
spec.homepage = "https://github.com/pdobb/object_identifier"
|
14
17
|
spec.license = "MIT"
|
15
18
|
|
@@ -29,12 +32,14 @@ Gem::Specification.new do |spec|
|
|
29
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
33
|
spec.require_paths = ["lib"]
|
31
34
|
|
32
|
-
spec.add_development_dependency "bundler"
|
33
|
-
spec.add_development_dependency "
|
34
|
-
spec.add_development_dependency "minitest"
|
35
|
-
spec.add_development_dependency "minitest-reporters"
|
36
|
-
spec.add_development_dependency "
|
37
|
-
spec.add_development_dependency "byebug"
|
38
|
-
spec.add_development_dependency "
|
39
|
-
spec.add_development_dependency "
|
35
|
+
spec.add_development_dependency "bundler"
|
36
|
+
spec.add_development_dependency "byebug"
|
37
|
+
spec.add_development_dependency "minitest"
|
38
|
+
spec.add_development_dependency "minitest-reporters"
|
39
|
+
spec.add_development_dependency "pry"
|
40
|
+
spec.add_development_dependency "pry-byebug"
|
41
|
+
spec.add_development_dependency "rake"
|
42
|
+
spec.add_development_dependency "reek"
|
43
|
+
spec.add_development_dependency "rubocop"
|
44
|
+
spec.add_development_dependency "simplecov"
|
40
45
|
end
|
metadata
CHANGED
@@ -1,131 +1,159 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_identifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Dobbins
|
8
8
|
- Evan Sherwood
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: byebug
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: minitest
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: minitest-reporters
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: pry
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '0
|
76
|
+
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '0
|
83
|
+
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name: byebug
|
85
|
+
name: pry-byebug
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
90
|
+
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
97
|
+
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: rake
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0
|
104
|
+
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '0
|
111
|
+
version: '0'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: reek
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
118
|
+
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - "
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: simplecov
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
126
154
|
description: Object Identifier allows quick, easy, and uniform identification of an
|
127
155
|
object by inspecting its class name and outputting any desirable attributes/methods.
|
128
|
-
It is great for
|
156
|
+
It is great for logging, sending descriptive notification messages, etc.
|
129
157
|
email:
|
130
158
|
- paul.dobbins@icloud.com
|
131
159
|
executables: []
|
@@ -133,6 +161,8 @@ extensions: []
|
|
133
161
|
extra_rdoc_files: []
|
134
162
|
files:
|
135
163
|
- ".gitignore"
|
164
|
+
- ".rubocop"
|
165
|
+
- ".rubocop.yml"
|
136
166
|
- ".travis.yml"
|
137
167
|
- CHANGELOG.md
|
138
168
|
- Gemfile
|
@@ -142,11 +172,11 @@ files:
|
|
142
172
|
- Rakefile
|
143
173
|
- bin/console
|
144
174
|
- bin/setup
|
175
|
+
- lib/core_ext/big_decimal.rb
|
176
|
+
- lib/core_ext/object.rb
|
177
|
+
- lib/core_ext/string.rb
|
178
|
+
- lib/core_ext/symbol.rb
|
145
179
|
- lib/object_identifier.rb
|
146
|
-
- lib/object_identifier/core_ext/big_decimal.rb
|
147
|
-
- lib/object_identifier/core_ext/object.rb
|
148
|
-
- lib/object_identifier/core_ext/string.rb
|
149
|
-
- lib/object_identifier/core_ext/symbol.rb
|
150
180
|
- lib/object_identifier/identifier.rb
|
151
181
|
- lib/object_identifier/version.rb
|
152
182
|
- object_identifier.gemspec
|
@@ -154,7 +184,7 @@ homepage: https://github.com/pdobb/object_identifier
|
|
154
184
|
licenses:
|
155
185
|
- MIT
|
156
186
|
metadata: {}
|
157
|
-
post_install_message:
|
187
|
+
post_install_message:
|
158
188
|
rdoc_options: []
|
159
189
|
require_paths:
|
160
190
|
- lib
|
@@ -162,16 +192,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
192
|
requirements:
|
163
193
|
- - ">="
|
164
194
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
195
|
+
version: 2.4.0
|
166
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
197
|
requirements:
|
168
198
|
- - ">="
|
169
199
|
- !ruby/object:Gem::Version
|
170
200
|
version: '0'
|
171
201
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
202
|
+
rubygems_version: 3.1.4
|
203
|
+
signing_key:
|
175
204
|
specification_version: 4
|
176
205
|
summary: ObjectIdentifier identifies an object by its class name and attributes.
|
177
206
|
test_files: []
|