Class: Babushka::CurrentRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/babushka/current_ruby.rb

Overview

This class provides information about the active ruby installation according to the system's $PATH. This might be different to the ruby via which babushka was invoked.

The preferred way to use this class is via `Babushka.ruby`.

Instance Method Summary collapse

Instance Method Details

#bin_dirObject

The directory in which gem binaries are found. This is sometimes different to the path that `gem` itself runs from.


27
28
29
# File 'lib/babushka/current_ruby.rb', line 27

def bin_dir
  gem_env.val_for('EXECUTABLE DIRECTORY').p
end

#gem_dirObject

The path to the current ruby's installed set of gems.


32
33
34
# File 'lib/babushka/current_ruby.rb', line 32

def gem_dir
  gem_env.val_for('INSTALLATION DIRECTORY') / 'gems'
end

#gem_versionObject

The version of the `gem` in the path.


47
48
49
# File 'lib/babushka/current_ruby.rb', line 47

def gem_version
  gem_env.val_for('RUBYGEMS VERSION').to_version
end

#gemspec_dirObject

The path to the gemspecs for the current ruby's installed set of gems.


37
38
39
# File 'lib/babushka/current_ruby.rb', line 37

def gemspec_dir
  gem_env.val_for('INSTALLATION DIRECTORY') / 'specifications'
end

#pathObject

The path the ruby binary that is visible via the $PATH.


11
12
13
# File 'lib/babushka/current_ruby.rb', line 11

def path
  @path ||= Babushka::ShellHelpers.which('ruby').p
end

#rbenv?Boolean

True if the current ruby is managed by rbenv.

Returns:

  • (Boolean)

16
17
18
# File 'lib/babushka/current_ruby.rb', line 16

def rbenv?
  path.to_s[%r{\brbenv/}]
end

#rvm?Boolean

True if the current ruby is managed by rvm.

Returns:

  • (Boolean)

21
22
23
# File 'lib/babushka/current_ruby.rb', line 21

def rvm?
  path.to_s[%r{\brvm/}]
end

#versionObject

The version of the ruby in the path.


42
43
44
# File 'lib/babushka/current_ruby.rb', line 42

def version
  @_version ||= Babushka::ShellHelpers.shell('ruby --version').scan(/^ruby (\S+)/).flatten.first.to_version
end