Class: Herve::Ruby
- Inherits:
-
Object
- Object
- Herve::Ruby
- 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
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#gem_root ⇒ Object
readonly
Returns the value of attribute gem_root.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#symlink ⇒ Object
readonly
Returns the value of attribute symlink.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Sort by version.
-
#==(other) ⇒ Boolean
Check equality.
- #bin_path ⇒ Object
- #display_name ⇒ Object
- #executable_path ⇒ Object
- #gem_home ⇒ Object
-
#initialize(key, version, path, symlink, arch, os, gem_root) ⇒ Ruby
constructor
A new instance of Ruby.
- #to_json(state = nil) ⇒ Object
- #valid? ⇒ Boolean
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
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
8 9 10 |
# File 'lib/herve/ruby.rb', line 8 def arch @arch end |
#gem_root ⇒ Object (readonly)
Returns the value of attribute gem_root.
8 9 10 |
# File 'lib/herve/ruby.rb', line 8 def gem_root @gem_root end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/herve/ruby.rb', line 8 def key @key end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
8 9 10 |
# File 'lib/herve/ruby.rb', line 8 def os @os end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/herve/ruby.rb', line 8 def path @path end |
#symlink ⇒ Object (readonly)
Returns the value of attribute symlink.
8 9 10 |
# File 'lib/herve/ruby.rb', line 8 def symlink @symlink end |
#version ⇒ Object (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
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
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.
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_path ⇒ Object
151 152 153 |
# File 'lib/herve/ruby.rb', line 151 def bin_path path.join("bin") end |
#display_name ⇒ Object
139 140 141 |
# File 'lib/herve/ruby.rb', line 139 def display_name version.to_s end |
#executable_path ⇒ Object
147 148 149 |
# File 'lib/herve/ruby.rb', line 147 def executable_path bin_path.join("ruby") end |
#gem_home ⇒ Object
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
143 144 145 |
# File 'lib/herve/ruby.rb', line 143 def valid? executable_path.exist? end |