tmpgem 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebfffc424ba8548c95d4f63e24bce3ae5876b0fd
4
+ data.tar.gz: b55537b4aeda7885a06025a07c2b66fa5957a6bf
5
+ SHA512:
6
+ metadata.gz: a2525b820b78eb94fcbf25e2739d478ee727e365a5d8ff46723cf2c9f61204112f5353339ab253f07beb5b30512b53dfbd2f999fe082f7712ce07e5495b90434
7
+ data.tar.gz: 0b743384c7e583acd036e849e9b163c20e93971e451df02ec3cc846f3ac32f9aa25ce701aa09a34b9a17c274b3e0b382d4db10ae560ee4f14cf1a58388a2e274
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tmpgem.gemspec
4
+ gemspec
@@ -0,0 +1,58 @@
1
+ # Tmpgem
2
+
3
+ Tmpgem is a temporary gem installer.
4
+
5
+ ## What's this?
6
+
7
+ You install a gem by `rake install:local` when you develop the gem.
8
+ But the way has a problem. The way changes installed gem.
9
+
10
+ ```bash
11
+ $ cd your/gem/dir/
12
+ # Editing code
13
+ $ vim lib/yourgem.rb
14
+ $ bundle exec rake install:local
15
+
16
+ # Checking yourgem behaviour
17
+ $ yourgem --some-option
18
+
19
+ # Run other gem that uses the yourgem as a library.
20
+ $ awesome-yourgem --foobar # => It run with changed yourgem!
21
+ ```
22
+
23
+ If you add `binding.pry` to yourgem, the `awesome-yourgem` command executes pry. It is an unexpected behaviour.
24
+ You should restore original yourgem to prevent this bug.
25
+
26
+
27
+ This gem installs and restores a gem automatically.
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'tmpgem'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install tmpgem
44
+
45
+ ## Usage
46
+
47
+ ```bash
48
+ $ cd your/gem/dir/
49
+ # Edit gem source code
50
+ $ tmpgem
51
+ tmpgem-0.1.0.gem is installed temporary. Please CTRL-C when you do not need this gem.
52
+ # You can use the edited gem until CTRL-C.
53
+ ^C
54
+ Restoring the gem...
55
+ tmpgem is restored!
56
+
57
+ # You can use the original gem.
58
+ ```
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tmpgem"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!ruby
2
+
3
+ require 'tmpgem'
4
+
5
+ exit Tmpgem::CLI.new(ARGV).run
@@ -0,0 +1,11 @@
1
+ require 'open3'
2
+ require 'optparse'
3
+ require 'pathname'
4
+ require 'tmpdir'
5
+
6
+ require "tmpgem/version"
7
+ require 'tmpgem/cli'
8
+
9
+ module Tmpgem
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,115 @@
1
+ module Tmpgem
2
+ class CLI
3
+ class CommandExecutionError < StandardError; end
4
+
5
+ def initialize(argv)
6
+ @argv = argv
7
+ @debug = false
8
+ end
9
+
10
+ def run
11
+ parse_args
12
+
13
+ gemspecs = Dir.glob('*.gemspec')
14
+ unless gemspecs.size == 1
15
+ $stderr.puts "gemspec must be one, but got #{gemspecs.join(', ')}."
16
+ return 1
17
+ end
18
+ gemspec = gemspecs.first
19
+ fname = build(gemspec)
20
+
21
+ backup_original(fname) do
22
+ install(fname)
23
+ puts "#{fname} is installed temporary. Please CTRL-C when you do not need this gem."
24
+ sleep
25
+ end
26
+ return 0
27
+ end
28
+
29
+ private
30
+
31
+ def parse_args
32
+ opt = OptionParser.new
33
+ opt.on('-d', '--debug') { @debug = true }
34
+ opt.parse!(@argv)
35
+ end
36
+
37
+ def capture3!(*cmd)
38
+
39
+ Open3.capture3(*cmd).tap do |out, err, status|
40
+ msg = <<~MSG
41
+ Cmd: #{cmd.join(' ')}
42
+ Status: #{status.exitstatus}
43
+ STDOUT:
44
+ #{out}
45
+ STDERR:
46
+ #{err}
47
+ MSG
48
+ debug_log("Command is executed.\n" + msg)
49
+
50
+ unless status.success?
51
+ raise CommandExecutionError, "Command Execution is failed\n" + msg
52
+ end
53
+ end
54
+ end
55
+
56
+ def debug?
57
+ @debug
58
+ end
59
+
60
+ def debug_log(*args)
61
+ return unless debug?
62
+ $stderr.puts(*args)
63
+ end
64
+
65
+ # @return [String] `*.gem` filename
66
+ def build(gemspec)
67
+ out, _err, _status = capture3!('gem', 'build', gemspec)
68
+ out.each_line.find do |line|
69
+ break $1 if line =~ /^ File: (.+)/
70
+ end
71
+ end
72
+
73
+ def install(fname)
74
+ capture3!('gem', 'install', '--local', fname)
75
+ end
76
+
77
+ def backup_original(fname)
78
+ cache = Gem.path.find do |dir|
79
+ cache = Pathname(dir) / 'cache' / fname
80
+ break cache if cache.exist?
81
+ end
82
+
83
+ unless cache
84
+ yield
85
+ return
86
+ end
87
+
88
+ Dir.mktmpdir do |tmpdir|
89
+ tmpfile = Pathname(tmpdir) / fname
90
+ debug_log cache
91
+ debug_log tmpfile
92
+ FileUtils.cp(cache, tmpfile)
93
+ begin
94
+ yield
95
+ rescue Interrupt
96
+ puts 'Restoring the gem...'
97
+ gemname = gemname(fname)
98
+ version = version(fname)
99
+ capture3!('gem', 'uninstall', gemname, '--version', version, '--ignore-dependencies')
100
+ FileUtils.cp(tmpfile, cache)
101
+ capture3!('gem', 'install', '--local', gemname, chdir: File.dirname(tmpfile))
102
+ puts "#{gemname(fname)} is restored!"
103
+ end
104
+ end
105
+ end
106
+
107
+ def gemname(fname)
108
+ fname.match(/^(.+)-([^-]+)\.gem$/)[1]
109
+ end
110
+
111
+ def version(fname)
112
+ fname.match(/^(.+)-([^-]+)\.gem$/)[2]
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,3 @@
1
+ module Tmpgem
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tmpgem/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tmpgem"
8
+ spec.version = Tmpgem::VERSION
9
+ spec.authors = ["Masataka Kuwabara"]
10
+ spec.email = ["kuwabara@pocke.me"]
11
+
12
+ spec.summary = %q{Temporary gem installer}
13
+ spec.description = %q{Temporary gem installer}
14
+ spec.homepage = "https://github.com/pocke/tmpgem"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmpgem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-22 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: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Temporary gem installer
42
+ email:
43
+ - kuwabara@pocke.me
44
+ executables:
45
+ - tmpgem
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - exe/tmpgem
56
+ - lib/tmpgem.rb
57
+ - lib/tmpgem/cli.rb
58
+ - lib/tmpgem/version.rb
59
+ - tmpgem.gemspec
60
+ homepage: https://github.com/pocke/tmpgem
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.11
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Temporary gem installer
83
+ test_files: []