irb-kit 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d4a5907eebfaf893e3124cdc4e0377b7fbca4c5b574275cdda768cc57d8cd729
4
+ data.tar.gz: 84043d9813d5e9731305f7630b93393644b746a3b3410641bdcae8d19945b663
5
+ SHA512:
6
+ metadata.gz: 5c1e6591d55b4f59324265e0f86ebaf034907e707640b4d3678e0d23091a973b184d3c1122b619da83deb1b876b63a6dd69f9e9990631f13c8b50f0e81f45cf4
7
+ data.tar.gz: d584db7f831d24d84f55aec04cf1f27e8ced2754f33b5d7101adcf67c8d5db7064fac27e6ad5dbd1cdcae79959acfe0d845759b7d924cd878a9fd36394ba7045
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,300 @@
1
+ :toc: macro
2
+ :toclevels: 5
3
+ :figure-caption!:
4
+
5
+ :hanami_link: link:https://hanamirb.org[Hanami]
6
+ :irb_article_link: link:https://alchemists.io/articles/interactive_ruby[Interactive Ruby]
7
+ :irb_extensions_link: link:https://github.com/ruby/irb/blob/master/EXTEND_IRB.md[IRB Extensions]
8
+ :irb_link: link:https://github.com/ruby/irb[IRB]
9
+ :rails_link: link:https://rubyonrails.org[Rails]
10
+ :ruby_link: link:https://www.ruby-lang.org[Ruby]
11
+ :xdg_link: link:https://alchemists.io/projects/xdg[XDG]
12
+
13
+ = IRB Kit
14
+
15
+ This gem is a collection of {irb_extensions_link} for enhancing {irb_link} with additional commands, helpers, prompts, and more. Add this gem to your {irb_link} configuration (i.e. `irbrc`) to get all these enhancements immediately while keeping your IRB configuration slim and readable.
16
+
17
+ toc::[]
18
+
19
+ == Features
20
+
21
+ * Provides custom helpers.
22
+ * Provides dynamic prompt based on environment.
23
+
24
+ == Requirements
25
+
26
+ . {ruby_link}.
27
+ . {irb_link}.
28
+ . A solid understanding of {irb_article_link}.
29
+
30
+ == Setup
31
+
32
+ To install _with_ security, run:
33
+
34
+ [source,bash]
35
+ ----
36
+ # 💡 Skip this line if you already have the public certificate installed.
37
+ gem cert --add <(curl --compressed --location https://alchemists.io/projects/irb-kit/gems.pem)
38
+ gem install irb-kit --trust-policy HighSecurity
39
+ ----
40
+
41
+ To install _without_ security, run:
42
+
43
+ [source,bash]
44
+ ----
45
+ gem install irb-kit
46
+ ----
47
+
48
+ You can also add the gem directly to your project:
49
+
50
+ [source,bash]
51
+ ----
52
+ bundle add irb-kit
53
+ ----
54
+
55
+ Once the gem is installed, you only need to require it:
56
+
57
+ [source,ruby]
58
+ ----
59
+ require "irb/kit"
60
+ ----
61
+
62
+ == Usage
63
+
64
+ To use, add the following to your `~/.config/irb/irbrc` configuration (or `~/.irbrc` if not using {xdg_link}).
65
+
66
+ [source,ruby]
67
+ ----
68
+ require "irb/kit"
69
+ ----
70
+
71
+ This ensures this gem is fully loaded in order to enhance {irb_link} further. To customize, read on.
72
+
73
+ === Quick Start
74
+
75
+ If you'd like all the bells and whistles fully enabled, add the following to your {irb_link} configuration (as discussed above):
76
+
77
+ [source,ruby]
78
+ ----
79
+ require "irb/kit"
80
+
81
+ IRB::Kit.register_helpers :all
82
+
83
+ IRB.conf[:PROMPT][:DEMO] = {
84
+ PROMPT_I: "[#{IRB::Kit.prompt}]> ",
85
+ PROMPT_N: "[#{IRB::Kit.prompt}]| ",
86
+ PROMPT_C: "[#{IRB::Kit.prompt}]| ",
87
+ PROMPT_S: "[#{IRB::Kit.prompt}]%l ",
88
+ RETURN: "=> %s\n"
89
+ }
90
+
91
+ IRB.conf[:PROMPT_MODE] = :DEMO
92
+ ----
93
+
94
+ The above enables all helpers and configures your prompt for {ruby_link}, {hanami_link}, and {rails_link} environments.
95
+
96
+
97
+ 💡 Use of `:DEMO`, while functional, is meant to be replaced with the name of your organization or personal identity. So please ensure you replace both occurrences of `:DEMO` with your own unique identifier.
98
+
99
+ === Commands
100
+
101
+ At the moment, this gem does not provide any custom commands _but might in the future_. See {irb_extensions_link} documentation for further details.
102
+
103
+ === Helpers
104
+
105
+ Several custom helpers are provided for you by this gem. Each is listed below as found when using `help` within an {irb_link} console:
106
+
107
+ ....
108
+ Helper methods
109
+ clip Copy input to macOS clipboard.
110
+ csource Find a constant's source location.
111
+ msource Find an object method's source location.
112
+ paste Paste last entry from macOS clipboard.
113
+ search Search an object's methods by pattern.
114
+ ....
115
+
116
+ To enable all of these helpers, use `IRB::Kit.register_helpers :all`. This is the same as using:
117
+
118
+ [source,ruby]
119
+ ----
120
+ IRB::Kit.register_helpers(*%i[clip csource msource paste search])
121
+ ----
122
+
123
+ Knowing this, you can disable all helpers entirely, use only the ones you care about, or enable all of them at once. The following explains each helper in greater detail.
124
+
125
+ ==== `clip`
126
+
127
+ Use this helper to copy output into the macOS clipboard. Example:
128
+
129
+ [source,ruby]
130
+ ----
131
+ clip (1..3).to_a
132
+ # 1
133
+ # 2
134
+ # 3
135
+
136
+ clip 1, 2, 3
137
+ # 1
138
+ # 2
139
+ # 3
140
+
141
+ clip Object.new
142
+ # #<Object:0x000000012a46eaf8>
143
+ ----
144
+
145
+ This helper accepts any number of arguments. Each is delimited by a new line for pasting into another application.
146
+
147
+ ==== `csource`
148
+
149
+ Use this helper, short for _constant source_, to find the source location of a constant. Example:
150
+
151
+ [source,ruby]
152
+ ----
153
+ csource :RUBY_VERSION # ["<main>", 0]
154
+ csource "RUBY_VERSION" # ["<main>", 0]
155
+ ----
156
+
157
+ You can use a symbol or a string when looking up the source location of a constant.
158
+
159
+ ==== `msource`
160
+
161
+ Use this helper, short for _method source_, to find the source location of a method. Example:
162
+
163
+ [source,ruby]
164
+ ----
165
+ msource IRB, :start # ["ruby/gems/3.3.0/gems/irb-1.13.1/lib/irb.rb", 893]
166
+ msource IRB, "start" # ["ruby/gems/3.3.0/gems/irb-1.13.1/lib/irb.rb", 893]
167
+ ----
168
+
169
+ The first argument is the object you want to message while the second argument is the object's method you want to find the source code location for. You'll get an array with the path and the line number of the method's source. You can also use a symbol or string for the method.
170
+
171
+ ==== `paste`
172
+
173
+ Use this helper to paste the last entry from your macOS clipboard into your console. For example, assuming the text `This is a demonstration` is in your clipboard, you'd see the following:
174
+
175
+ [source,ruby]
176
+ ----
177
+ paste
178
+ # "This is a demonstration"
179
+ ----
180
+
181
+ This helper takes no arguments.
182
+
183
+ ==== `search`
184
+
185
+ Use this helper to search for methods on an object. Example:
186
+
187
+ [source,ruby]
188
+ ----
189
+ search Module, "protected"
190
+ # [
191
+ # protected_instance_methods(*args) #<Class:Module> (Class)
192
+ # protected_method_defined?(*arg1) #<Class:Module> (Module)
193
+ # protected_methods(*args) #<Class:Module> (Object)
194
+ # ]
195
+
196
+ search Module, /_defined/
197
+ # [
198
+ # class_variable_defined?(arg1) #<Class:Module> (Module)
199
+ # const_defined?(*arg1) #<Class:Module> (Module)
200
+ # instance_variable_defined?(arg1) #<Class:Module> (Kernel)
201
+ # method_defined?(*arg1) #<Class:Module> (Module)
202
+ # private_method_defined?(*arg1) #<Class:Module> (Module)
203
+ # protected_method_defined?(*arg1) #<Class:Module> (Module)
204
+ # public_method_defined?(*arg1) #<Class:Module> (Module)
205
+ # ]
206
+ ----
207
+
208
+ This helper takes two arguments. The first is the object you want to search on and the second argument is the string or regular expression of the methods to search for.
209
+
210
+ === Prompt
211
+
212
+ A dynamic prompt, based on environment, is provided for you. The code -- as shown above -- for configuring IRB to make use of this custom prompt is:
213
+
214
+ [source,ruby]
215
+ ----
216
+ IRB.conf[:PROMPT][:DEMO] = {
217
+ PROMPT_I: "[#{IRB::Kit.prompt}]> ",
218
+ PROMPT_N: "[#{IRB::Kit.prompt}]| ",
219
+ PROMPT_C: "[#{IRB::Kit.prompt}]| ",
220
+ PROMPT_S: "[#{IRB::Kit.prompt}]%l ",
221
+ RETURN: "=> %s\n"
222
+ }
223
+
224
+ IRB.conf[:PROMPT_MODE] = :DEMO
225
+ ----
226
+
227
+ You only need to swap out the `:DEMO` key with a key that identifies you as you see fit.
228
+
229
+ At the moment, the prompt dynamically detects the following environments:
230
+
231
+ * {ruby_link}
232
+ * {hanami_link}
233
+ * {rails_link}
234
+
235
+ Additionally, when working with the {hanami_link} and/or {rails_link} frameworks, environment information will be color coded as follows:
236
+
237
+ * *Non-Production*: Displays as green for any environment other than production.
238
+ * *Production*: Displays as red but only for a production environment.
239
+
240
+ The following screenshots demonstrate what the prompt looks like in different environments:
241
+
242
+ *Ruby (with Git)*
243
+
244
+ image::https://alchemists.io/images/projects/irb-kit/screenshots/prompt-with_git.png[Screenshot,459,108,role=focal_point]
245
+
246
+ *Ruby (without Git)*
247
+
248
+ image::https://alchemists.io/images/projects/irb-kit/screenshots/prompt-without_git.png[Screenshot,292,116,role=focal_point]
249
+
250
+ *Hanami*
251
+
252
+ image::https://alchemists.io/images/projects/irb-kit/screenshots/prompt-hanami.png[Screenshot,520,120,role=focal_point]
253
+
254
+ *Rails*
255
+
256
+ image::https://alchemists.io/images/projects/irb-kit/screenshots/prompt-rails.png[Screenshot,541,137,role=focal_point]
257
+
258
+ == Development
259
+
260
+ To contribute, run:
261
+
262
+ [source,bash]
263
+ ----
264
+ git clone https://github.com/bkuhlmann/irb-kit
265
+ cd irb-kit
266
+ bin/setup
267
+ ----
268
+
269
+ You can also use the IRB console for direct access to all objects:
270
+
271
+ [source,bash]
272
+ ----
273
+ bin/console
274
+ ----
275
+
276
+ == Tests
277
+
278
+ To test, run:
279
+
280
+ [source,bash]
281
+ ----
282
+ bin/rake
283
+ ----
284
+
285
+ == link:https://alchemists.io/policies/license[License]
286
+
287
+ == link:https://alchemists.io/policies/security[Security]
288
+
289
+ == link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
290
+
291
+ == link:https://alchemists.io/policies/contributions[Contributions]
292
+
293
+ == link:https://alchemists.io/projects/irb-kit/versions[Versions]
294
+
295
+ == link:https://alchemists.io/community[Community]
296
+
297
+ == Credits
298
+
299
+ * Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
300
+ * Engineered by link:https://alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
data/irb-kit.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "irb-kit"
5
+ spec.version = "0.0.0"
6
+ spec.authors = ["Brooke Kuhlmann"]
7
+ spec.email = ["brooke@alchemists.io"]
8
+ spec.homepage = "https://alchemists.io/projects/irb-kit"
9
+ spec.summary = "Extends IRB by providing additional productivity enhancements."
10
+ spec.license = "Hippocratic-2.1"
11
+
12
+ spec.metadata = {
13
+ "bug_tracker_uri" => "https://github.com/bkuhlmann/irb-kit/issues",
14
+ "changelog_uri" => "https://alchemists.io/projects/irb-kit/versions",
15
+ "documentation_uri" => "https://alchemists.io/projects/irb-kit",
16
+ "funding_uri" => "https://github.com/sponsors/bkuhlmann",
17
+ "label" => "Irb Kit",
18
+ "rubygems_mfa_required" => "true",
19
+ "source_code_uri" => "https://github.com/bkuhlmann/irb-kit"
20
+ }
21
+
22
+ spec.signing_key = Gem.default_key_path
23
+ spec.cert_chain = [Gem.default_cert_path]
24
+
25
+ spec.required_ruby_version = "~> 3.3"
26
+ spec.add_dependency "irb", "~> 1.13"
27
+ spec.add_dependency "zeitwerk", "~> 2.6"
28
+
29
+ spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
30
+ spec.files = Dir["*.gemspec", "lib/**/*"]
31
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ module Helpers
6
+ # Copies input to macOS clipboard.
7
+ class Clip < IRB::HelperMethod::Base
8
+ description "Copy input to macOS clipboard."
9
+
10
+ def self.moniker = :clip
11
+
12
+ # :nocov:
13
+ def initialize io = IO
14
+ super()
15
+ @io = io
16
+ end
17
+
18
+ def execute(*lines)
19
+ io.popen("pbcopy", "w") { |clipboard| clipboard.write lines.join("\n") }
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :io
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ module Helpers
6
+ # Finds constant's source location.
7
+ class ConstantSource < IRB::HelperMethod::Base
8
+ description "Find a constant's source location."
9
+
10
+ def self.moniker = :csource
11
+
12
+ def initialize object = Object
13
+ super()
14
+ @object = object
15
+ end
16
+
17
+ def execute name
18
+ object.const_source_location name
19
+ rescue NameError
20
+ "ERROR: Invalid constant (#{name.inspect})."
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :object
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ module Helpers
6
+ # Find an object method's source location.
7
+ class MethodSource < IRB::HelperMethod::Base
8
+ description "Find an object method's source location."
9
+
10
+ def self.moniker = :msource
11
+
12
+ def execute object, name
13
+ object.method(name).source_location
14
+ rescue NameError => error
15
+ "ERROR: #{error.message}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ module Helpers
6
+ # Pastes last entry from macOS clipboard.
7
+ class Paste < IRB::HelperMethod::Base
8
+ description "Paste last entry from macOS clipboard."
9
+
10
+ def self.moniker = :paste
11
+
12
+ # :nocov:
13
+ def initialize io = IO
14
+ super()
15
+ @io = io
16
+ end
17
+
18
+ def execute = io.popen "pbpaste", "r", &:read
19
+
20
+ private
21
+
22
+ attr_reader :io
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ module Helpers
6
+ # Search an object's methods by pattern.
7
+ class Search < IRB::HelperMethod::Base
8
+ description "Search an object's methods by pattern."
9
+
10
+ def self.moniker = :search
11
+
12
+ def initialize regex = Regexp
13
+ super()
14
+ @regex = regex
15
+ end
16
+
17
+ def execute object, pattern
18
+ object.methods.grep regex.new(pattern)
19
+ rescue TypeError
20
+ "ERROR: Use only a string or regular expression for the pattern."
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :regex
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ # Loads IRB extensions for namespace.
6
+ class Loader
7
+ ALL = [:all].freeze
8
+
9
+ def initialize registrar, namespace, all: ALL
10
+ @registrar = registrar
11
+ @namespace = IRB::Kit.const_get namespace
12
+ @all = all
13
+ end
14
+
15
+ def call(*monikers) = monikers == all ? register_all : register_selected(*monikers)
16
+
17
+ private
18
+
19
+ attr_reader :registrar, :namespace, :all
20
+
21
+ def register_all = helpers.each { |helper| registrar.register helper.moniker, helper }
22
+
23
+ def register_selected(*monikers)
24
+ helpers.select { |helper| monikers.include? helper.moniker }
25
+ .then { |selected| monikers.zip selected }
26
+ .each { |moniker, helper| registrar.register moniker, helper }
27
+ end
28
+
29
+ def helpers = namespace.constants.sort.map { |name| namespace.const_get name }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Kit
5
+ # Dynamically computes prompt based environment.
6
+ class Prompter
7
+ COLORS = {green: 32, red: 31}.freeze
8
+
9
+ def initialize version = RUBY_VERSION, delimiter: "|", colors: COLORS
10
+ super()
11
+ @version = version
12
+ @delimiter = delimiter
13
+ @colors = colors
14
+ end
15
+
16
+ def call
17
+ if defined? Hanami
18
+ details Hanami::VERSION, Hanami.app.name.delete_suffix("::App"), Hanami.env
19
+ elsif defined? Rails
20
+ details Rails.version, Rails.application.class.module_parent_name, Rails.env
21
+ else version_with_optional_project
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :version, :delimiter, :colors
28
+
29
+ def details framework_version, application_name, environment
30
+ [version, framework_version, application_name.downcase, color(environment)].join delimiter
31
+ end
32
+
33
+ def color environment
34
+ code = environment.to_sym == :production ? red : green
35
+ "\e[#{code}m#{environment}\e[0m"
36
+ end
37
+
38
+ def version_with_optional_project
39
+ File.basename(`git rev-parse --show-toplevel 2> /dev/null`.strip)
40
+ .downcase
41
+ .then { |project| [version, project].reject(&:empty?).join delimiter }
42
+ end
43
+
44
+ def green = colors.fetch __method__
45
+
46
+ def red = colors.fetch __method__
47
+ end
48
+ end
49
+ end
data/lib/irb/kit.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "irb"
4
+ require "zeitwerk"
5
+
6
+ Zeitwerk::Loader.new.then do |loader|
7
+ loader.inflector.inflect "irb" => "IRB"
8
+ loader.tag = "irb-kit"
9
+ loader.push_dir "#{__dir__}/.."
10
+ loader.setup
11
+ end
12
+
13
+ module IRB
14
+ # Main namespace.
15
+ module Kit
16
+ def self.loader registry = Zeitwerk::Registry
17
+ @loader ||= registry.loaders.find { |loader| loader.tag == "irb-kit" }
18
+ end
19
+
20
+ def self.register_helpers(*) = Loader.new(IRB::HelperMethod, :Helpers).call(*)
21
+
22
+ def self.prompt = @prompt ||= Prompter.new.call
23
+ end
24
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb-kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brooke Kuhlmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEeDCCAuCgAwIBAgIBATANBgkqhkiG9w0BAQsFADBBMQ8wDQYDVQQDDAZicm9v
14
+ a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
15
+ aW8wHhcNMjMwMzIyMTYxNDQxWhcNMjUwMzIxMTYxNDQxWjBBMQ8wDQYDVQQDDAZi
16
+ cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQB
17
+ GRYCaW8wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCro8tj5/E1Hg88
18
+ f4qfiwPVd2zJQHvdYt4GHVvuHRRgx4HGhJuNp+4BId08RBn7V6V1MW6MY3kezRBs
19
+ M+7QOQ4b1xNLTvY7FYQB1wGK5a4x7TTokDrPYQxDB2jmsdDYCzVbIMrAvUfcecRi
20
+ khyGZCdByiiCl4fKv77P12tTT+NfsvXkLt/AYCGwjOUyGKTQ01Z6eC09T27GayPH
21
+ QQvIkakyFgcJtzSyGzs8bzK5q9u7wQ12MNTjJoXzW69lqp0oNvDylu81EiSUb5S6
22
+ QzzPxZBiRB1sgtbt1gUbVI262ZDq1gR+HxPFmp+Cgt7ZLIJZAtesQvtcMzseXpfn
23
+ hpmm0Sw22KGhRAy/mqHBRhDl5HqS1SJp2Ko3lcnpXeFResp0HNlt8NSu13vhC08j
24
+ GUHU9MyIXbFOsnp3K3ADrAVjPWop8EZkmUR3MV/CUm00w2cZHCSGiXl1KMpiVKvk
25
+ Ywr1gd2ZME4QLSo+EXUtLxDUa/W3xnBS8dBOuMMz02FPWYr3PN8CAwEAAaN7MHkw
26
+ CQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFAFgmv0tYMZnItuPycSM
27
+ F5wykJEVMB8GA1UdEQQYMBaBFGJyb29rZUBhbGNoZW1pc3RzLmlvMB8GA1UdEgQY
28
+ MBaBFGJyb29rZUBhbGNoZW1pc3RzLmlvMA0GCSqGSIb3DQEBCwUAA4IBgQAX+EGY
29
+ 9RLYGxF1VLZz+G1ACQc4uyrCB6kXwI06kzUa5dF9tPXqTX9ffnz3/W8ck2IQhKzu
30
+ MKO2FVijzbDWTsZeZGglS4E+4Jxpau1lU9HhOIcKolv6LeC6UdALTFudY+GLb8Xw
31
+ REXgaJkjzzhkUSILmEnRwEbY08dVSl7ZAaxVI679vfI2yapLlIwpbBgmQTiTvPr3
32
+ qyyLUno9flYEOv9fmGHunSrM+gE0/0niGTXa5GgXBXYGS2he4LQGgSBfGp/cTwMU
33
+ rDKJRcusZ12lNBeDfgqACz/BBJF8FLodgk6rGMRZz7+ZmjjHEmpG5bQpR6Q2BuWL
34
+ XMtYk/QzaWuhiR7pWjiF8jbdd7RO6or0ohq7iFkokz/5xrtQ/vPzU2RQ3Qc6YaKw
35
+ 3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
+ gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
+ -----END CERTIFICATE-----
38
+ date: 2024-05-18 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: irb
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.13'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.13'
54
+ - !ruby/object:Gem::Dependency
55
+ name: zeitwerk
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.6'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.6'
68
+ description:
69
+ email:
70
+ - brooke@alchemists.io
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - README.adoc
75
+ - LICENSE.adoc
76
+ files:
77
+ - LICENSE.adoc
78
+ - README.adoc
79
+ - irb-kit.gemspec
80
+ - lib/irb/kit.rb
81
+ - lib/irb/kit/helpers/clip.rb
82
+ - lib/irb/kit/helpers/constant_source.rb
83
+ - lib/irb/kit/helpers/method_source.rb
84
+ - lib/irb/kit/helpers/paste.rb
85
+ - lib/irb/kit/helpers/search.rb
86
+ - lib/irb/kit/loader.rb
87
+ - lib/irb/kit/prompter.rb
88
+ homepage: https://alchemists.io/projects/irb-kit
89
+ licenses:
90
+ - Hippocratic-2.1
91
+ metadata:
92
+ bug_tracker_uri: https://github.com/bkuhlmann/irb-kit/issues
93
+ changelog_uri: https://alchemists.io/projects/irb-kit/versions
94
+ documentation_uri: https://alchemists.io/projects/irb-kit
95
+ funding_uri: https://github.com/sponsors/bkuhlmann
96
+ label: Irb Kit
97
+ rubygems_mfa_required: 'true'
98
+ source_code_uri: https://github.com/bkuhlmann/irb-kit
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '3.3'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.5.10
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Extends IRB by providing additional productivity enhancements.
118
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ �'����B�1��b�2:�*������aS% �H��C$D��
2
+ �z8s1�c���Ob49Lى��Dh��':J�R5g��9s���q�%��C��Y���b�p�'kd)�b5��o�յ���8�be<����#�Y�Ե+,[&E��w��(�&l�(�Ļ3�K��z.~=9�_�� ﬕ~^������Fa��ETG.o}�mOD���MOW������� �߹�Q���� I�2�l�4��Y��P�
3
+ �('Ռa�S��3ؿ8�y���Dr��S�[�4o��eR]#�GzD��H�U�z_��