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 ⇒ Object
Execute the task, setting the executed flag.
-
#executed? ⇒ Boolean
Determine whether this task has been executed in this cycle.
-
#invoke ⇒ Object
Invoke the task, loading cached dependencies if not already loaded, and handling the task stack.
- #pre_autodep_invoke ⇒ Object
- #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.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rote/cache.rb', line 92 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 ⇒ Object
Execute the task, setting the executed flag. Used by the monitor task.
344 345 346 347 |
# File 'lib/rote/rotetasks.rb', line 344 def execute @executed = true pre_rote_execute end |
#executed? ⇒ Boolean
Determine whether this task has been executed in this cycle. Used by the monitor task.
337 338 339 |
# File 'lib/rote/rotetasks.rb', line 337 def executed? @executed end |
#invoke ⇒ Object
Invoke the task, loading cached dependencies if not already loaded, and handling the task stack. The argument controls whether or not cached dependencies are loaded and should not be set false except in testing.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rote/cache.rb', line 69 def invoke # Invoke patched to record task stack and # load cached dependencies on first go. Rake.load_cached_dependencies if Rake.cache_enabled? begin Rake.task_stack << self Rake.cached_dependencies[name] = [] if Rake.cached_dependencies[name] pre_autodep_invoke ensure Rake.task_stack.pop end end |
#pre_autodep_invoke ⇒ Object
63 |
# File 'lib/rote/cache.rb', line 63 alias :pre_autodep_invoke :invoke |
#pre_rote_execute ⇒ Object
341 |
# File 'lib/rote/rotetasks.rb', line 341 alias :pre_rote_execute :execute |
#reset ⇒ Object
Reset the executed and invoked flags on this task. Used by the monitor task.
330 331 332 333 |
# File 'lib/rote/rotetasks.rb', line 330 def reset @already_invoked = false @executed = false end |