Class: Reap::Runner
- Inherits:
-
Object
- Object
- Reap::Runner
- Defined in:
- lib/reap/runner.rb
Overview
Main Runner class
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #acknowledge ⇒ Object
- #call(tsk, *args) ⇒ Object
-
#initialize(config_file = nil) ⇒ Runner
constructor
A new instance of Runner.
- #run(tsk, *args) ⇒ Object
- #task?(tsk) ⇒ Boolean
Constructor Details
#initialize(config_file = nil) ⇒ Runner
Returns a new instance of Runner.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/reap/runner.rb', line 29 def initialize( config_file=nil ) config_file ||= 'Reapfile' if File.file?( config_file ) # load config file config = YAML.load( File.open( config_file ) ) config.traverse!{ |k,v| [k.downcase, v] } @config = config # main parameters @title = @config['title'] @name = @config['name'] @version = @config['version'] @summary = @config['summary'] @description = @config['description'] raise "TITLE is a required configuration field" unless @title raise "NAME is a required configuration field" unless @name raise "VERSION is a required configuration field" unless @version else @config = {} end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/reap/runner.rb', line 27 def config @config end |
Instance Method Details
#acknowledge ⇒ Object
89 90 91 |
# File 'lib/reap/runner.rb', line 89 def acknowledge y @config end |
#call(tsk, *args) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/reap/runner.rb', line 63 def call( tsk, *args ) tsk = tsk.to_s.downcase.to_sym case tsk when :acknowledge, :show acknowledge else run( tsk, *args ) end end |
#run(tsk, *args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/reap/runner.rb', line 73 def run( tsk, *args ) taskClass = Task.registry.find { |t| t.task.to_sym == tsk } raise "Task undefined." unless taskClass # should not happen task = taskClass.new( @config ) section = taskClass.task.to_s.downcase if @config[section].is_a?( Array ) @config[section].each do |s| task.set( s ) task.run end else task.set( @config[section] ) task.run end end |