Class: Mattock::TaskLib
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Mattock::TaskLib
- Defined in:
- lib/mattock/tasklib.rb
Overview
Rake::Tasklib provides a common, well known way to generalize tasks and use them in multiple projects.
Typically, the #initialize method for CoolTask yields itself into the block (so, ‘t’ in the example) and then runs #define which does the heavy lifting to actually create tasks and set them up with dependencies and whatnot.
Rake::Tasklib doesn’t really provide much in the way of help or guidance about how to do this, though, and everyone winds up having to do a lot of the same work.
Mattock::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.
The configuration handling is provided by CascadingDefinition, and configuration options are built using Configurable
Constant Summary
Constants included from Configurable
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 Configurable::DirectoryStructure
Methods included from CascadingDefinition
#confirm_configuration, #confirm_step, #confirm_steps, #default_configuration, #resolve_configuration, #setup_cascade
Methods included from Configurable
#check_required, #copy_settings, #copy_settings_to, #fail_unless_set, #field_unset?, #initialize_copy, #proxy_settings, #proxy_settings_to, #proxy_value, #setup_defaults, #to_hash, #unset?, #unset_defaults_guard, unset_defaults_guard
Methods included from Configurable::ClassMethods
#default_value_for, #default_values, #field_metadata, #field_names, #included, #inspect_instance, #missing_required_fields_on, #nested, #nil_fields, #required_fields, #runtime_required_fields, #runtime_setting, #set_defaults_on, #setting, #settings, #to_hash
Constructor Details
#initialize(*toolkits, &block) ⇒ TaskLib
Returns a new instance of TaskLib.
54 55 56 57 |
# File 'lib/mattock/tasklib.rb', line 54 def initialize(*toolkits, &block) @tasks = [] setup_cascade(*toolkits, &block) end |
Instance Attribute Details
#namespace_name=(value) ⇒ Object (writeonly)
Sets the attribute namespace_name
44 45 46 |
# File 'lib/mattock/tasklib.rb', line 44 def namespace_name=(value) @namespace_name = value end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
52 53 54 |
# File 'lib/mattock/tasklib.rb', line 52 def tasks @tasks end |
Class Method Details
.default_namespace(name) ⇒ Object
The namespace this lib’s tasks will created within. Changeable at instantiation
48 49 50 |
# File 'lib/mattock/tasklib.rb', line 48 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
136 137 138 |
# File 'lib/mattock/tasklib.rb', line 136 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
71 72 73 74 |
# File 'lib/mattock/tasklib.rb', line 71 def bracket_task(before, name, after, &block) task self[name] => before, &block task after => self[name] end |
#debug_settings_task ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/mattock/tasklib.rb', line 123 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
112 113 114 |
# File 'lib/mattock/tasklib.rb', line 112 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
119 120 121 |
# File 'lib/mattock/tasklib.rb', line 119 def define debug_settings_task end |
#in_namespace(args) ⇒ Object #in_namespace(&block) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mattock/tasklib.rb', line 90 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
108 109 110 |
# File 'lib/mattock/tasklib.rb', line 108 def root_task @namespace_name || :default end |
#task(*args) ⇒ Object
Records tasks as they are created
60 61 62 63 64 |
# File 'lib/mattock/tasklib.rb', line 60 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
78 79 80 81 82 83 |
# File 'lib/mattock/tasklib.rb', line 78 def task_spine(*list) task list.first list.each_cons(2) do |first, second| task second => first end end |