Class: Subcontractor::Command
- Inherits:
-
Object
- Object
- Subcontractor::Command
- Defined in:
- lib/subcontractor/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_choose_env_and_command_present?(command) ⇒ Boolean
- #_env_specifier(command) ⇒ Object
- #_set_rbenv_version ⇒ Object
- #_use_command?(command) ⇒ Boolean
- #build ⇒ Object
-
#initialize(parts, options) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(parts, options) ⇒ Command
Returns a new instance of Command.
7 8 9 10 |
# File 'lib/subcontractor/command.rb', line 7 def initialize(parts, ) @parts = parts @options = end |
Class Method Details
.build(parts, options) ⇒ Object
3 4 5 |
# File 'lib/subcontractor/command.rb', line 3 def self.build(parts, ) new(parts.dup, ).build end |
Instance Method Details
#_choose_env_and_command_present?(command) ⇒ Boolean
28 29 30 |
# File 'lib/subcontractor/command.rb', line 28 def _choose_env_and_command_present?(command) @options.has_key?(:choose_env) && system("which #{command} > /dev/null 2>&1") end |
#_env_specifier(command) ⇒ Object
38 39 40 |
# File 'lib/subcontractor/command.rb', line 38 def _env_specifier(command) @options[command] || @options[:choose_env] end |
#_set_rbenv_version ⇒ Object
32 33 34 35 36 |
# File 'lib/subcontractor/command.rb', line 32 def _set_rbenv_version env_specifier = _env_specifier(:rbenv) env_specifier = "`rbenv local`" if env_specifier == "." "env RBENV_VERSION=#{env_specifier}" end |
#_use_command?(command) ⇒ Boolean
24 25 26 |
# File 'lib/subcontractor/command.rb', line 24 def _use_command?(command) @options.has_key?(command) || _choose_env_and_command_present?(command) end |
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/subcontractor/command.rb', line 12 def build if _use_command?(:rbenv) @parts.unshift("#{_set_rbenv_version} rbenv exec") elsif _use_command?(:rvm) @parts.unshift("rvm #{_env_specifier(:rvm)} exec") elsif _use_command?(:chruby) @parts.unshift("chruby-exec #{_env_specifier(:chruby)} --") end @parts.join(" ") end |