Class: IMW::Runner
- Inherits:
-
Object
- Object
- IMW::Runner
- Defined in:
- lib/imw/runner.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :requires => [], :selectors => [], :dry_run => false }
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #datasets ⇒ Object
- #handles ⇒ Object
-
#initialize(*args) ⇒ Runner
constructor
A new instance of Runner.
- #list! ⇒ Object
- #parser ⇒ Object
- #require_files ⇒ Object
- #run! ⇒ Object
- #run_task! ⇒ Object
- #task ⇒ Object
Constructor Details
#initialize(*args) ⇒ Runner
Returns a new instance of Runner.
18 19 20 21 22 |
# File 'lib/imw/runner.rb', line 18 def initialize *args @args = args @options = DEFAULT_OPTIONS.dup parser.parse!(args) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
16 17 18 |
# File 'lib/imw/runner.rb', line 16 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/imw/runner.rb', line 16 def @options end |
Instance Method Details
#datasets ⇒ Object
88 89 90 |
# File 'lib/imw/runner.rb', line 88 def datasets handles.map { |handle| IMW.repository[handle] } end |
#handles ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/imw/runner.rb', line 78 def handles if [:selectors].blank? IMW.repository.keys.sort else IMW.repository.handles.map do |handle| handle if [:selectors].all? { |selector| handle.to_s =~ Regexp.new(selector) } end.compact.sort end end |
#list! ⇒ Object
92 93 94 95 |
# File 'lib/imw/runner.rb', line 92 def list! puts handles exit end |
#parser ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/imw/runner.rb', line 24 def parser OptionParser.new do |opts| opts. = "usage: imw [OPTIONS] TASK" opts.separator <<EOF Run TASK for all datasets in the repository. IMW will read any *.imw files in the current directory by default. Options include EOF opts.on('-v', '--verbose', "Print verbose output") do IMW.verbose = true # class level, see IMW::Runner.verbose? end opts.on('-d', '--skip-dependencies', "Execute given tasks without invoking dependencies first") do [:execute] = true end opts.on('-l', '--list', "List datasets in repository") do [:list] = true end opts.on('-s', '--selector SELECTOR', "Filter datasets by regexp SELECTOR. Can be given more than once.") do |selector| [:selectors] << selector end opts.on('-r', '--require PATH', "Require PATH. Can be given more than once.") do |path| [:requires] << path end end end |
#require_files ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/imw/runner.rb', line 59 def require_files Dir['*.imw'].each { |path| load File.(path) } Dir['*.rb'].each { |path| require path.gsub(/\.rb$/,'') } [:requires].each do |path| IMW.open(path) do |requireable| if requireable.directory? requireable["**/*.rb"].each { |file| require file } requireable["**/*.imw"].each { |file| load file } else require requireable.path end end end end |
#run! ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/imw/runner.rb', line 104 def run! require_files case when [:list] list! when task.blank? puts parser exit 1 else run_task! end end |
#run_task! ⇒ Object
97 98 99 100 101 102 |
# File 'lib/imw/runner.rb', line 97 def run_task! datasets.each do |dataset| dataset[task].send([:execute] ? :execute : :invoke) end exit end |
#task ⇒ Object
74 75 76 |
# File 'lib/imw/runner.rb', line 74 def task args.first end |