Sha256: c22fcc020bfc48a384d8eebc082cf67e441f73fccd0a5a130373f8f8c8e69de8

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module Stove
  class Filter
    include Mixin::Insideable
    include Mixin::Loggable

    #
    # The class that created this filter.
    #
    # @return [~Plugin::Base]
    #
    attr_reader :klass

    #
    # The message given by the filter.
    #
    # @return [String]
    #
    attr_reader :message

    #
    # The block captured by the filter.
    #
    # @return [Proc]
    #
    attr_reader :block

    #
    # Create a new filter object.
    #
    # @param [~Plugin::Base] klass
    #   the class that created this filter
    # @param [String] message
    #   the message given by the filter
    # @param [Proc] block
    #   the block captured by this filter
    #
    def initialize(klass, message, &block)
      @klass   = klass
      @message = message
      @block   = block
    end

    #
    # Execute this filter in the context of the creating class, inside the
    # given cookbook's path.
    #
    # @param [Cookbook]
    #   the cookbook to run this filter against
    #
    def run(cookbook, options = {})
      log.info(message)
      instance = klass.new(cookbook, options)

      inside(cookbook) do
        instance.instance_eval(&block)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stove-2.0.0.beta.2 lib/stove/filter.rb
stove-2.0.0.beta.1 lib/stove/filter.rb