Sha256: 18ab3842de09ac1d4c01b27193ff426eb9b5fe8b65d5401ec02d218c11b678f7

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

#!/usr/bin/env ruby

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 $stdin.tty?
  require 'tempfile'
  require 'yaml'
  script = Tempfile.new.tap do |f|
    File.write(f, <<CODEZ.gsub(/\n+ *(?=\S)/, ';'))
require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  gem 'pry'
  YAML.load(#{YAML.dump(gems).inspect}).each {|gargs| gem(*gargs) }
end
$stdin = $stdin.reopen '/dev/tty';
CODEZ
  end
  exec %{cat #{script.path} | pry}
else
  exec %{script=$(cat;echo; echo '$stdin = $stdin.reopen "/dev/tty";'); printf "${script}" | pry}
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pry-try-0.2.2 exe/pry-try
pry-try-0.2.1 exe/pry-try
pry-try-0.2.0 exe/pry-try