Module: Capsaicin::Namespace
- Defined in:
- lib/capsaicin/namespace.rb
Instance Method Summary collapse
-
#noop_tasks(name, list) ⇒ Object
Override tasks in a namespace to a NOOP.
-
#task_settings(task, vars) ⇒ Object
Redefine settings for the duration of an existing task.
-
#undef_tasks(name, list) ⇒ Object
Undefine tasks in a namespace.
Instance Method Details
#noop_tasks(name, list) ⇒ Object
Override tasks in a namespace to a NOOP.
39 40 41 42 43 44 45 46 |
# File 'lib/capsaicin/namespace.rb', line 39 def noop_tasks(name, list) namespace name do = class << self; self; end list.each do |k| tasks[k.to_sym].instance_variable_set(:@body, lambda {}) end end end |
#task_settings(task, vars) ⇒ Object
Redefine settings for the duration of an existing task.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/capsaicin/namespace.rb', line 6 def task_settings(task, vars) orig_vars = vars.keys.select { |k| exists? k }.inject({}) { |h,k| h[k] = variables[k]; h } orig_body = tasks[task].body tasks[task].instance_variable_set(:@body, lambda do vars.each { |k,v| Proc===v ? set(k, &v) : set(k, v) } begin orig_body.call ensure vars.keys.each do |k| if ! orig_vars.include? k variables.delete k else v = orig_vars[k] Proc===v ? set(k, &v) : set(k, v) end end end end) end |
#undef_tasks(name, list) ⇒ Object
Undefine tasks in a namespace.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/capsaicin/namespace.rb', line 27 def undef_tasks(name, list) namespace name do = class << self; self; end list.each do |k| k = k.to_sym .send(:undef_method, k) tasks.delete k end end end |