Sha256: e7be7e6556f2416707f7ec67d345137d968833c2704496c790d162a94b022a48

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module Eaco
  module DSL

    ##
    # Base DSL class. Provides handy access to the +target+ class being
    # manipulated, DSL-specific options, and a {#target_eval} helper to do
    # +instance_eval+ on the +target+.
    #
    # Nothing too fancy.
    #
    class Base

      ##
      # Executes a DSL block in the context of a DSL manipulator.
      #
      # @see DSL::ACL
      # @see DSL::Actor
      # @see DSL::Resource
      #
      # @return [Base]
      #
      def self.eval(klass, options = {}, &block)
        new(klass, options).tap do |dsl|
          dsl.instance_eval(&block) if block
        end
      end

      # The target class of the manipulation
      attr_reader :target

      # DSL-specific options
      attr_reader :options

      ##
      # @param target [Class]
      # @param options [Hash]
      #
      def initialize(target, options)
        @target, @options = target, options
      end

      protected
        ##
        # Evaluates the given block in the context of the target class
        #
        def target_eval(&block)
          target.instance_eval(&block)
        end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eaco-0.6.1 lib/eaco/dsl/base.rb
eaco-0.6.0 lib/eaco/dsl/base.rb
eaco-0.5.0 lib/eaco/dsl/base.rb