inspectable 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.adoc +134 -0
- data/README.adoc +238 -0
- data/inspectable.gemspec +23 -22
- data/lib/inspectable/builder.rb +61 -0
- data/lib/inspectable/registry.rb +18 -0
- data/lib/inspectable/transformers/classifier.rb +8 -0
- data/lib/inspectable/transformers/redactor.rb +8 -0
- data/lib/inspectable.rb +9 -30
- data.tar.gz.sig +0 -0
- metadata +69 -59
- metadata.gz.sig +4 -0
- data/MIT-LICENSE +0 -19
- data/README.rdoc +0 -22
- data/WHATSNEW +0 -2
- data/lib/inspectable/version.rb +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f839f2848c735ffa79fdb9a4cd6200f2965715a02ada73150d21c928af88b69
|
4
|
+
data.tar.gz: 39f6d038705e0fa23d8c7bf5f919b30a739c908aa87258491249ce9d629fe7ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d70a034f1cb6c1b81ff71d4d97878fb11e8a46a1491dab16636355af12344c17776c5d638c62f2c33ada6f135fd468759e0a3135330645b29dc0841c36fd36a
|
7
|
+
data.tar.gz: 2f02e2922f22ac16a1db43952c7c6b049999cbbc7b1bc6e6c5821f61d643e2f210fa0b24379150d27a80ceefd974e7872dd18af29538461712f21446db984eaa
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/LICENSE.adoc
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
= Hippocratic License
|
2
|
+
|
3
|
+
Version: 2.1.0.
|
4
|
+
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to
|
6
|
+
permit the Licensee (as defined below) broad permission, if consistent
|
7
|
+
with Human Rights Laws and Human Rights Principles (as each is defined
|
8
|
+
below), to use and work with the Software (as defined below) within the
|
9
|
+
full scope of Licensor’s copyright and patent rights, if any, in the
|
10
|
+
Software, while ensuring attribution and protecting the Licensor from
|
11
|
+
liability.
|
12
|
+
|
13
|
+
Permission and Conditions. The Licensor grants permission by this
|
14
|
+
license ("License"), free of charge, to the extent of Licensor’s
|
15
|
+
rights under applicable copyright and patent law, to any person or
|
16
|
+
entity (the "Licensee") obtaining a copy of this software and
|
17
|
+
associated documentation files (the "Software"), to do everything with
|
18
|
+
the Software that would otherwise infringe (i) the Licensor’s copyright
|
19
|
+
in the Software or (ii) any patent claims to the Software that the
|
20
|
+
Licensor can license or becomes able to license, subject to all of the
|
21
|
+
following terms and conditions:
|
22
|
+
|
23
|
+
* Acceptance. This License is automatically offered to every person and
|
24
|
+
entity subject to its terms and conditions. Licensee accepts this
|
25
|
+
License and agrees to its terms and conditions by taking any action with
|
26
|
+
the Software that, absent this License, would infringe any intellectual
|
27
|
+
property right held by Licensor.
|
28
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
29
|
+
of this Software from Licensee, with or without changes, also receives
|
30
|
+
the License and the above copyright notice (and if included by the
|
31
|
+
Licensor, patent, trademark and attribution notice). Licensee must cause
|
32
|
+
any modified versions of the Software to carry prominent notices stating
|
33
|
+
that Licensee changed the Software. For clarity, although Licensee is
|
34
|
+
free to create modifications of the Software and distribute only the
|
35
|
+
modified portion created by Licensee with additional or different terms,
|
36
|
+
the portion of the Software not modified must be distributed pursuant to
|
37
|
+
this License. If anyone notifies Licensee in writing that Licensee has
|
38
|
+
not complied with this Notice section, Licensee can keep this License by
|
39
|
+
taking all practical steps to comply within 30 days after the notice. If
|
40
|
+
Licensee does not do so, Licensee’s License (and all rights licensed
|
41
|
+
hereunder) shall end immediately.
|
42
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
43
|
+
[arabic]
|
44
|
+
. Human Rights Principles.
|
45
|
+
[loweralpha]
|
46
|
+
.. Licensee is advised to consult the articles of the United Nations
|
47
|
+
Universal Declaration of Human Rights and the United Nations Global
|
48
|
+
Compact that define recognized principles of international human rights
|
49
|
+
(the "Human Rights Principles"). Licensee shall use the Software in a
|
50
|
+
manner consistent with Human Rights Principles.
|
51
|
+
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
52
|
+
controversy, or claim arising out of or relating to (i) Section 1(a)
|
53
|
+
regarding Human Rights Principles, including the breach of Section 1(a),
|
54
|
+
termination of this License for breach of the Human Rights Principles,
|
55
|
+
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
56
|
+
is consistent or in conflict with Human Rights Principles pursuant to
|
57
|
+
Section 2, below, shall be settled by arbitration in accordance with the
|
58
|
+
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
59
|
+
provided, however, that Licensee may elect not to participate in such
|
60
|
+
arbitration, in which event this License (and all rights licensed
|
61
|
+
hereunder) shall end immediately. The number of arbitrators shall be one
|
62
|
+
unless the Rules require otherwise.
|
63
|
+
+
|
64
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
65
|
+
documents and information concerning the arbitration shall be public and
|
66
|
+
may be disclosed by any party; (2) The repository referred to under
|
67
|
+
Article 43 of the Rules shall make available to the public in a timely
|
68
|
+
manner all documents concerning the arbitration which are communicated
|
69
|
+
to it, including all submissions of the parties, all evidence admitted
|
70
|
+
into the record of the proceedings, all transcripts or other recordings
|
71
|
+
of hearings and all orders, decisions and awards of the arbitral
|
72
|
+
tribunal, subject only to the arbitral tribunal’s powers to take such
|
73
|
+
measures as may be necessary to safeguard the integrity of the arbitral
|
74
|
+
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
75
|
+
Article 26(6) of the Rules shall not apply.
|
76
|
+
. Human Rights Laws. The Software shall not be used by any person or
|
77
|
+
entity for any systems, activities, or other uses that violate any Human
|
78
|
+
Rights Laws. "Human Rights Laws" means any applicable laws,
|
79
|
+
regulations, or rules (collectively, "Laws") that protect human,
|
80
|
+
civil, labor, privacy, political, environmental, security, economic, due
|
81
|
+
process, or similar rights; provided, however, that such Laws are
|
82
|
+
consistent and not in conflict with Human Rights Principles (a dispute
|
83
|
+
over the consistency or a conflict between Laws and Human Rights
|
84
|
+
Principles shall be determined by arbitration as stated above). Where
|
85
|
+
the Human Rights Laws of more than one jurisdiction are applicable or in
|
86
|
+
conflict with respect to the use of the Software, the Human Rights Laws
|
87
|
+
that are most protective of the individuals or groups harmed shall
|
88
|
+
apply.
|
89
|
+
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
90
|
+
any other contributor) against all losses, damages, liabilities,
|
91
|
+
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
92
|
+
penalties, fines, costs, or expenses of whatever kind, including
|
93
|
+
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
94
|
+
Licensee’s use of the Software in violation of Human Rights Laws or
|
95
|
+
Human Rights Principles.
|
96
|
+
* Failure to Comply. Any failure of Licensee to act according to the
|
97
|
+
terms and conditions of this License is both a breach of the License and
|
98
|
+
an infringement of the intellectual property rights of the Licensor
|
99
|
+
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
100
|
+
breach or infringement, the terms and conditions of this License may be
|
101
|
+
enforced by Licensor under the Laws of any jurisdiction to which
|
102
|
+
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
103
|
+
the terms and conditions of this License against Licensee through
|
104
|
+
specific performance (or similar remedy under Laws) to the extent
|
105
|
+
permitted by Laws. For clarity, except in the event of a breach of this
|
106
|
+
License, infringement, or as otherwise stated in this License, Licensor
|
107
|
+
may not terminate this License with Licensee.
|
108
|
+
* Enforceability and Interpretation. If any term or provision of this
|
109
|
+
License is determined to be invalid, illegal, or unenforceable by a
|
110
|
+
court of competent jurisdiction, then such invalidity, illegality, or
|
111
|
+
unenforceability shall not affect any other term or provision of this
|
112
|
+
License or invalidate or render unenforceable such term or provision in
|
113
|
+
any other jurisdiction; provided, however, subject to a court
|
114
|
+
modification pursuant to the immediately following sentence, if any term
|
115
|
+
or provision of this License pertaining to Human Rights Laws or Human
|
116
|
+
Rights Principles is deemed invalid, illegal, or unenforceable against
|
117
|
+
Licensee by a court of competent jurisdiction, all rights in the
|
118
|
+
Software granted to Licensee shall be deemed null and void as between
|
119
|
+
Licensor and Licensee. Upon a determination that any term or provision
|
120
|
+
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
121
|
+
the court may modify this License to affect the original purpose that
|
122
|
+
the Software be used in compliance with Human Rights Principles and
|
123
|
+
Human Rights Laws as closely as possible. The language in this License
|
124
|
+
shall be interpreted as to its fair meaning and not strictly for or
|
125
|
+
against any party.
|
126
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
127
|
+
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
128
|
+
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
129
|
+
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
130
|
+
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
131
|
+
|
132
|
+
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
133
|
+
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
134
|
+
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
:toc: macro
|
2
|
+
:toclevels: 5
|
3
|
+
:figure-caption!:
|
4
|
+
|
5
|
+
:dry_schema_link: link:https://dry-rb.org/gems/dry-schema[Dry Schema]
|
6
|
+
:object_inspection_link: link:https://alchemists.io/articles/ruby_object_inspection[Ruby Object Inspection]
|
7
|
+
|
8
|
+
= Inspectable
|
9
|
+
|
10
|
+
A customizable object inspector which enhances {object_inspection_link} behavior beyond what is provided by default. You can always implement your own `#inspect` method but this becomes tedious when you need to exclude or transform the same instance variables across multiple objects.
|
11
|
+
|
12
|
+
toc::[]
|
13
|
+
|
14
|
+
== Features
|
15
|
+
|
16
|
+
- Allows you to customize and configure `Object#inspect` with minimal effort.
|
17
|
+
- Allows you to exclude instance variables that are too verbose or undesired.
|
18
|
+
- Allows you to register reusable transformers for more advanced behavior.
|
19
|
+
|
20
|
+
== Requirements
|
21
|
+
|
22
|
+
. link:https://www.ruby-lang.org[Ruby].
|
23
|
+
. A good understanding of default {object_inspection_link} behavior.
|
24
|
+
|
25
|
+
== Setup
|
26
|
+
|
27
|
+
To install _with_ security, run:
|
28
|
+
|
29
|
+
[source,bash]
|
30
|
+
----
|
31
|
+
# 💡 Skip this line if you already have the public certificate installed.
|
32
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
|
33
|
+
gem install inspectable --trust-policy HighSecurity
|
34
|
+
----
|
35
|
+
|
36
|
+
To install _without_ security, run:
|
37
|
+
|
38
|
+
[source,bash]
|
39
|
+
----
|
40
|
+
gem install inspectable
|
41
|
+
----
|
42
|
+
|
43
|
+
You can also add the gem directly to your project:
|
44
|
+
|
45
|
+
[source,bash]
|
46
|
+
----
|
47
|
+
bundle add inspectable
|
48
|
+
----
|
49
|
+
|
50
|
+
Once the gem is installed, you only need to require it:
|
51
|
+
|
52
|
+
[source,ruby]
|
53
|
+
----
|
54
|
+
require "inspectable"
|
55
|
+
----
|
56
|
+
|
57
|
+
== Usage
|
58
|
+
|
59
|
+
By default, `Object#inspect` is designed to include all instance variables so this gem is designed to exclude what you don't need. Otherwise, you don't need this gem at all. Take the following, for example:
|
60
|
+
|
61
|
+
[source,ruby]
|
62
|
+
----
|
63
|
+
class Demo
|
64
|
+
include Inspectable[:token]
|
65
|
+
|
66
|
+
def initialize token: "secret", uri: "https://demo.io"
|
67
|
+
@token = token
|
68
|
+
@uri = uri
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Demo.new.inspect
|
73
|
+
#<Demo:0x00000000000005d0 @uri="https://demo.io">
|
74
|
+
----
|
75
|
+
|
76
|
+
Notice, when inspecting the instance of `Demo`, the `token` instance variable was excluded. This is important when you want to hide sensitive information, information that is too verbose, or you don't need at all.
|
77
|
+
|
78
|
+
You can also use the built-in transformers to transform sensitive information as well. Example:
|
79
|
+
|
80
|
+
[source,ruby]
|
81
|
+
----
|
82
|
+
class Demo
|
83
|
+
include Inspectable[token: :redact]
|
84
|
+
|
85
|
+
def initialize token: "secret", uri: "https://demo.io"
|
86
|
+
@token = token
|
87
|
+
@uri = uri
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
Demo.new.inspect
|
92
|
+
"#<Demo:0x0000000000000ea0 @token=\"[REDACTED]\", @uri=\"https://demo.io\">"
|
93
|
+
----
|
94
|
+
|
95
|
+
The above is nearly identical to the first example except we've used the built-in `:redact` transformer which replaced `"secret"` with `"[REDACTED]"`. This is why this transformer is provided for you because leaking sensitive information is a fairly common occurrence that this gem has made this simple for you to manage. To learn more, see the xref:_transformers[Transformers] section below.
|
96
|
+
|
97
|
+
=== Registry
|
98
|
+
|
99
|
+
At the moment, this gem's registry only allows the registration of custom transformers. Example:
|
100
|
+
|
101
|
+
[source,ruby]
|
102
|
+
----
|
103
|
+
Inspectable.add_transformer(:upcase, -> value { value.upcase if value })
|
104
|
+
.add_transformer "cleaner", -> value { value.sub(/\h{10}/, "") if value }
|
105
|
+
----
|
106
|
+
|
107
|
+
Notice you can register transformers using strings or symbols. The latter is preferred because all transformers are identified by symbol when referenced. The value must be a lambda where the value is the value of your instance variable which will be transformed at time of object inspection.
|
108
|
+
|
109
|
+
Here's an example using the above registered transformers:
|
110
|
+
|
111
|
+
[source,ruby]
|
112
|
+
----
|
113
|
+
class Demo
|
114
|
+
include Inspectable[name: :suffix, label: :upcase]
|
115
|
+
|
116
|
+
def initialize name: "demo-ab12ef", label: "Demo"
|
117
|
+
@name = name
|
118
|
+
@label = label
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
Demo.new.inspect
|
123
|
+
"#<Demo:0x00000000000012f0 @name=\"demo\", @label=\"DEMO\">"
|
124
|
+
----
|
125
|
+
|
126
|
+
=== Transformers
|
127
|
+
|
128
|
+
This gem includes a few basic transformers that can help you hide sensitive information or reduce verbosity. To view them, use:
|
129
|
+
|
130
|
+
[source,ruby]
|
131
|
+
----
|
132
|
+
Inspectable.transformers
|
133
|
+
# {
|
134
|
+
# class: #<Proc:0x000000010e09dc10 inspectable/transformers/classifier.rb:6 (lambda)>,
|
135
|
+
# redact: #<Proc:0x000000010e09cf40 inspectable/transformers/redactor.rb:6 (lambda)>
|
136
|
+
# }
|
137
|
+
----
|
138
|
+
|
139
|
+
Continue reading to learn how each of these work and how you can provide your own transformers.
|
140
|
+
|
141
|
+
==== Classifier
|
142
|
+
|
143
|
+
This is a simple transformer that always asks for the class of the instance variable's value.
|
144
|
+
|
145
|
+
This transformer is most helpful for objects, like {dry_schema_link}, that are extremely verbose. With this transformer, you can see the type of schema without all of the additional details. This transformer is also handy when you only want type information in general.
|
146
|
+
|
147
|
+
To use, supply the instance variable you want to transform as the key and the transformer's key (symbol) as the value. Example:
|
148
|
+
|
149
|
+
[source,ruby]
|
150
|
+
----
|
151
|
+
include Inspectable[demo: :class]
|
152
|
+
----
|
153
|
+
|
154
|
+
==== Redactor
|
155
|
+
|
156
|
+
This transformer's sole purpose is to hide sensitive information. This is most helpful for obscuring credentials, passwords, and secrets in general. When your instance variable's value is not `nil`, you'll see `"[REDACTED]"` as the value. Otherwise, if your instance variable's value is `nil`, you'll see `nil` instead.
|
157
|
+
|
158
|
+
To use, supply the instance variable you want to transform as the key and the transformer's key (symbol) as the value. Example:
|
159
|
+
|
160
|
+
[source,ruby]
|
161
|
+
----
|
162
|
+
include Inspectable[demo: :redact]
|
163
|
+
----
|
164
|
+
|
165
|
+
==== Overrides
|
166
|
+
|
167
|
+
Should you not like default transformer behavior, you can override an existing transformer with your own. For example, maybe you'd like the `Redactor` transform to use `"[FILTERED]"` instead of `"[REDACTED]"`. Here's how you do that:
|
168
|
+
|
169
|
+
[source,ruby]
|
170
|
+
----
|
171
|
+
Inspectable.add_transformer :redact, -> value { "[FILTERED]" if value }
|
172
|
+
----
|
173
|
+
|
174
|
+
The above will override default behavior with your own functionality.
|
175
|
+
|
176
|
+
==== Custom
|
177
|
+
|
178
|
+
You can add as many transformers as you like by using the `.add_transformer` method. Several examples have been presented already but here are the guidelines for customization:
|
179
|
+
|
180
|
+
* Use only a string or symbol for the first argument (a symbol is preferred). This allows you to quickly identify and use your transformer when applying custom inspection behavior to your objects.
|
181
|
+
* Use a lambda for the second argument. The lambda must accept a value as the first positional parameter. How you transform the value is up to you.
|
182
|
+
|
183
|
+
Let's say you don't like hex digests showing up when inspecting object, you could register a custom transformer for this:
|
184
|
+
|
185
|
+
[source,ruby]
|
186
|
+
----
|
187
|
+
Inspectable.add_transformer :dehexer, -> value { value.sub(/\h+/, "") if value }
|
188
|
+
----
|
189
|
+
|
190
|
+
The above would strip hexes from the output. Notice the guard to check if the `value` exists before performing the transformation. This is good to have when your value might be `nil` so you don't have exceptions.
|
191
|
+
|
192
|
+
ℹ️ Please note that the value of all transformers will always be sent the `#inspect` message as found with default {object_inspection_link} behavior. This means you don't have to worry about doing this yourself when building custom transformers.
|
193
|
+
|
194
|
+
== Development
|
195
|
+
|
196
|
+
To contribute, run:
|
197
|
+
|
198
|
+
[source,bash]
|
199
|
+
----
|
200
|
+
git clone https://github.com/bkuhlmann/inspectable
|
201
|
+
cd inspectable
|
202
|
+
bin/setup
|
203
|
+
----
|
204
|
+
|
205
|
+
You can also use the IRB console for direct access to all objects:
|
206
|
+
|
207
|
+
[source,bash]
|
208
|
+
----
|
209
|
+
bin/console
|
210
|
+
----
|
211
|
+
|
212
|
+
== Tests
|
213
|
+
|
214
|
+
To test, run:
|
215
|
+
|
216
|
+
[source,bash]
|
217
|
+
----
|
218
|
+
bin/rake
|
219
|
+
----
|
220
|
+
|
221
|
+
== link:https://alchemists.io/policies/license[License]
|
222
|
+
|
223
|
+
== link:https://alchemists.io/policies/security[Security]
|
224
|
+
|
225
|
+
== link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
|
226
|
+
|
227
|
+
== link:https://alchemists.io/policies/contributions[Contributions]
|
228
|
+
|
229
|
+
== link:https://alchemists.io/policies/developer_certificate_of_origin[Developer Certificate of Origin]
|
230
|
+
|
231
|
+
== link:https://alchemists.io/projects/inspectable/versions[Versions]
|
232
|
+
|
233
|
+
== link:https://alchemists.io/community[Community]
|
234
|
+
|
235
|
+
== Credits
|
236
|
+
|
237
|
+
* Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
|
238
|
+
* Engineered by link:https://alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/inspectable.gemspec
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "inspectable"
|
5
|
+
spec.version = "0.2.0"
|
6
|
+
spec.authors = ["Brooke Kuhlmann"]
|
7
|
+
spec.email = ["brooke@alchemists.io"]
|
8
|
+
spec.homepage = "https://alchemists.io/projects/inspectable"
|
9
|
+
spec.summary = "A customizable object inspector."
|
10
|
+
spec.license = "Hippocratic-2.1"
|
6
11
|
|
7
|
-
|
12
|
+
spec.metadata = {
|
13
|
+
"bug_tracker_uri" => "https://github.com/bkuhlmann/inspectable/issues",
|
14
|
+
"changelog_uri" => "https://alchemists.io/projects/inspectable/versions",
|
15
|
+
"homepage_uri" => "https://alchemists.io/projects/inspectable",
|
16
|
+
"funding_uri" => "https://github.com/sponsors/bkuhlmann",
|
17
|
+
"label" => "Inspectable",
|
18
|
+
"rubygems_mfa_required" => "true",
|
19
|
+
"source_code_uri" => "https://github.com/bkuhlmann/inspectable"
|
20
|
+
}
|
8
21
|
|
9
|
-
|
10
|
-
|
11
|
-
customize the fields that appear in their #inspect output, to avoid being
|
12
|
-
too verbose.
|
13
|
-
}.strip!.gsub! /\s+/, ' '
|
22
|
+
spec.signing_key = Gem.default_key_path
|
23
|
+
spec.cert_chain = [Gem.default_cert_path]
|
14
24
|
|
15
|
-
|
25
|
+
spec.required_ruby_version = "~> 3.4"
|
16
26
|
|
17
|
-
|
18
|
-
|
19
|
-
MIT-LICENSE
|
20
|
-
README.rdoc
|
21
|
-
WHATSNEW
|
22
|
-
inspectable.gemspec
|
23
|
-
lib
|
24
|
-
lib/inspectable.rb
|
25
|
-
lib/inspectable
|
26
|
-
lib/inspectable/version.rb
|
27
|
-
]
|
27
|
+
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
28
|
+
spec.files = Dir["*.gemspec", "lib/**/*"]
|
28
29
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Inspectable
|
4
|
+
# Provides custom object inspection behavior.
|
5
|
+
class Builder < Module
|
6
|
+
def initialize *excludes, registry: Inspectable, **transformers
|
7
|
+
super()
|
8
|
+
@excludes = excludes.map { :"@#{it}" }
|
9
|
+
@transformers = resolve transformers, registry
|
10
|
+
|
11
|
+
validate
|
12
|
+
define_inspect
|
13
|
+
freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :excludes, :transformers
|
19
|
+
|
20
|
+
def validate
|
21
|
+
return unless excludes.empty? && transformers.empty?
|
22
|
+
|
23
|
+
fail ArgumentError, "Excludes or transformers are required."
|
24
|
+
end
|
25
|
+
|
26
|
+
def define_inspect body_builder: method(:build_body)
|
27
|
+
define_method :inspect do
|
28
|
+
format %(#<%<class>s:%<id>#018x #{body_builder.call(self).chomp ", "}>),
|
29
|
+
class: self.class,
|
30
|
+
id: object_id << 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_body instance
|
35
|
+
exclude_and_transform(instance).reduce(+"") do |body, (variable, value)|
|
36
|
+
body << "#{variable}=#{value}, "
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def exclude_and_transform instance
|
41
|
+
(instance.instance_variables - excludes).each.with_object({}) do |variable, attributes|
|
42
|
+
value = instance.instance_variable_get variable
|
43
|
+
transform = transformers[variable].call(value) if transformers.key? variable
|
44
|
+
|
45
|
+
attributes[variable] = (transform || value).inspect
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def resolve transformers, registry
|
50
|
+
transformers.each.with_object({}) do |(key, object), collection|
|
51
|
+
value = case object
|
52
|
+
when Proc then object
|
53
|
+
when Symbol then registry.transformers[object]
|
54
|
+
else fail TypeError, "Invalid transformer: #{object.inspect}. Use Proc or Symbol."
|
55
|
+
end
|
56
|
+
|
57
|
+
collection[:"@#{key}"] = value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Inspectable
|
4
|
+
# Provides global regsitry for further customization.
|
5
|
+
module Registry
|
6
|
+
def self.extended descendant
|
7
|
+
descendant.add_transformer(:class, Inspectable::Transformers::Classifier)
|
8
|
+
.add_transformer :redact, Inspectable::Transformers::Redactor
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_transformer key, function
|
12
|
+
transformers[key.to_sym] = function
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def transformers = @transformers ||= {}
|
17
|
+
end
|
18
|
+
end
|
data/lib/inspectable.rb
CHANGED
@@ -1,34 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@_attr_inspector |= names.map { |n| n.to_s } if names.any?
|
8
|
-
@_attr_inspector
|
9
|
-
ensure
|
10
|
-
define_method(:inspected_attrs) { self.class.attr_inspector }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.included(base)
|
15
|
-
base.extend ClassMethods
|
16
|
-
end
|
17
|
-
|
18
|
-
def inspect
|
19
|
-
return super unless respond_to?(:inspected_attrs)
|
3
|
+
require "inspectable/builder"
|
4
|
+
require "inspectable/registry"
|
5
|
+
require "inspectable/transformers/classifier"
|
6
|
+
require "inspectable/transformers/redactor"
|
20
7
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
'%s=%s' % [ attr_name.to_s, send(attr_name.to_sym).inspect ]
|
26
|
-
end.compact.join(', ')
|
8
|
+
# Main namespace.
|
9
|
+
module Inspectable
|
10
|
+
extend Registry
|
27
11
|
|
28
|
-
|
29
|
-
'#<%s:0x%s %s>' % [ self.class.to_s, object_id.to_s(16), inspected ]
|
30
|
-
else
|
31
|
-
super
|
32
|
-
end
|
33
|
-
end
|
12
|
+
def self.[](*, **) = Builder.new(*, **)
|
34
13
|
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,72 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspectable
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
14
|
-
autorequire:
|
6
|
+
authors:
|
7
|
+
- Brooke Kuhlmann
|
15
8
|
bindir: bin
|
16
|
-
cert_chain:
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
cert_chain:
|
10
|
+
- |
|
11
|
+
-----BEGIN CERTIFICATE-----
|
12
|
+
MIIENjCCAp6gAwIBAgIBAjANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZicm9v
|
13
|
+
a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
|
14
|
+
aW8wHhcNMjUwMzIyMTQ1NDE3WhcNMjYwMzIyMTQ1NDE3WjBBMQ8wDQYDVQQDDAZi
|
15
|
+
cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQB
|
16
|
+
GRYCaW8wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCro8tj5/E1Hg88
|
17
|
+
f4qfiwPVd2zJQHvdYt4GHVvuHRRgx4HGhJuNp+4BId08RBn7V6V1MW6MY3kezRBs
|
18
|
+
M+7QOQ4b1xNLTvY7FYQB1wGK5a4x7TTokDrPYQxDB2jmsdDYCzVbIMrAvUfcecRi
|
19
|
+
khyGZCdByiiCl4fKv77P12tTT+NfsvXkLt/AYCGwjOUyGKTQ01Z6eC09T27GayPH
|
20
|
+
QQvIkakyFgcJtzSyGzs8bzK5q9u7wQ12MNTjJoXzW69lqp0oNvDylu81EiSUb5S6
|
21
|
+
QzzPxZBiRB1sgtbt1gUbVI262ZDq1gR+HxPFmp+Cgt7ZLIJZAtesQvtcMzseXpfn
|
22
|
+
hpmm0Sw22KGhRAy/mqHBRhDl5HqS1SJp2Ko3lcnpXeFResp0HNlt8NSu13vhC08j
|
23
|
+
GUHU9MyIXbFOsnp3K3ADrAVjPWop8EZkmUR3MV/CUm00w2cZHCSGiXl1KMpiVKvk
|
24
|
+
Ywr1gd2ZME4QLSo+EXUtLxDUa/W3xnBS8dBOuMMz02FPWYr3PN8CAwEAAaM5MDcw
|
25
|
+
CQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFAFgmv0tYMZnItuPycSM
|
26
|
+
F5wykJEVMA0GCSqGSIb3DQEBCwUAA4IBgQBlzRfyAYx/fCFjizS0Npxw4+4T3aYL
|
27
|
+
hbXoDqQRWjxuhFZcXUymhz3r8/Ltyri9lSof8grzB+8/+mrMVms7Gwt5qolk6zdn
|
28
|
+
FkySGy/jmpN12ldOHFbBEnyVBZNBvOBVb8zkkw8PhiHdBdXOUm4Jy39yJvBLfjcC
|
29
|
+
iM1aeWPmgPy1GbvZU+leRGZLt6dRIR9oCDXcWLRjha8xLMoz6Yn9fJBYexBA3iEz
|
30
|
+
h5S7pn4AX/JhVRiSyl8pAy4jEKydpyQrliH3gHkpNmUS/XDczP+9xX1bAB4BvqL2
|
31
|
+
NCxMcQ+hiJNqCKpPgHxaOOHZfIxV33logIuPEQ8NryHAwZ9ZWnwtYDE8kQGGKskI
|
32
|
+
Kkm6QT474hZl7MpwiJjWgW313CR7jUEekQahX1QxCxHPI7LSrKpno0plH3uWIOQp
|
33
|
+
KUlkb9uyACBgyRO52ZHiDVI8YvtU5O/j9pSes9/3XgvBeC1onx4qWp+uRX7eVsYS
|
34
|
+
GiijocTc3enZVrXERetaXj8/9XWs3fB3HWY=
|
35
|
+
-----END CERTIFICATE-----
|
36
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
20
37
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
email: jordi@bunster.org
|
38
|
+
email:
|
39
|
+
- brooke@alchemists.io
|
24
40
|
executables: []
|
25
|
-
|
26
41
|
extensions: []
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
files:
|
31
|
-
-
|
32
|
-
- README.
|
33
|
-
- WHATSNEW
|
42
|
+
extra_rdoc_files:
|
43
|
+
- LICENSE.adoc
|
44
|
+
- README.adoc
|
45
|
+
files:
|
46
|
+
- LICENSE.adoc
|
47
|
+
- README.adoc
|
34
48
|
- inspectable.gemspec
|
35
49
|
- lib/inspectable.rb
|
36
|
-
- lib/inspectable/
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
50
|
+
- lib/inspectable/builder.rb
|
51
|
+
- lib/inspectable/registry.rb
|
52
|
+
- lib/inspectable/transformers/classifier.rb
|
53
|
+
- lib/inspectable/transformers/redactor.rb
|
54
|
+
homepage: https://alchemists.io/projects/inspectable
|
55
|
+
licenses:
|
56
|
+
- Hippocratic-2.1
|
57
|
+
metadata:
|
58
|
+
bug_tracker_uri: https://github.com/bkuhlmann/inspectable/issues
|
59
|
+
changelog_uri: https://alchemists.io/projects/inspectable/versions
|
60
|
+
homepage_uri: https://alchemists.io/projects/inspectable
|
61
|
+
funding_uri: https://github.com/sponsors/bkuhlmann
|
62
|
+
label: Inspectable
|
63
|
+
rubygems_mfa_required: 'true'
|
64
|
+
source_code_uri: https://github.com/bkuhlmann/inspectable
|
42
65
|
rdoc_options: []
|
43
|
-
|
44
|
-
require_paths:
|
66
|
+
require_paths:
|
45
67
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
|
48
|
-
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '3.4'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
49
75
|
- - ">="
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
52
|
-
segments:
|
53
|
-
- 0
|
54
|
-
version: "0"
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
64
78
|
requirements: []
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
signing_key:
|
69
|
-
specification_version: 3
|
70
|
-
summary: "Ruby mixing to aid in customizing the #inspect method"
|
79
|
+
rubygems_version: 3.6.8
|
80
|
+
specification_version: 4
|
81
|
+
summary: A customizable object inspector.
|
71
82
|
test_files: []
|
72
|
-
|
metadata.gz.sig
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
,}��͠T�64kb;�1m����EB����U��x��w��wNC��!P�jQ����gYW~��e uy��Ӷ\����p�d��+��]�Ϟ��T 8����~���Vt�����N��E�d:�S��FF�^��+���#\�+?�$�`��-���ee�<g�څ���ܚ���FJ���M�C
|
2
|
+
QƏw�"�}w/�S����ͬ��A'�@Y������F��< ��Q�랭�40t����ex���XU�`8��P�
|
3
|
+
h�=�t+hc���&�#��@cR�X�
|
4
|
+
ḳ�أ�����e�B��?3�;)(�qƱ�*�}拏V�M���m=(��d����h�2*2}3e�z��U^��<��0\(�\��sоV�R���p�>r6�
|
data/MIT-LICENSE
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2009, 2010 Jordi Bunster <jordi@bunster.org>
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
= inspectable
|
2
|
-
|
3
|
-
Inspectable helps you to customize the output of your Ruby classes's 'inspect'
|
4
|
-
method.
|
5
|
-
|
6
|
-
More documentation forthcoming.
|
7
|
-
|
8
|
-
== Installation instructions
|
9
|
-
|
10
|
-
gem install inspectable
|
11
|
-
|
12
|
-
== Example usage
|
13
|
-
|
14
|
-
require 'inspectable'
|
15
|
-
|
16
|
-
class FancyObject
|
17
|
-
include Inspectable
|
18
|
-
end
|
19
|
-
|
20
|
-
== Legal
|
21
|
-
|
22
|
-
Copyright (c) 2010 Jordi Bunster, released under the MIT license
|
data/WHATSNEW
DELETED
data/lib/inspectable/version.rb
DELETED