Class: Herve::Ruby

Inherits:
Object
  • Object
show all
Defined in:
lib/herve/ruby.rb,
lib/herve/ruby/engine.rb,
lib/herve/ruby/request.rb

Defined Under Namespace

Classes: Engine, Request, RequestError

Constant Summary collapse

RUBY_EXTRACT_SCRIPT =
"puts(Object.const_defined?(:RUBY_ENGINE) ? RUBY_ENGINE : 'ruby')\nputs(RUBY_VERSION)\nputs(Object.const_defined?(:RUBY_PLATFORM) ? RUBY_PLATFORM : 'unknown')\nputs(Object.const_defined?(:RbConfig) && RbConfig::CONFIG['host_cpu'] ? RbConfig::CONFIG['host_cpu'] : 'unknown')\nputs(Object.const_defined?(:RbConfig) && RbConfig::CONFIG['host_os'] ? RbConfig::CONFIG['host_os'] : 'unknown')\nputs(begin; require 'rubygems'; Gem.default_dir; rescue ScriptError, NoMethodError; end)\n"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, version, path, symlink, arch, os, gem_root) ⇒ Ruby

Returns a new instance of Ruby.



129
130
131
132
133
134
135
136
137
# File 'lib/herve/ruby.rb', line 129

def initialize(key, version, path, symlink, arch, os, gem_root)
  @key = key
  @version = version
  @path = path
  @symlink = symlink
  @arch = arch
  @os = os
  @gem_root = gem_root
end

Instance Attribute Details

#archObject (readonly)

Returns the value of attribute arch.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def arch
  @arch
end

#gem_rootObject (readonly)

Returns the value of attribute gem_root.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def gem_root
  @gem_root
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def key
  @key
end

#osObject (readonly)

Returns the value of attribute os.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def os
  @os
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def path
  @path
end

Returns the value of attribute symlink.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def symlink
  @symlink
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/herve/ruby.rb', line 8

def version
  @version
end

Class Method Details

.from_directory(directory) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
# File 'lib/herve/ruby.rb', line 20

def from_directory(directory)
  dir = Pathname.new(directory)
  raise RubyError, "invalid directory #{directory}" if !dir.exist? || dir.empty?

  ruby_bin = dir.join("bin", "ruby")
  raise RubyError, "no ruby executable found" unless ruby_bin.executable?

  extract_info(ruby_bin, dir)
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Sort by version

Returns:



174
175
176
# File 'lib/herve/ruby.rb', line 174

def <=>(other)
  version <=> other.version
end

#==(other) ⇒ Boolean

Check equality. other must be a Herve::Ruby with same #version, #os, #arch and #path.

Parameters:

Returns:



181
182
183
# File 'lib/herve/ruby.rb', line 181

def ==(other)
  other.is_a?(Ruby) && (version == other.version) && (arch == other.arch) && (os == other.os) && (path == other.path)
end

#bin_pathObject



151
152
153
# File 'lib/herve/ruby.rb', line 151

def bin_path
  path.join("bin")
end

#display_nameObject



139
140
141
# File 'lib/herve/ruby.rb', line 139

def display_name
  version.to_s
end

#executable_pathObject



147
148
149
# File 'lib/herve/ruby.rb', line 147

def executable_path
  bin_path.join("ruby")
end

#gem_homeObject



155
156
157
# File 'lib/herve/ruby.rb', line 155

def gem_home
  Pathname.new(Dir.home).join(".gem", version.engine.name, version.version_number)
end

#to_json(state = nil) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/herve/ruby.rb', line 159

def to_json(state = nil, *)
  hsh = {
    key: key,
    version: display_name,
    path: path.to_s,
    arch: arch,
    os: os,
    gem_root: gem_root.to_s
  }
  hsh[:symlink] = symlink.to_s if symlink
  JSON::State.from_state(state).generate(hsh)
end

#valid?Boolean

Returns:



143
144
145
# File 'lib/herve/ruby.rb', line 143

def valid?
  executable_path.exist?
end