gem-try 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +30 -0
- data/Rakefile +10 -0
- data/lib/gem/try/version.rb +7 -0
- data/lib/gem/try.rb +10 -0
- data/lib/rubygems/commands/try_command.rb +122 -0
- data/lib/rubygems_plugin.rb +3 -0
- data/sig/gem/try.rbs +6 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c89138939b1779ac263d2f691114698bdf76b0e677b34c96e8c1d7c4041339e7
|
4
|
+
data.tar.gz: 17d6c6c84379c6b0757ec961a18e9f1ba096b0182c2a5d0c9242855815f07881
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64cf4ab7a69b7d23ceaf57e4ef1ef43b2a2865329a5ef7eccf7be63ddad2240e9c79816e2f71e55cfb1cf61815d86a6eae2b23e4bd25d06440d70b4fb67fee13
|
7
|
+
data.tar.gz: b6b7f457b533b568d10bb42d535852efe1bcd1c8bebd744f1c7bf0f55e481600df5aa862b3087cb790c4d5fdd74381925030aa00fcd832aa9af13f37e24d647c
|
data/.rspec
ADDED
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Gert Goet
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Gem::Try
|
2
|
+
|
3
|
+
Gem subcommand to fire up an IRB-session with gems loaded:
|
4
|
+
|
5
|
+
```shell
|
6
|
+
$ gem try activerecord sqlite3
|
7
|
+
Resolving dependencies...
|
8
|
+
irb(main):001> ActiveRecord::Base.establish_connection(adapter: :sqlite3, database: ':memory:')
|
9
|
+
irb(main):002> ActiveRecord::Base.connection.select_all('select 1')
|
10
|
+
```
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
```shell
|
15
|
+
$ gem install gem-try
|
16
|
+
```
|
17
|
+
|
18
|
+
## Development
|
19
|
+
|
20
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
21
|
+
|
22
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eval/gem-try.
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/gem/try.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require "irb"
|
2
|
+
|
3
|
+
class Gem::Commands::TryCommand < Gem::Command
|
4
|
+
def initialize
|
5
|
+
super("try", "Spin up an IRB-session with gems loaded")
|
6
|
+
|
7
|
+
add_option "--print", "print the inline-gemfile, then exit" do |value, options|
|
8
|
+
options[:print] = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
if options[:args].any?
|
14
|
+
gemfile = render_inline_gemfile(parse_args(options[:args]))
|
15
|
+
|
16
|
+
if options[:print]
|
17
|
+
puts gemfile
|
18
|
+
else
|
19
|
+
written_gemfile = Tempfile.new(%w[inline_gemfile .rb]).tap do |file|
|
20
|
+
file.write(gemfile)
|
21
|
+
file.rewind
|
22
|
+
end
|
23
|
+
ARGV.clear
|
24
|
+
ARGV << "-r#{written_gemfile.path}"
|
25
|
+
IRB.start
|
26
|
+
end
|
27
|
+
else
|
28
|
+
ARGV.clear
|
29
|
+
IRB.start unless options[:print]
|
30
|
+
end
|
31
|
+
ensure
|
32
|
+
if written_gemfile
|
33
|
+
written_gemfile.close
|
34
|
+
written_gemfile.unlink
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def usage # :nodoc:
|
39
|
+
"#{program_name} [some-gem[:some/require][@version]] [some-gem ...]"
|
40
|
+
end
|
41
|
+
|
42
|
+
def description
|
43
|
+
<<~DESC
|
44
|
+
|
45
|
+
Examples usage:
|
46
|
+
|
47
|
+
# Provide zero or more gems and it's off to the races:
|
48
|
+
$ gem try rails sqlite3
|
49
|
+
irb(main):001> ActiveRecord::Base.establish_connection(adapter: :sqlite3, database: ':memory:')
|
50
|
+
irb(main):002> ActiveRecord::Base.connection.select_all('select 1')
|
51
|
+
|
52
|
+
# Versions
|
53
|
+
#
|
54
|
+
# Any version provided is prepended with '~> ' (most common, saves
|
55
|
+
# typing and quoting).
|
56
|
+
# So this:
|
57
|
+
$ gem try rails@7.2
|
58
|
+
# ...is as if you typed:
|
59
|
+
$ gem try rails@'~>7.2'
|
60
|
+
# Prepend with '=' to get exact version:
|
61
|
+
$ gem try rails@=7.2.1
|
62
|
+
|
63
|
+
# Requires
|
64
|
+
#
|
65
|
+
# If you need a require that differs from the gem-name:
|
66
|
+
$ gem try dotenv:dotenv/load@'~> 2'
|
67
|
+
|
68
|
+
# For e.g. rails, activesupport etc. special requires are baked in.
|
69
|
+
# So e.g. instead of this:
|
70
|
+
$ gem try activesupport:active_support/all
|
71
|
+
|
72
|
+
# ...this suffices:
|
73
|
+
$ gem try activesupport
|
74
|
+
irb(main):001> [:cat].inquiry.cat?
|
75
|
+
=> true
|
76
|
+
|
77
|
+
# To prevent require (require: false)
|
78
|
+
$ gem try rails:
|
79
|
+
|
80
|
+
# Debug
|
81
|
+
#
|
82
|
+
# See what inline gemfile is generated using print:
|
83
|
+
$ gem try --print activerecord sqlite3
|
84
|
+
DESC
|
85
|
+
end
|
86
|
+
|
87
|
+
def parse_args(args)
|
88
|
+
args.map do |item|
|
89
|
+
/(?<gem>[^:@]+)(?::(?<require>[^@]*))?(?:@(?<version>.+))?/.match(item)&.values_at(:gem, :require, :version)
|
90
|
+
end.map do |(gem, req, version)|
|
91
|
+
req = req&.empty? ? false : (req || predefined_requires_by_gem[gem] || gem)
|
92
|
+
version = case version
|
93
|
+
when /^\d/ then "~>#{version}"
|
94
|
+
else
|
95
|
+
version
|
96
|
+
end
|
97
|
+
|
98
|
+
[gem, req, version]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def predefined_requires_by_gem
|
103
|
+
{"rails" => "rails/all",
|
104
|
+
"activerecord" => "active_record",
|
105
|
+
"activesupport" => "active_support/all"}
|
106
|
+
end
|
107
|
+
|
108
|
+
def render_inline_gemfile(parsed)
|
109
|
+
require "erb"
|
110
|
+
ERB.new(<<~GEMFILE, trim_mode: "-").result(binding)
|
111
|
+
require "bundler/inline"
|
112
|
+
|
113
|
+
gemfile(true) do
|
114
|
+
source "https://rubygems.org"
|
115
|
+
|
116
|
+
<% parsed.each do |gem,req,ver| -%>
|
117
|
+
gem <%= gem.inspect %>, <%= ver ? ver.inspect << ", " : '' %>require: <%= req.inspect %>
|
118
|
+
<% end -%>
|
119
|
+
end
|
120
|
+
GEMFILE
|
121
|
+
end
|
122
|
+
end
|
data/sig/gem/try.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-try
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gert Goet
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Spin up an IRB-session with gems loaded
|
14
|
+
email:
|
15
|
+
- gert@thinkcreate.dk
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".standard.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/gem/try.rb
|
27
|
+
- lib/gem/try/version.rb
|
28
|
+
- lib/rubygems/commands/try_command.rb
|
29
|
+
- lib/rubygems_plugin.rb
|
30
|
+
- sig/gem/try.rbs
|
31
|
+
homepage: https://github.com/eval/gem-try
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/eval/gem-try
|
36
|
+
source_code_uri: https://github.com/eval/gem-try
|
37
|
+
changelog_uri: https://github.com/eval/gem-try/blob/main/CHANGELOG.md
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.0.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.5.3
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Spin up an IRB-session with gems loaded
|
57
|
+
test_files: []
|