Class: RegenerateBinstubsCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/executable-hooks/regenerate_binstubs_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegenerateBinstubsCommand

Returns a new instance of RegenerateBinstubsCommand.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 24

def initialize
  super 'regenerate_binstubs', 'Re run generation of executable wrappers for gems.'

  add_option(:"Install/Update", '-i', '--install-dir DIR',
    'Gem repository directory to get installed',
    'gems') do |value, options|
    options[:install_dir] = File.expand_path(value)
  end

  add_option(:"Install/Update", '-n', '--bindir DIR',
    'Directory where binary files are',
    'located') do |value, options|
    options[:bin_dir] = File.expand_path(value)
  end
end

Class Method Details

.default_install_optionsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 7

def self.default_install_options
  require 'rubygems/commands/install_command'
  Gem::Command.extra_args = Gem.configuration[:gem]
  config_args = Gem.configuration[:install]
  config_args =
    case config_args
    when String
      config_args.split ' '
    else
      Array(config_args)
    end
  Gem::Command.add_specific_extra_args 'install', config_args
  ic = Gem::Commands::InstallCommand.new
  ic.handle_options ["install"]
  ic.options
end

Instance Method Details

#argumentsObject

:nodoc:



40
41
42
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 40

def arguments # :nodoc:
  "STRING        start of gem name to regenerate binstubs"
end

#defaults_strObject

:nodoc:



48
49
50
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 48

def defaults_str # :nodoc:
  ""
end

#descriptionObject

:nodoc:



52
53
54
55
56
57
58
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 52

def description # :nodoc:
  'Re run generation of executable wrappers for all gems. '+
  'Wrappers will be compatible with both rubygems and bundler. '+
  'The switcher is BUNDLE_GEMFILE environment variable, '+
  'when set it switches to bundler mode, when not set, '+
  'then the command will work as it was with pure rubygems.'
end

#executeObject



60
61
62
63
64
65
66
67
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 60

def execute
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('2.0.0') then
    # https://github.com/rubygems/rubygems/issues/326
    puts "try also: gem pristine --binstubs"
  end
  ExecutableHooks::Wrapper.new(options).install
  execute_no_wrapper
end

#execute_no_wrapper(wrapper_name = ExecutableHooks::Wrapper.expanded_wrapper_name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 69

def execute_no_wrapper(wrapper_name = ExecutableHooks::Wrapper.expanded_wrapper_name)
  require 'executable-hooks/installer'
  name = get_one_optional_argument || ''
  specs = installed_gems.select{|spec| spec.name =~ /^#{name}/i }
  specs.each do |spec|
    executables = spec.executables.reject{ |name| name == 'executable-hooks-uninstaller' }
    unless executables.empty?
      try_to_fix_binstubs(spec, executables, wrapper_name) or
      try_to_install_binstubs(spec) or
      $stderr.puts "##{spec.name} #{spec.version} not found in GEM_PATH"
    end
  end
end

#usageObject

:nodoc:



44
45
46
# File 'lib/executable-hooks/regenerate_binstubs_command.rb', line 44

def usage # :nodoc:
  "#{program_name} [STRING]"
end