Sha256: 6f9d901f13a68c3672d20b189343ef9960a416d2d5ebe5952b23817305798fc1

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Ratch

  # = PLugin
  #
  # A Plugin is essentially a delegated Service class..
  #
  # The plugin acts a base class for ecapsulating batch routines.
  # This helps to keep the main batch context free of the clutter
  # of private supporting methods.
  #
  # Plugins are tightly coupled to the batch context,
  # which allows them to call on the context easily.
  # However this means plugins cannot be used independent
  # of a batch context, and changes in the batch context
  # can cause effects in plujgin behvior that can be harder
  # to track down and fix if a bug arises.
  #
  # Unless the tight coupling of a plugin is required, use the
  # loose coupling of a Service class instead.

  class Plugin

    # The batch context.
    attr :context

    alias_method :project, :context

    private

    #
    def initialize(context, options=nil)
      @context = context

      raise TypeError, "context must be a subclass of Ratch::DSL" unless context.is_a?(Ratch::DSL)

      initialize_defaults

      options ||= {}
      options.each do |k, v|
        send("#{k}=", v) if respond_to?("#{k}=")
      end
    end

    def initialize_defaults
    end

    # TODO: This should be optional? How?
    def method_missing(s, *a, &b)
      @context.send(s, *a, &b)
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ratch-1.0.0 lib/ratch/plugin.rb