pry-try 0.2.3 → 0.3.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 +4 -4
- data/exe/pry-try +70 -57
- data/lib/pry-try/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceeebe103aab15f554d27433ac565082fd17c2c0
|
4
|
+
data.tar.gz: cf9bc6f2f1c46b6ae764320c3f9f2200f45016b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0866ddc118236d382fa304ac3925cd835cfef5ede511056b0df0b90d763ffd131aeca85734c6616393c7a29221bd6b902e862f4c48b74a411d16035b665a4327'
|
7
|
+
data.tar.gz: cadf1fc27ac4bda9154ba2976b610f1f6903c0c01638624cb8c3eadcc5199ceb834c861b0033ed76ec05c40607ace320093aa0fa026e1fe9b0f2c82b45e92cd5
|
data/exe/pry-try
CHANGED
@@ -1,86 +1,99 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
VERSION_LIKE_RE = [Gem::Requirement::PATTERN, /v?\d+\.\d+/, /^\h+$/].freeze
|
4
|
+
|
5
|
+
REQUIREMENTS = {
|
6
|
+
'rails' => %w(rails/all active_support/all),
|
7
|
+
'activerecord' => %w(active_record),
|
8
|
+
'activesupport' => %w(active_support/all),
|
9
|
+
}.freeze
|
6
10
|
|
7
|
-
|
11
|
+
def parse_gems(args)
|
12
|
+
args.each_with_object([]) do |arg, obj|
|
13
|
+
matches_arg = arg.method(:match).to_proc
|
14
|
+
if VERSION_LIKE_RE.detect(&matches_arg)
|
15
|
+
obj[-1] << arg
|
16
|
+
else
|
17
|
+
obj << [arg]
|
18
|
+
end
|
19
|
+
end.map do |gem|
|
20
|
+
if r = REQUIREMENTS[gem.first]
|
21
|
+
gem << {:require => r}
|
22
|
+
else
|
23
|
+
gem
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
8
27
|
|
9
|
-
|
28
|
+
def template_for_gems(gems)
|
29
|
+
require 'erb'
|
30
|
+
@gems = gems
|
31
|
+
ERB.new(<<-GEMFILE, 1, "-").result
|
32
|
+
begin
|
33
|
+
require "bundler/inline"
|
34
|
+
rescue LoadError => e
|
35
|
+
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
|
36
|
+
raise e
|
37
|
+
end
|
10
38
|
|
11
|
-
|
39
|
+
gemfile(true) do
|
40
|
+
source 'https://rubygems.org'
|
41
|
+
gem 'pry'
|
42
|
+
<% @gems.each do |(gem, *opts)|
|
43
|
+
options = opts.last.is_a?(Hash) ? opts.pop : {}
|
44
|
+
version = opts.pop -%>
|
45
|
+
gem <%= gem.inspect %><% if version %>, <%= version.inspect %> <% end %><% if options[:require] %>, :require => <%= options[:require] %><% end %>
|
46
|
+
<% end -%>
|
47
|
+
end
|
48
|
+
GEMFILE
|
49
|
+
end
|
12
50
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
51
|
+
if ARGV.empty? || %w(-h --help).include?(ARGV.first)
|
52
|
+
puts(<<-EOH)
|
53
|
+
Usage:
|
54
|
+
pry-try activesupport
|
55
|
+
cat script.rb | pry-try
|
17
56
|
|
18
|
-
|
57
|
+
Options:
|
58
|
+
-h Show this help
|
59
|
+
-v Show version
|
60
|
+
--inline Print script to STDOUT with inline gemfile as specified
|
19
61
|
|
20
|
-
|
62
|
+
Example:
|
63
|
+
pry-try activesupport
|
21
64
|
|
22
|
-
|
65
|
+
Start Pry-repl with activesupport required.
|
23
66
|
|
24
|
-
|
67
|
+
pry-try activesupport '~> 4.2'
|
25
68
|
|
26
|
-
|
69
|
+
Start Pry-repl with activesupport version 4.x required.
|
27
70
|
|
28
|
-
|
71
|
+
pry-try activesupport redis
|
29
72
|
|
30
|
-
|
73
|
+
Start Pry-repl with both activesupport and redis required.
|
31
74
|
|
32
|
-
|
75
|
+
pry-try --inline activesupport '~> 4.2'
|
33
76
|
|
77
|
+
Print script with inline gemfile.
|
34
78
|
EOH
|
35
79
|
exit
|
36
80
|
elsif %w(-v --version).include?(ARGV.first)
|
37
81
|
require 'pry-try'
|
38
82
|
puts PryTry::VERSION
|
39
83
|
exit
|
84
|
+
elsif %w(--inline).include?(ARGV.first)
|
85
|
+
ARGV.shift
|
86
|
+
puts template_for_gems(parse_gems(ARGV))
|
87
|
+
exit
|
40
88
|
end
|
41
89
|
|
42
|
-
|
43
|
-
|
44
|
-
def parse_args(args)
|
45
|
-
args.each_with_object([]) do |arg, obj|
|
46
|
-
matches_arg = arg.method(:match).to_proc
|
47
|
-
if VERSION_LIKE_RE.detect(&matches_arg)
|
48
|
-
obj[-1] << arg
|
49
|
-
else
|
50
|
-
obj << [arg]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
REQUIREMENTS = {
|
56
|
-
'rails' => %w(rails/all active_support/all),
|
57
|
-
'activerecord' => %w(active_record),
|
58
|
-
'activesupport' => %w(active_support/all),
|
59
|
-
}.freeze
|
60
|
-
|
61
|
-
@gems = parse_args(ARGV).map do |gem|
|
62
|
-
if r = REQUIREMENTS[gem.first]
|
63
|
-
gem << {:require => r}
|
64
|
-
else
|
65
|
-
gem
|
66
|
-
end
|
67
|
-
end
|
90
|
+
@gems = parse_gems(ARGV)
|
68
91
|
|
69
92
|
if @gems.any?
|
70
93
|
require 'tempfile'
|
71
|
-
require 'yaml'
|
72
|
-
@script = Tempfile.new('pry-try').tap do |f|
|
73
|
-
File.write(f, <<CODEZ.gsub(/\n+ *(?=\S)/, ';'))
|
74
|
-
require 'bundler/inline'
|
75
|
-
require 'yaml'
|
76
94
|
|
77
|
-
|
78
|
-
|
79
|
-
gem 'pry'
|
80
|
-
YAML.load(#{YAML.dump(@gems).inspect}).each {|gargs| gem(*gargs) }
|
81
|
-
end;nil
|
82
|
-
CODEZ
|
95
|
+
@script = Tempfile.new('pry-try').tap do |f|
|
96
|
+
File.write(f, template_for_gems(@gems).gsub(/\n+ *(?=\S)/, ';'))
|
83
97
|
end
|
98
|
+
exec %{unset BUNDLE_BIN;script=$(cat #{@script ? @script.path : ''} #{$stdin.tty? ? '' : '-'}; echo;echo '$stdin = $stdin.reopen "/dev/tty";'); printf "${script}" | pry}
|
84
99
|
end
|
85
|
-
|
86
|
-
exec %{unset BUNDLE_BIN;script=$(cat #{@script ? @script.path : ''} #{$stdin.tty? ? '' : '-'}; echo;echo '$stdin = $stdin.reopen "/dev/tty";'); printf "${script}" | pry}
|
data/lib/pry-try/version.rb
CHANGED