Class: RCoLi::SystemExecutor
- Inherits:
-
Object
- Object
- RCoLi::SystemExecutor
- Includes:
- Singleton
- Defined in:
- lib/rcoli/utils.rb
Instance Method Summary collapse
- #execute(command, *args) ⇒ Object
-
#initialize ⇒ SystemExecutor
constructor
A new instance of SystemExecutor.
- #register(file) ⇒ Object
Constructor Details
#initialize ⇒ SystemExecutor
Returns a new instance of SystemExecutor.
54 55 |
# File 'lib/rcoli/utils.rb', line 54 def initialize end |
Instance Method Details
#execute(command, *args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rcoli/utils.rb', line 63 def execute(command, *args) cmnd = @commands[command.to_s] if cmnd cmnd.scan(/\$\{([^}\s]+)\}/).each do |s| context = args[0] (s[0].split('.').each{|key| context = (context.is_a? Hash) ? context[key] : nil}) cmnd = cmnd.gsub("${#{s[0]}}", ((context.is_a? Array) ? context.join(',') : context.to_s)) if context end # ALTERNATIVE SOLUTION # cmnd.to_enum(:scan, /\$\{([^\s]+)\}/).map {[Regexp.last_match[0], Regexp.last_match[1].split('.')]}.each do |m| # context = (context.nil? ? config : context)[m[1].delete_at(0)] until m[1].size == 0 # cmnd = cmnd.sub(m[0], context) if context.is_a? String # end log.debug("EXEC: #{cmnd}") system(cmnd) unless ApplicationContext.instance.devmode else raise ApplicationError, "The command #{command} isn't configured. Check the file #{@source}" end end |
#register(file) ⇒ Object
57 58 59 60 61 |
# File 'lib/rcoli/utils.rb', line 57 def register(file) @source = file log.debug("Loading commands from file #{file}") @commands = YAML::load(File.open(file)) end |