Class: Mattock::TaskLib
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Mattock::TaskLib
- Includes:
- Calibrate::Configurable::DirectoryStructure, CascadingDefinition
- Defined in:
- lib/mattock/tasklib.rb
Overview
TaskLib provides a base class to build tasklibs on so that you can get to what you care about, and get option validation as well.
The convention that’s added in Mattock is that Tasklibs are passed to each other as arguments, so that behavior can be composed out of modular components.
To define a new task lib: subclass TaskLib, add some ::setting calls, and override #define to add some tasks.
To use your tasklib, instantiate with a block, optionally passing other task libs to copy configuration from.
The configuration handling is provided by CascadingDefinition, and configuration options are built using Configurable
Direct Known Subclasses
Instance Attribute Summary collapse
-
#namespace_name ⇒ Object
writeonly
Sets the attribute namespace_name.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
-
.default_namespace(name) ⇒ Object
The namespace this lib’s tasks will created within.
Instance Method Summary collapse
-
#[](taskname) ⇒ Object
Wraps a single task in lib’s namespace.
-
#bracket_task(before, name, after, &block) ⇒ Object
Shorthand for task name => before task after => name Which ensures that if “after” is ever invoked, the execution will be before, name, then after.
- #debug_settings_task ⇒ Object
- #default_namespace ⇒ Object
-
#define ⇒ Object
Default define defines some tasks related to debugging Rakefiles - subclasses can get these just by remembering to call ‘super’ in their define.
- #in_namespace(*tasknames) ⇒ Object
-
#initialize(*toolkits, &block) ⇒ TaskLib
constructor
A new instance of TaskLib.
- #root_task ⇒ Object
-
#task(*args) ⇒ Object
Records tasks as they are created.
-
#task_spine(*list) ⇒ Object
Builds a series of tasks in a sequence - the idea is that dependant tasklibs can depend on stages of a larger process.
Methods included from CascadingDefinition
#confirm_configuration, #confirm_step, #confirm_steps, #default_configuration, #resolve_configuration, #setup_cascade
Constructor Details
#initialize(*toolkits, &block) ⇒ TaskLib
Returns a new instance of TaskLib.
65 66 67 68 |
# File 'lib/mattock/tasklib.rb', line 65 def initialize(*toolkits, &block) @tasks = [] setup_cascade(*toolkits, &block) end |
Instance Attribute Details
#namespace_name=(value) ⇒ Object (writeonly)
Sets the attribute namespace_name
55 56 57 |
# File 'lib/mattock/tasklib.rb', line 55 def namespace_name=(value) @namespace_name = value end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
63 64 65 |
# File 'lib/mattock/tasklib.rb', line 63 def tasks @tasks end |
Class Method Details
.default_namespace(name) ⇒ Object
The namespace this lib’s tasks will created within. Changeable at instantiation
59 60 61 |
# File 'lib/mattock/tasklib.rb', line 59 def self.default_namespace(name) setting(:namespace_name, name).isnt(:copiable) end |
Instance Method Details
#[](taskname) ⇒ Object
Wraps a single task in lib’s namespace
147 148 149 |
# File 'lib/mattock/tasklib.rb', line 147 def [](taskname) in_namespace(taskname).first end |
#bracket_task(before, name, after, &block) ⇒ Object
Shorthand for
task name => before
task after => name
Which ensures that if “after” is ever invoked, the execution will be before, name, then after
82 83 84 85 |
# File 'lib/mattock/tasklib.rb', line 82 def bracket_task(before, name, after, &block) task self[name] => before, &block task after => self[name] end |
#debug_settings_task ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/mattock/tasklib.rb', line 134 def debug_settings_task in_namespace do task :debug_settings do require 'pp' puts self.class.name pp self.to_hash end end task :debug_settings => self[:debug_settings] end |
#default_namespace ⇒ Object
123 124 125 |
# File 'lib/mattock/tasklib.rb', line 123 def default_namespace nil end |
#define ⇒ Object
Default define defines some tasks related to debugging Rakefiles - subclasses can get these just by remembering to call ‘super’ in their define
130 131 132 |
# File 'lib/mattock/tasklib.rb', line 130 def define debug_settings_task end |
#in_namespace(args) ⇒ Object #in_namespace(&block) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mattock/tasklib.rb', line 101 def in_namespace(*tasknames) if tasknames.empty? if block_given? if @namespace_name.nil? yield else namespace @namespace_name do yield end end end else tasknames.map do |taskname| [@namespace_name, taskname].compact.join(":") end end end |
#root_task ⇒ Object
119 120 121 |
# File 'lib/mattock/tasklib.rb', line 119 def root_task @namespace_name || :default end |
#task(*args) ⇒ Object
Records tasks as they are created
71 72 73 74 75 |
# File 'lib/mattock/tasklib.rb', line 71 def task(*args) a_task = super @tasks << a_task return a_task end |
#task_spine(*list) ⇒ Object
Builds a series of tasks in a sequence - the idea is that dependant tasklibs can depend on stages of a larger process
89 90 91 92 93 94 |
# File 'lib/mattock/tasklib.rb', line 89 def task_spine(*list) task list.first list.each_cons(2) do |first, second| task second => first end end |