Module: Mattock::CascadingDefinition
- Includes:
- Calibrate::Configurable
- Included in:
- ConfigurableTask, TaskLib
- Defined in:
- lib/mattock/cascading-definition.rb
Overview
Collects shared configuration management behavior for TaskLibs and Tasks
The chain of events in initialize looks like:
setup_defaults
default_configuration(*tasklibs)
yield self if block_given?
resolve_configuration
confirm_configuration
define
(see #setup_cascade)
Override those methods to adjust how a TaskLib processes its options
The only method not defined here is Configurable#setup_defaults
For an overview see TaskLib
Instance Method Summary collapse
-
#confirm_configuration ⇒ Object
Last step before definition: confirm that all the configuration settings have good values.
- #confirm_step(step) ⇒ Object
- #confirm_steps(*steps) ⇒ Object
-
#default_configuration(*tasklibs) ⇒ Object
Sets default values for library settings.
-
#define ⇒ Object
Any useful TaskLib will override this to define tasks, essentially like a templated Rakefile snippet.
-
#resolve_configuration ⇒ Object
Called after the configuration block has been called, so secondary configurations can be set up.
- #setup_cascade(*other_definitions) ⇒ Object
Instance Method Details
#confirm_configuration ⇒ Object
Last step before definition: confirm that all the configuration settings have good values. The default ensures that required settings have been given values. Very much shortens the debugging cycle when using TaskLibs if this is well written.
81 82 83 84 |
# File 'lib/mattock/cascading-definition.rb', line 81 def confirm_configuration confirm_step(:confirm_configuration) check_required end |
#confirm_step(step) ⇒ Object
54 55 56 |
# File 'lib/mattock/cascading-definition.rb', line 54 def confirm_step(step) @steps.delete(step) end |
#confirm_steps(*steps) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/mattock/cascading-definition.rb', line 44 def confirm_steps(*steps) @steps = steps yield unless @steps.empty? #Otherwise, it's very easy to forget the 'super' statement and leave #essential configuration out. The result is really confusing raise "#{self.class.name} didn't run superclass step#{@steps.length == 1 ? "" : "s"}: #{@steps.inspect} (put a 'super' in appropriate methods)" end end |
#default_configuration(*tasklibs) ⇒ Object
Sets default values for library settings
61 62 63 |
# File 'lib/mattock/cascading-definition.rb', line 61 def default_configuration(*tasklibs) confirm_step(:default_configuration) end |
#define ⇒ Object
Any useful TaskLib will override this to define tasks, essentially like a templated Rakefile snippet.
89 90 |
# File 'lib/mattock/cascading-definition.rb', line 89 def define end |
#resolve_configuration ⇒ Object
Called after the configuration block has been called, so secondary configurations can be set up. For instance, consider:
self.command = bin_dir + command_name if is_unset?(:command)
The full path to the command could be set in the configuration block in the Rakefile, or if bin_dir and command_name are set, we can put those together.
73 74 75 |
# File 'lib/mattock/cascading-definition.rb', line 73 def resolve_configuration confirm_step(:resolve_configuration) end |
#setup_cascade(*other_definitions) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mattock/cascading-definition.rb', line 28 def setup_cascade(*other_definitions) @runtime = false setup_defaults confirm_steps(:default_configuration, :resolve_configuration, :confirm_configuration) do default_configuration(*other_definitions) yield self if block_given? resolve_configuration confirm_configuration end define end |