Class: RightDevelop::Utility::Shell
- Inherits:
-
RightGit::Shell::Default
- Object
- RightGit::Shell::Default
- RightDevelop::Utility::Shell
- Defined in:
- lib/right_develop/utility/shell.rb
Overview
extends default shell easy-singleton from right_git gem.
Defined Under Namespace
Classes: NullLoggerSingleton
Instance Method Summary collapse
-
#configure_executioner(executioner, options) ⇒ Object
Overrides ::RightGit::Shell::Default#configure_executioner.
-
#default_logger ⇒ Logger
RightSupport::Log::Mixin.default_logger.
-
#execute(cmd, options = {}) ⇒ Integer
Overrides ::RightGit::Shell::Default#execute.
-
#is_darwin? ⇒ TrueClass|FalseClass
True if running on Mac OS X platform.
-
#is_linux? ⇒ TrueClass|FalseClass
True if running on Linux platform.
-
#is_windows? ⇒ TrueClass|FalseClass
True if running on Windows platform.
-
#null_logger ⇒ Logger
Creates a null logger.
-
#setup_clean_env ⇒ Object
bundle exec sets GEM_HOME and GEM_PATH (in Windows?) and these need to be wacked in order to have a pristing rubygems environment since bundler won’t clean them.
-
#wrap_executioner_with_clean_env(executioner) ⇒ Proc
Encapsulates executioner with bundler-defeating logic, but only if bundler has been loaded by current process.
Instance Method Details
#configure_executioner(executioner, options) ⇒ Object
Overrides ::RightGit::Shell::Default#configure_executioner
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/right_develop/utility/shell.rb', line 129 def configure_executioner(executioner, ) # super configure early to ensure that any custom env vars are set after # restoring the pre-bundler env. executioner = super(executioner, ) # clean all bundler env vars, if requested. if [:clean_bundler_env] executioner = wrap_executioner_with_clean_env(executioner) end executioner end |
#default_logger ⇒ Logger
Returns RightSupport::Log::Mixin.default_logger.
92 93 94 |
# File 'lib/right_develop/utility/shell.rb', line 92 def default_logger RightSupport::Log::Mixin.default_logger end |
#execute(cmd, options = {}) ⇒ Integer
Overrides ::RightGit::Shell::Default#execute
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/right_develop/utility/shell.rb', line 113 def execute(cmd, = {}) = { :clean_bundler_env => true, :sudo => false }.merge() if [:sudo] fail "Not available in Windows" if is_windows? cmd = "sudo #{cmd}" unless ::Process.euid == 0 end # super execute. super(cmd, ) end |
#is_darwin? ⇒ TrueClass|FalseClass
Returns true if running on Mac OS X platform.
75 76 77 |
# File 'lib/right_develop/utility/shell.rb', line 75 def is_darwin? return !!(RUBY_PLATFORM =~ /darwin/i) end |
#is_linux? ⇒ TrueClass|FalseClass
Returns true if running on Linux platform.
80 81 82 |
# File 'lib/right_develop/utility/shell.rb', line 80 def is_linux? return !!(RUBY_PLATFORM =~ /linux/i) end |
#is_windows? ⇒ TrueClass|FalseClass
Returns true if running on Windows platform.
70 71 72 |
# File 'lib/right_develop/utility/shell.rb', line 70 def is_windows? return !!(RUBY_PLATFORM =~ /mswin|win32|dos|mingw|cygwin/i) end |
#null_logger ⇒ Logger
Creates a null logger.
87 88 89 |
# File 'lib/right_develop/utility/shell.rb', line 87 def null_logger NullLoggerSingleton.instance end |
#setup_clean_env ⇒ Object
bundle exec sets GEM_HOME and GEM_PATH (in Windows?) and these need to be wacked in order to have a pristing rubygems environment since bundler won’t clean them. also, if you ‘bundle exec rake …’ and then put arguments to the right of the task name, then these args won’t appear in Bundler::ORIGINAL_ENV. example: “bundle exec rake build:all DEBUG=true …”
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/right_develop/utility/shell.rb', line 49 def setup_clean_env # user may be running gem binary directly without bundler. if defined?(::Bundler) # a little revisionist history music... ::ENV.each do |key, value| if key.start_with?('GEM_') || key.start_with?('BUNDLER_') ::Bundler::ORIGINAL_ENV[key] = nil elsif Bundler::ORIGINAL_ENV[key].nil? ::Bundler::ORIGINAL_ENV[key] = value end end ::Bundler.with_clean_env do # now the ENV is clean and not missing any right-hand args so replace # the ORIGINAL_ENV. ::Bundler::ORIGINAL_ENV.replace(ENV) end end true end |
#wrap_executioner_with_clean_env(executioner) ⇒ Proc
Encapsulates executioner with bundler-defeating logic, but only if bundler has been loaded by current process.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/right_develop/utility/shell.rb', line 147 def wrap_executioner_with_clean_env(executioner) # only if bundler is loaded. if defined?(::Bundler) # double-lambda, single call freezes the inner call made to previous # definition of executioner. executioner = lambda do |e| lambda { ::Bundler.with_clean_env { e.call } } end.call(executioner) end executioner end |