Sha256: 40c7528d97d6830c1fc8b37555ae2c23f41e6a9e04106d80303ac8dde3cd1af0

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

class Gem::Commands::BeitCommand < Gem::Command
  def description
    'Edit from current Gemfile'
  end

  def initialize
    super('beit', description)
  end

  def execute
    require 'rubygems/commands/path_command'
    require 'bundler/setup'

    if options[:args].first.nil?
      say("Usage: gem beit [GEM NAME]")
    elsif Bundler::SharedHelpers.in_bundle?
      beit
    else
      say("No Gemfile detected.")
    end
  end

  def beit
    cmd  = Gem::Commands::PathCommand.new
    name = options[:args].first
    spec = Bundler.locked_gems.specs.find do |s|
      name == s.name
    end

    if spec
      gem(spec.name, spec.version)
      exec("#{eit} #{cmd.find_gem_path(spec.name)}")
    else
      say("#{name} not found.")
    end
  end

  def exec *args
    say(args.join(' '))
    super
  end

  def eit
    ENV['GEM_EDITOR'] || ENV['EDITOR'] || 'vim'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gem-beit-0.6.0 lib/rubygems/commands/beit_command.rb