Class: Rake::Task
- Inherits:
-
Object
- Object
- Rake::Task
- Defined in:
- lib/rote/rotetasks.rb,
lib/rote/cache.rb
Overview
Rote adds the following methods to the Rake::Task class.
Class Method Summary collapse
-
.memoize(args, &block) ⇒ Object
Memoize the result of the block with respect to the file-based dependencies.
Instance Method Summary collapse
-
#execute(args) ⇒ Object
Execute the task, setting the executed flag.
-
#executed? ⇒ Boolean
Determine whether this task has been executed in this cycle.
- #pre_rote_execute ⇒ Object
-
#reset ⇒ Object
Reset the executed and invoked flags on this task.
Class Method Details
.memoize(args, &block) ⇒ Object
Memoize the result of the block with respect to the file-based dependencies. Specify a description and dependencies like a Task:
Rake::Task.memoize :task_name => [fn1,fn2] { ... }
If the cached result is up-to-date with respect to the dependencies then the block will not be executed. Instead, the result will be unmarshalled from disk.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rote/cache.rb', line 97 def self.memoize(args, &block) task_name, deps = resolve_args(args) fn = File.join(Rake.cache_dir, MD5.new(deps.inspect).to_s + "." + task_name) Rake.register_dependency(deps) result = nil # This file task isn't ever used other than manually below with t.invoke t = file fn => deps do result = block.call mkdir_p Rake.cache_dir unless File.exists?(Rake.cache_dir) File.open(fn,"w") { |fp| Marshal.dump(result,fp) } end if t.needed? then t.invoke result else Marshal.load(File.read(fn)) end end |
Instance Method Details
#execute(args) ⇒ Object
Execute the task, setting the executed flag. Used by the monitor
task.
350 351 352 353 |
# File 'lib/rote/rotetasks.rb', line 350 def execute(args) @executed = true pre_rote_execute end |
#executed? ⇒ Boolean
Determine whether this task has been executed in this cycle. Used by the monitor
task.
343 344 345 |
# File 'lib/rote/rotetasks.rb', line 343 def executed? @executed end |
#pre_rote_execute ⇒ Object
347 |
# File 'lib/rote/rotetasks.rb', line 347 alias :pre_rote_execute :execute |
#reset ⇒ Object
Reset the executed and invoked flags on this task. Used by the monitor
task.
336 337 338 339 |
# File 'lib/rote/rotetasks.rb', line 336 def reset @already_invoked = false @executed = false end |