Sha256: ddc2a2712a85c505f777f9c488ba3a82941f16605465aea068497d86397ed47c
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
#!/usr/bin/env ruby if ARGV.empty? || %w(-h --help).include?(ARGV.first) puts(<<-EOH) EXAMPLES Try scripts: $ cat some-script.rb | pry-try Try gems: $ pry-try redis ... some bundling ... irb(main):001:0> Redis => Redis Multiple gems: $ pry-try redis rake Specific version: $ pry-try redis '3.1.0' ...or any requirement that would be understood by bundler: $ pry-try redis '~> 3.1.0' Combined with gems that don't need a specific version: $ pry-try redis '~> 3.1.0' rake gem_with_version '1.0' EOH exit elsif %w(-v --version).include?(ARGV.first) require 'pry-try' puts PryTry::VERSION exit end VERSION_LIKE_RE = [Gem::Requirement::PATTERN, /v?\d+\.\d+/, /^\h+$/].freeze def parse_args(args) args.each_with_object([]) do |arg, obj| matches_arg = arg.method(:match).to_proc if VERSION_LIKE_RE.detect(&matches_arg) obj[-1] << arg else obj << [arg] end end end REQUIREMENTS = { 'rails' => %w(rails/all active_support/all), 'activerecord' => %w(active_record), 'activesupport' => %w(active_support/all), }.freeze @gems = parse_args(ARGV).map do |gem| if r = REQUIREMENTS[gem.first] gem << {:require => r} else gem end end if @gems.any? require 'tempfile' require 'yaml' @script = Tempfile.new('pry-try').tap do |f| File.write(f, <<CODEZ.gsub(/\n+ *(?=\S)/, ';')) require 'bundler/inline' require 'yaml' gemfile(true) do source 'https://rubygems.org' gem 'pry' YAML.load(#{YAML.dump(@gems).inspect}).each {|gargs| gem(*gargs) } end;nil CODEZ end end exec %{unset BUNDLE_BIN;script=$(cat #{@script ? @script.path : ''} #{$stdin.tty? ? '' : '-'}; echo;echo '$stdin = $stdin.reopen "/dev/tty";'); printf "${script}" | pry}
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pry-try-0.2.3 | exe/pry-try |