Class: Asmodai::Info
- Inherits:
-
Object
- Object
- Asmodai::Info
- Defined in:
- lib/asmodai/info.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#base_file ⇒ Object
Returns the generated base file where the daemon class is declared in.
- #base_file_owner ⇒ Object
-
#daemon_class ⇒ Object
Returns the class of the Daemon.
-
#daemon_class_name ⇒ Object
Returns the camelized daemon name.
-
#daemon_name ⇒ Object
Returns the name of the daemon which is equal to the name of the directory, the daemon lives in.
-
#execute_sudo_checked(cmd) ⇒ Object
Executes cmd in the context of the user, even if asmodai is called sudoed.
-
#initialize(path = Asmodai.root) ⇒ Info
constructor
A new instance of Info.
-
#run_as_sudo? ⇒ Boolean
Return the sudoer if present, false otherwise.
- #rvm_environment? ⇒ Boolean
- #rvm_path ⇒ Object
- #rvm_ruby_string ⇒ Object
- #rvm_wrapper_path ⇒ Object
Constructor Details
#initialize(path = Asmodai.root) ⇒ Info
Returns a new instance of Info.
13 14 15 |
# File 'lib/asmodai/info.rb', line 13 def initialize(path=Asmodai.root) self.path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/asmodai/info.rb', line 5 def path @path end |
Class Method Details
.current ⇒ Object
8 9 10 |
# File 'lib/asmodai/info.rb', line 8 def current @current||=self.new end |
Instance Method Details
#base_file ⇒ Object
Returns the generated base file where the daemon class is declared in.
53 54 55 |
# File 'lib/asmodai/info.rb', line 53 def base_file path.join("#{daemon_name}.rb") end |
#base_file_owner ⇒ Object
57 58 59 |
# File 'lib/asmodai/info.rb', line 57 def base_file_owner Etc.getpwuid(Pathname.new(base_file).stat.uid) end |
#daemon_class ⇒ Object
Returns the class of the Daemon
46 47 48 49 |
# File 'lib/asmodai/info.rb', line 46 def daemon_class require "./#{daemon_name}" eval(daemon_class_name) end |
#daemon_class_name ⇒ Object
Returns the camelized daemon name
24 25 26 |
# File 'lib/asmodai/info.rb', line 24 def daemon_class_name daemon_name.camelize end |
#daemon_name ⇒ Object
Returns the name of the daemon which is equal to the name of the directory, the daemon lives in
19 20 21 |
# File 'lib/asmodai/info.rb', line 19 def daemon_name File.basename(self.path) end |
#execute_sudo_checked(cmd) ⇒ Object
Executes cmd in the context of the user, even if asmodai is called sudoed
72 73 74 75 76 77 78 |
# File 'lib/asmodai/info.rb', line 72 def execute_sudo_checked(cmd) if (su=run_as_sudo?) `sudo -u #{su} bash -l -c '#{cmd}'`.strip else `#{cmd}`.strip end end |
#run_as_sudo? ⇒ Boolean
Return the sudoer if present, false otherwise
62 63 64 65 66 67 68 |
# File 'lib/asmodai/info.rb', line 62 def run_as_sudo? if ENV['USER']=='root' and (su=ENV['SUDO_USER']) su else false end end |
#rvm_environment? ⇒ Boolean
28 29 30 |
# File 'lib/asmodai/info.rb', line 28 def rvm_environment? !rvm_ruby_string.empty? end |
#rvm_path ⇒ Object
36 37 38 39 |
# File 'lib/asmodai/info.rb', line 36 def rvm_path execute_sudo_checked( "env | grep rvm_path | grep -v SUDO").strip.split("=").last end |
#rvm_ruby_string ⇒ Object
32 33 34 |
# File 'lib/asmodai/info.rb', line 32 def rvm_ruby_string execute_sudo_checked("env | grep rvm_ruby_string | grep -v SUDO").strip end |
#rvm_wrapper_path ⇒ Object
41 42 43 |
# File 'lib/asmodai/info.rb', line 41 def rvm_wrapper_path File.join(rvm_path, "bin/bootup_asmodai") end |