Class: Asmodai::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/asmodai/info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/asmodai/info.rb', line 5

def path
  @path
end

Class Method Details

.currentObject



8
9
10
# File 'lib/asmodai/info.rb', line 8

def current
  @current||=self.new
end

Instance Method Details

#base_fileObject

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_ownerObject



57
58
59
# File 'lib/asmodai/info.rb', line 57

def base_file_owner
  Etc.getpwuid(Pathname.new(base_file).stat.uid)
end

#daemon_classObject

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_nameObject

Returns the camelized daemon name



24
25
26
# File 'lib/asmodai/info.rb', line 24

def daemon_class_name
  daemon_name.camelize
end

#daemon_nameObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


28
29
30
# File 'lib/asmodai/info.rb', line 28

def rvm_environment?
  !rvm_ruby_string.empty?
end

#rvm_pathObject



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_stringObject



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_pathObject



41
42
43
# File 'lib/asmodai/info.rb', line 41

def rvm_wrapper_path
  File.join(rvm_path, "bin/bootup_asmodai")
end