Class: Eaco::DSL::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/eaco/dsl/base.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, options) ⇒ Base

Sets up the DSL instance target class and the options.


40
41
42
# File 'lib/eaco/dsl/base.rb', line 40

def initialize(target, options)
  @target, @options = target, options
end

Instance Attribute Details

#optionsObject (readonly)

DSL-specific options


32
33
34
# File 'lib/eaco/dsl/base.rb', line 32

def options
  @options
end

#targetObject (readonly)

The target class of the manipulation


29
30
31
# File 'lib/eaco/dsl/base.rb', line 29

def target
  @target
end

Class Method Details

.eval(klass, options = {}, &block) ⇒ Base

Executes a DSL block in the context of a DSL manipulator.

See Also:


22
23
24
25
26
# File 'lib/eaco/dsl/base.rb', line 22

def self.eval(klass, options = {}, &block)
  new(klass, options).tap do |dsl|
    dsl.instance_eval(&block) if block
  end
end

Instance Method Details

#target_eval(&block) (protected)

This method returns an undefined value.

Evaluates the given block in the context of the target class


51
52
53
# File 'lib/eaco/dsl/base.rb', line 51

def target_eval(&block)
  target.instance_eval(&block)
end