Module: Mattock::CascadingDefinition

Includes:
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

Override those methods to adjust how a TaskLib processes its options

The only method not defined here is Mattock::Configurable#setup_defaults

For an overview see TaskLib

Constant Summary

Constants included from Configurable

Mattock::Configurable::RequiredField

Instance Method Summary collapse

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 Mattock::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

Instance Method Details

#confirm_configurationObject

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.



79
80
81
82
# File 'lib/mattock/cascading-definition.rb', line 79

def confirm_configuration
  confirm_step(:confirm_configuration)
  check_required
end

#confirm_step(step) ⇒ Object



52
53
54
# File 'lib/mattock/cascading-definition.rb', line 52

def confirm_step(step)
  @steps.delete(step)
end

#confirm_steps(*steps) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/mattock/cascading-definition.rb', line 42

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

Parameters:

  • tasklibs (TaskLib)

    Other libs upon which this one depends to set its defaults



59
60
61
# File 'lib/mattock/cascading-definition.rb', line 59

def default_configuration(*tasklibs)
  confirm_step(:default_configuration)
end

#defineObject

Any useful TaskLib will override this to define tasks, essentially like a templated Rakefile snippet.



87
88
# File 'lib/mattock/cascading-definition.rb', line 87

def define
end

#resolve_configurationObject

Called after the configuration block has been called, so secondary configurations can be set up. For instance, consider:

self.command ||= bin_dir + command_name

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.



71
72
73
# File 'lib/mattock/cascading-definition.rb', line 71

def resolve_configuration
  confirm_step(:resolve_configuration)
end

#setup_cascade(*other_definitions) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mattock/cascading-definition.rb', line 26

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