Class: SchemaDev::RubySelector::Chruby

Inherits:
ManagerBase show all
Defined in:
lib/schema_dev/ruby_selector.rb

Constant Summary collapse

CORE_COMMAND =
'chruby-exec'

Instance Method Summary collapse

Methods inherited from ManagerBase

installed?

Constructor Details

#initializeChruby

Returns a new instance of Chruby.



30
31
32
33
34
35
36
37
# File 'lib/schema_dev/ruby_selector.rb', line 30

def initialize
  super

  @rubies = Pathname.new(ENV['HOME'])
                    .join('.rubies')
                    .entries
                    .map { |e| e.basename.to_s }
end

Instance Method Details

#command(ruby) ⇒ Object



39
40
41
42
43
44
# File 'lib/schema_dev/ruby_selector.rb', line 39

def command(ruby)
  bash = Which.which 'bash' || abort('no bash shell found')
  ruby = @rubies.select { |e| e =~ /^(ruby-)?#{ruby}(-p.*)?$/ }
                .last || ruby
  "SHELL=#{bash} #{CORE_COMMAND} #{ruby} --"
end