Class: ScriptRunner::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/script-runner/main.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Main

Returns a new instance of Main.



5
6
7
# File 'lib/script-runner/main.rb', line 5

def initialize(logger)
  @logger = logger
end

Instance Method Details

#run(paths, env_vars, error_handler = nil, &block) ⇒ Object

Run a set of scripts

Note: non executable files are skipped and a warning is sent to the console



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/script-runner/main.rb', line 18

def run( paths, env_vars, error_handler = nil, &block)

  all_paths = all_files(paths).select{ |p| File.file? p }

  @logger.debug all_paths

  runnable = all_paths.select{ |p| File.executable? p }

  set_env(env_vars) if runnable.length > 0

  non_runnable = all_paths - runnable

  non_runnable.each{ |nr|
    @logger.warn "#{nr} is not runnable - skipping"
  }

  runnable.each{ |p|
    @logger.info "run => #{p}"
    exec(p, error_handler, &block)
  }
end