Module: GitWit::Commands::Util
- Included in:
- GitWit::Cli
- Defined in:
- lib/git_wit/commands/util.rb
Instance Method Summary collapse
- #app_user ⇒ Object
- #boot_app ⇒ Object
- #booted? ⇒ Boolean
- #exec_with_sudo!(user = app_user) ⇒ Object
- #load_gw_env ⇒ Object
- #rails_root ⇒ Object
- #running_as?(user) ⇒ Boolean
Instance Method Details
#app_user ⇒ Object
21 22 23 |
# File 'lib/git_wit/commands/util.rb', line 21 def app_user File.stat(rails_root).uid end |
#boot_app ⇒ Object
32 33 34 35 |
# File 'lib/git_wit/commands/util.rb', line 32 def boot_app require File. File.join(rails_root, "config/environment") unless booted? require "git_wit" end |
#booted? ⇒ Boolean
37 38 39 |
# File 'lib/git_wit/commands/util.rb', line 37 def booted? defined?(Rails) end |
#exec_with_sudo!(user = app_user) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/git_wit/commands/util.rb', line 4 def exec_with_sudo!(user = app_user) return if running_as?(user) Dir.chdir rails_root ENV["TERM"] = "dumb" load_gw_env cmd = ["sudo", "-u", "##{user}", $PROGRAM_NAME, *ARGV] exec *cmd end |
#load_gw_env ⇒ Object
13 14 15 |
# File 'lib/git_wit/commands/util.rb', line 13 def load_gw_env ENV.keys.each { |k| ENV[k.gsub /^GW_/, ""] = ENV[k] if k.start_with? "GW_" } end |
#rails_root ⇒ Object
25 26 27 28 29 30 |
# File 'lib/git_wit/commands/util.rb', line 25 def rails_root return File.(ENV["RAILS_ROOT"]) if ENV["RAILS_ROOT"] return Dir.pwd if File.exist? File.join(Dir.pwd, "config/environment.rb") return File.("..", ENV["BUNDLE_GEMFILE"]) if ENV["BUNDLE_GEMFILE"] Dir.pwd end |
#running_as?(user) ⇒ Boolean
17 18 19 |
# File 'lib/git_wit/commands/util.rb', line 17 def running_as?(user) Process.uid == user end |