Class: RubyVersionReader
- Inherits:
-
Object
- Object
- RubyVersionReader
- Includes:
- Comparable
- Defined in:
- lib/ruby_version_reader.rb
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Attribute Summary collapse
-
#environment_manager ⇒ Object
Returns the value of attribute environment_manager.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
comparable.
-
#engine ⇒ Object
accessors.
- #environment_manager_load_string ⇒ Object
- #full_version ⇒ Object
- #gemset ⇒ Object
-
#initialize(given_path = './', given_environment_manager = 'rvm', given_options = {}) ⇒ RubyVersionReader
constructor
Available options: *:rvm_path: The path to the rvm executable (used if given_environment_manager == ‘rvm’).
-
#is?(other = nil) ⇒ Boolean
(also: #is)
chaining for dsl-like language.
- #major ⇒ Object (also: #main)
- #minor ⇒ Object (also: #mini)
- #not(other) ⇒ Object (also: #not?)
- #patchlevel ⇒ Object
- #tiny ⇒ Object (also: #teeny)
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(given_path = './', given_environment_manager = 'rvm', given_options = {}) ⇒ RubyVersionReader
Available options: *:rvm_path: The path to the rvm executable (used if given_environment_manager == ‘rvm’). Default: nil.
11 12 13 14 15 16 |
# File 'lib/ruby_version_reader.rb', line 11 def initialize(given_path = './', given_environment_manager = 'rvm', = {}) @path = File.(given_path) @environment_manager = given_environment_manager @options = {} @options[:rvm_path] = [:rvm_path].to_s end |
Instance Attribute Details
#environment_manager ⇒ Object
Returns the value of attribute environment_manager.
7 8 9 |
# File 'lib/ruby_version_reader.rb', line 7 def environment_manager @environment_manager end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/ruby_version_reader.rb', line 7 def @options end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/ruby_version_reader.rb', line 7 def path @path end |
Instance Method Details
#<=>(other) ⇒ Object
comparable
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_version_reader.rb', line 46 def <=>(other) value = case other when Integer major.to_i when Float full_version.to_f when String other_engine = extract_engine_from_string(other) if engine == other_engine other = extract_full_version_from_string(other) full_version else return engine <=> other_engine end else # A tiny bit of recursion return self <=> other.to_s end value <=> other end |
#engine ⇒ Object
accessors
97 98 99 |
# File 'lib/ruby_version_reader.rb', line 97 def engine @engine ||= extract_engine_from_string(read_ruby_version_file) end |
#environment_manager_load_string ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_version_reader.rb', line 32 def environment_manager_load_string case environment_manager when 'rvm' "#{[:rvm_path].empty? ? 'rvm' : [:rvm_path]} #{to_s} do" when 'rbenv' "RBENV_VERSION=#{to_s}" when 'chruby' "chruby-exec #{to_s} --" else raise "Unsupported environment_manager: #{environment_manager.inspect}" end end |
#full_version ⇒ Object
101 102 103 |
# File 'lib/ruby_version_reader.rb', line 101 def full_version @full_version ||= extract_full_version_from_string(read_ruby_version_file) end |
#gemset ⇒ Object
28 29 30 |
# File 'lib/ruby_version_reader.rb', line 28 def gemset read_ruby_gemset_file end |
#is?(other = nil) ⇒ Boolean Also known as: is
chaining for dsl-like language
70 71 72 73 74 75 76 |
# File 'lib/ruby_version_reader.rb', line 70 def is?(other = nil) if other self == other else self end end |
#major ⇒ Object Also known as: main
105 106 107 |
# File 'lib/ruby_version_reader.rb', line 105 def major full_version.to_i end |
#minor ⇒ Object Also known as: mini
110 111 112 |
# File 'lib/ruby_version_reader.rb', line 110 def minor full_version.split('.')[1].to_i end |
#not(other) ⇒ Object Also known as: not?
90 91 92 |
# File 'lib/ruby_version_reader.rb', line 90 def not(other) self != other end |
#patchlevel ⇒ Object
120 121 122 |
# File 'lib/ruby_version_reader.rb', line 120 def patchlevel full_version.split('-')[1].to_s end |
#tiny ⇒ Object Also known as: teeny
115 116 117 |
# File 'lib/ruby_version_reader.rb', line 115 def tiny full_version.split('.')[2].to_i end |
#to_s ⇒ Object Also known as: inspect
18 19 20 21 22 23 24 25 |
# File 'lib/ruby_version_reader.rb', line 18 def to_s return @to_s if @to_s @to_s = "#{engine}-#{full_version}" @to_s += "@#{gemset}" unless gemset.empty? @to_s end |