Sha256: 6e1be457174b17a2b3c26c9055675084e26851b9e9d031b1c3c26f5b26bb55e3

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

require 'mattock/configurable'

module Mattock
  #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 {Configurable#setup_defaults}
  #
  #For an overview see {TaskLib}
  module CascadingDefinition
    include Configurable

    def initialize(*tasklibs)
      setup_defaults
      default_configuration(*tasklibs)

      yield self if block_given?

      resolve_configuration
      confirm_configuration

      define
    end

    #@param [TaskLib] tasklibs Other libs upon which this one depends to set
    #  its defaults
    #Sets default values for library settings
    def default_configuration(*tasklibs)
    end

    #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.
    def resolve_configuration
    end

    #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.
    def confirm_configuration
      check_required
    end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mattock-0.2.13 lib/mattock/cascading-definition.rb
mattock-0.2.12 lib/mattock/cascading-definition.rb
mattock-0.2.11 lib/mattock/cascading-definition.rb
mattock-0.2.10 lib/mattock/cascading-definition.rb
mattock-0.2.9 lib/mattock/cascading-definition.rb
mattock-0.2.8 lib/mattock/cascading-definition.rb
mattock-0.2.7 lib/mattock/cascading-definition.rb
mattock-0.2.6 lib/mattock/cascading-definition.rb