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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/exe/pry-try +70 -57
  3. data/lib/pry-try/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 405e16310b0d37efbb3e8504231322984bd65084
4
- data.tar.gz: 417378b3d4253bda89879d51d694603b357bb0fc
3
+ metadata.gz: ceeebe103aab15f554d27433ac565082fd17c2c0
4
+ data.tar.gz: cf9bc6f2f1c46b6ae764320c3f9f2200f45016b9
5
5
  SHA512:
6
- metadata.gz: 79bb275f7b24f7bb331b0582e44654853f34cda53cc9809f8b056f6cce4f575ffee92d3eea0d193039f8c7d0683d8e4bfde3fb48e8e87a55746da57c6052620b
7
- data.tar.gz: 97e2af0d7133ad5fe1d106a61c50363c04c9bab1426d9356beb7301cc65000365941753be72bccfc72d2cefc5c7b4bdd2263c5abe8c9b55bd75ef5d5e4cd6828
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
- if ARGV.empty? || %w(-h --help).include?(ARGV.first)
4
- puts(<<-EOH)
5
- EXAMPLES
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
- Try scripts:
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
- $ cat some-script.rb | pry-try
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
- Try gems:
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
- $ pry-try redis
14
- ... some bundling ...
15
- irb(main):001:0> Redis
16
- => Redis
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
- Multiple gems:
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
- $ pry-try redis rake
62
+ Example:
63
+ pry-try activesupport
21
64
 
22
- Specific version:
65
+ Start Pry-repl with activesupport required.
23
66
 
24
- $ pry-try redis '3.1.0'
67
+ pry-try activesupport '~> 4.2'
25
68
 
26
- ...or any requirement that would be understood by bundler:
69
+ Start Pry-repl with activesupport version 4.x required.
27
70
 
28
- $ pry-try redis '~> 3.1.0'
71
+ pry-try activesupport redis
29
72
 
30
- Combined with gems that don't need a specific version:
73
+ Start Pry-repl with both activesupport and redis required.
31
74
 
32
- $ pry-try redis '~> 3.1.0' rake gem_with_version '1.0'
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
- VERSION_LIKE_RE = [Gem::Requirement::PATTERN, /v?\d+\.\d+/, /^\h+$/].freeze
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
- gemfile(true) do
78
- source 'https://rubygems.org'
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}
@@ -1,3 +1,3 @@
1
1
  module PryTry
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-try
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet