gem-default 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gem-default.gemspec +24 -0
- data/lib/rubygems/commands/default_command.rb +121 -0
- data/lib/rubygems_plugin.rb +1 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac33c127fa1e81e7756608931842be4ede30ea33d6a2c77f99f57e1ceaa5c127
|
4
|
+
data.tar.gz: 2b4c665766a742076ab0e64814f81b7679b0300075457c9c9dbc374ccfe54004
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb8ac2bdb655909ab23818ad5ecad6a8cc130ef27069361e2c06b5baec70ff52a46e7f3fd0b66bd9811007cffc727bc88a512c8adaae0a570055eda3eca22f43
|
7
|
+
data.tar.gz: f8cb928241049c4ad4a27d3781382aa4769c7eb5ab803d8f0e88f77a8207cc225c4ef63e1301fe47ccc1d518f08a5ee4136b0273952f6cf2623ec6098c1d4991
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Takashi Kokubun
|
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,66 @@
|
|
1
|
+
# Gem::Default
|
2
|
+
|
3
|
+
Change a non-default gem to a default gem in your local environment.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
$ gem install gem-default
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Run `gem default xxx` after `gem install xxx`.
|
14
|
+
|
15
|
+
## Example
|
16
|
+
|
17
|
+
### Before
|
18
|
+
|
19
|
+
Usually, we cannot run a non-default gem (`pry` for example) with `bundle exec`.
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ cat Gemfile
|
23
|
+
source 'https://rubygems.org'
|
24
|
+
gem 'rails'
|
25
|
+
|
26
|
+
$ gem install pry
|
27
|
+
Successfully installed pry-0.12.2
|
28
|
+
Parsing documentation for pry-0.12.2
|
29
|
+
Done installing documentation for pry after 0 seconds
|
30
|
+
1 gem installed
|
31
|
+
|
32
|
+
$ bundle exec pry
|
33
|
+
bundler: failed to load command: pry (/home/k0kubun/.rbenv/versions/ruby/bin/pry)
|
34
|
+
Gem::Exception: can't find executable pry for gem pry. pry is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
|
35
|
+
/home/k0kubun/.rbenv/versions/ruby/lib/ruby/2.7.0/bundler/rubygems_integration.rb:378:in `block in replace_bin_path'
|
36
|
+
/home/k0kubun/.rbenv/versions/ruby/lib/ruby/2.7.0/bundler/rubygems_integration.rb:406:in `block in replace_bin_path'
|
37
|
+
/home/k0kubun/.rbenv/versions/ruby/bin/pry:23:in `<top (required)>'
|
38
|
+
```
|
39
|
+
|
40
|
+
### After
|
41
|
+
|
42
|
+
With `gem default` command, you can make it available under `bundle exec`.
|
43
|
+
|
44
|
+
```bash
|
45
|
+
$ gem default pry
|
46
|
+
(..snip...)
|
47
|
+
=> Copying files from "/home/k0kubun/.rbenv/versions/ruby/lib/ruby/gems/2.7.0/gems/pry-0.12.2/bin" to:
|
48
|
+
/home/k0kubun/.rbenv/versions/ruby/bin/pry (original => /home/k0kubun/.rbenv/versions/ruby/bin/pry.old)
|
49
|
+
|
50
|
+
$ cat Gemfile
|
51
|
+
source 'https://rubygems.org'
|
52
|
+
gem 'rails'
|
53
|
+
|
54
|
+
$ bundle exec pry
|
55
|
+
[1] pry(main)>
|
56
|
+
```
|
57
|
+
|
58
|
+
## Caveats
|
59
|
+
|
60
|
+
* Own your risk. This gem may break your Ruby installation.
|
61
|
+
* This does not support gems having non-`*.rb` files under "lib" yet.
|
62
|
+
* Patches welcomed.
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gem/default"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gem-default.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'gem-default'
|
3
|
+
spec.version = '0.0.1'
|
4
|
+
spec.authors = ['Takashi Kokubun']
|
5
|
+
spec.email = ['takashikkbn@gmail.com']
|
6
|
+
|
7
|
+
spec.summary = %q{Make an arbitrary gem a default gem}
|
8
|
+
spec.description = %q{Make an arbitrary gem a default gem}
|
9
|
+
spec.homepage = 'https://github.com/k0kubun/gem-default'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
|
12
|
+
# Specify which files should be added to the gem when it is released.
|
13
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
14
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
end
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rubygems/command_manager'
|
3
|
+
|
4
|
+
class Gem::Commands::DefaultCommand < Gem::Command
|
5
|
+
def initialize(output = STDOUT)
|
6
|
+
super 'default', description
|
7
|
+
@output = output
|
8
|
+
|
9
|
+
add_option('-v', '--version VERSION', 'Gem version to be a default gem') do |version, _options|
|
10
|
+
options[:version] = version
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def usage
|
15
|
+
"#{program_name} GEMNAME"
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
'Allows you to change an arbitrary installed gem to a default gem'
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute
|
23
|
+
gem_name = options[:args][0]
|
24
|
+
if gem_name.nil?
|
25
|
+
abort 'gem name is not specified. Usage: `gem default gem_name -v 1.2.3`'
|
26
|
+
end
|
27
|
+
|
28
|
+
DefaultGemInstaller.new(
|
29
|
+
gem_home: Gem.paths.home,
|
30
|
+
ruby_arch_dir: RbConfig::CONFIG['rubyarchdir'],
|
31
|
+
ruby_bin_dir: RbConfig::CONFIG['bindir'],
|
32
|
+
ruby_lib_dir: RbConfig::CONFIG['rubylibdir'],
|
33
|
+
dlext: RbConfig::CONFIG['DLEXT'],
|
34
|
+
).install(gem_name, version: options[:version])
|
35
|
+
end
|
36
|
+
|
37
|
+
class DefaultGemInstaller
|
38
|
+
def initialize(gem_home:, ruby_arch_dir:, ruby_bin_dir:, ruby_lib_dir:, dlext:)
|
39
|
+
@gem_home = gem_home
|
40
|
+
@ruby_arch_dir = ruby_arch_dir
|
41
|
+
@ruby_bin_dir = ruby_bin_dir
|
42
|
+
@ruby_lib_dir = ruby_lib_dir
|
43
|
+
@dlext = dlext
|
44
|
+
end
|
45
|
+
|
46
|
+
def install(gem_name, version:)
|
47
|
+
begin
|
48
|
+
spec = Gem::Dependency.new(gem_name, version).to_spec
|
49
|
+
rescue Gem::MissingSpecError => e
|
50
|
+
puts "#{e.class}: #{e.message}\n\n"
|
51
|
+
abort "#{bold('Note:')} You need to run `gem install #{gem_name}` before `gem default #{gem_name}`."
|
52
|
+
end
|
53
|
+
install_spec(spec)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def install_spec(spec)
|
59
|
+
install_dependencies(spec)
|
60
|
+
|
61
|
+
spec.require_paths.each do |require_path|
|
62
|
+
case require_path
|
63
|
+
when 'lib'
|
64
|
+
from = File.join(spec.gem_dir, require_path)
|
65
|
+
to = @ruby_lib_dir
|
66
|
+
glob_path = '**/*.rb'
|
67
|
+
when /\A#{File.join(@gem_home, 'extensions')}/
|
68
|
+
from = require_path
|
69
|
+
to = @ruby_arch_dir
|
70
|
+
glob_path = "**/*.#{@dlext}"
|
71
|
+
else
|
72
|
+
raise "Unexpected require_path #{require_path.dump} is found in #{spec.name.dump}."
|
73
|
+
end
|
74
|
+
|
75
|
+
files = Dir.glob(File.join(from, glob_path)).select(&File.method(:file?)).map! do |path|
|
76
|
+
# delete_prefix is from Ruby 2.5 and too new
|
77
|
+
path.sub(/\A#{from}/, '')
|
78
|
+
end.sort!
|
79
|
+
copy_files(files, from: from, to: to)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Overwrite bin scripts generated by RubyGems which require "Gemfile" specification.
|
83
|
+
copy_files(spec.executables, from: spec.bin_dir, to: @ruby_bin_dir, preserve_old: true)
|
84
|
+
# copy_files(spec.executables, from: spec.bin_dir, to: File.join(@gem_home, 'bin'), preserve_old: true)
|
85
|
+
end
|
86
|
+
|
87
|
+
# TODO: resolve dependencies properly. For example, circular dependency might
|
88
|
+
# loop infinitely and duplicated dependencies might be installed several times.
|
89
|
+
def install_dependencies(spec)
|
90
|
+
spec.runtime_dependencies.each do |dependency|
|
91
|
+
install_spec(dependency.to_spec)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def copy_files(files, from:, to:, preserve_old: false)
|
96
|
+
puts "#{bold('=> Copying files')} from #{from.dump} to:"
|
97
|
+
files.each do |file|
|
98
|
+
from_path = File.join(from, file)
|
99
|
+
to_path = File.join(to, file)
|
100
|
+
old_path = "#{to_path}.old"
|
101
|
+
|
102
|
+
if preserve_old && File.exist?(to_path) && !File.exist?(old_path)
|
103
|
+
puts "#{to_path} (original => #{old_path})"
|
104
|
+
FileUtils.cp(to_path, old_path)
|
105
|
+
else
|
106
|
+
puts to_path
|
107
|
+
end
|
108
|
+
FileUtils.mkdir_p(File.dirname(to_path))
|
109
|
+
FileUtils.cp(from_path, to_path)
|
110
|
+
end
|
111
|
+
puts
|
112
|
+
end
|
113
|
+
|
114
|
+
def bold(text)
|
115
|
+
"\e[1m#{text}\e[0m"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
private_constant :DefaultGemInstaller
|
119
|
+
end
|
120
|
+
|
121
|
+
Gem::CommandManager.instance.register_command :default
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rubygems/commands/default_command'
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-default
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Kokubun
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Make an arbitrary gem a default gem
|
42
|
+
email:
|
43
|
+
- takashikkbn@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- gem-default.gemspec
|
56
|
+
- lib/rubygems/commands/default_command.rb
|
57
|
+
- lib/rubygems_plugin.rb
|
58
|
+
homepage: https://github.com/k0kubun/gem-default
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.1.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.0.3
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Make an arbitrary gem a default gem
|
81
|
+
test_files: []
|