Class: Irgat::Irgat
- Inherits:
-
Object
- Object
- Irgat::Irgat
- Includes:
- Dependencies, Execs, Help, Log, Mail
- Defined in:
- lib/irgat.rb
Constant Summary collapse
- @@debug_level =
- Class top variable debug level
-
can override config debug level
nil
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
accesor to action.
-
#commands_launched ⇒ Object
readonly
accesor to command launched.
-
#config ⇒ Object
readonly
accesor to configs.
-
#config_module ⇒ Object
readonly
Returns the value of attribute config_module.
-
#folders ⇒ Object
readonly
accesor to folders.
-
#init_time ⇒ Object
readonly
accesor to init time.
-
#log_process ⇒ Object
readonly
accesor log.
-
#programs ⇒ Object
readonly
accesor to programs.
Instance Method Summary collapse
- #help(args) ⇒ Object
-
#initialize(values = {}) ⇒ Irgat
constructor
simple initialize of a Irgat object…
-
#load_config(config_file = nil) ⇒ Object
method to load the config options for a module and return a hash symbol.
- #process(args = []) ⇒ Object
Methods included from Dependencies
Methods included from Execs
#execute_command, #exit_with_error
Methods included from Mail
Methods included from Log
#log, #output_log, #report_to_email, #report_to_log
Methods included from Help
Constructor Details
#initialize(values = {}) ⇒ Irgat
simple initialize of a Irgat object… loading general config
84 85 86 87 88 89 90 91 |
# File 'lib/irgat.rb', line 84 def initialize(values = {}) @init_time = Time.now @config = self.load_config # modify debug by cmd line class || scape nil value to 0 if @@debug_level.to_i >= 1 @config[:debug_level] = @@debug_level.to_i end end |
Instance Attribute Details
#action ⇒ Object (readonly)
accesor to action
66 67 68 |
# File 'lib/irgat.rb', line 66 def action @action end |
#commands_launched ⇒ Object (readonly)
accesor to command launched
64 65 66 |
# File 'lib/irgat.rb', line 64 def commands_launched @commands_launched end |
#config ⇒ Object (readonly)
accesor to configs
53 54 55 |
# File 'lib/irgat.rb', line 53 def config @config end |
#config_module ⇒ Object (readonly)
Returns the value of attribute config_module.
54 55 56 |
# File 'lib/irgat.rb', line 54 def config_module @config_module end |
#folders ⇒ Object (readonly)
accesor to folders
60 61 62 |
# File 'lib/irgat.rb', line 60 def folders @folders end |
#init_time ⇒ Object (readonly)
accesor to init time
56 57 58 |
# File 'lib/irgat.rb', line 56 def init_time @init_time end |
#log_process ⇒ Object (readonly)
accesor log
62 63 64 |
# File 'lib/irgat.rb', line 62 def log_process @log_process end |
#programs ⇒ Object (readonly)
accesor to programs
58 59 60 |
# File 'lib/irgat.rb', line 58 def programs @programs end |
Instance Method Details
#help(args) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/irgat.rb', line 93 def help(args) @log_to_stdout = true # help args.shift pattern = args.to_s show_help(pattern, exit_irgat = true) end |
#load_config(config_file = nil) ⇒ Object
method to load the config options for a module and return a hash symbol
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/irgat.rb', line 150 def load_config(config_file = nil) module_name = self.class.to_s.downcase.split('::').last config_file ||= "#{ IRGAT_CONFIG }/#{ module_name }.yml" if test(?e,config_file) config_yml = YAML.load_file(config_file ) config_to_symbols = Hash.new config_yml.each{|k, v| config_to_symbols[k.to_sym] = v} else log("warning", "No config '#{ config_file } found. Loading module with empty config", 2) config_to_symbols = {:subsystem_name => module_name, :subsystem_description => "Irgat #{ module_name } module", :log_file_actions => [], :log_mail_actions => [] } end config_to_symbols end |
#process(args = []) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/irgat.rb', line 101 def process(args = []) irgat_module = args.shift # get subsytem if active FIXME if !@config[:enable_subsystem].include?(irgat_module) exit_with_error('Module not enable in irgat config', { :exit_level => 2 }) end # action ? ( args.first ? action = args.shift : action = "default" ) # irgat options, extract from here the irgat options values module_args = Array.new while arg = args.shift case arg when "-w","--without_output" # modify stdout $stdout = File.new("/dev/null","w") when "-d","--debug_level" # take new debug level @@debug_level = args.shift else module_args << arg end end # init the module begin require 'modules/' + irgat_module irgat_process = Object.module_eval("#{ irgat_module.capitalize }").new({:action => action }) rescue LoadError => msj exit_with_error("Unable to start the #{ irgat_module } module. Error was: #{ msj.backtrace.to_s } ", { :exit_level => 2 }) end # scape possible private methods throught a bug in send method # http://joshstaiger.org/archives/2006/12/the_ruby_send_h.html if irgat_process.public_methods.include?(action) module_return = irgat_process.send(action, module_args) else exit_with_error("Unable to exec action. Not avaible public method '#{ action }' in '#{ irgat_module }' Module.", { :exit_level => 2 }) end # report output_log(irgat_process, { :main_msj => (module_return || "[IRGAT] [#{ irgat_module.upcase }] [OK] #{ action } process in #{ @config[:server_name] }")}) exit 0 end |