Class: Saper::DSL::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/saper/core/dsl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name = nil, ns = nil, &block) ⇒ Recipe

TODO:

Returns a new instance of Recipe


55
56
57
# File 'lib/saper/core/dsl.rb', line 55

def initialize(id, name = nil, ns = nil, &block)
  @recipe, @ns, @block = Saper::Recipe.new(id, :name => name), ns, block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object


65
66
67
# File 'lib/saper/core/dsl.rb', line 65

def method_missing(name, *args, &block)
  @recipe << Saper::Action.new(name, *args, :namespace => @ns, &block)
end

Instance Attribute Details

#recipeObject (readonly)

Returns the value of attribute recipe


52
53
54
# File 'lib/saper/core/dsl.rb', line 52

def recipe
  @recipe
end

Class Method Details

.parse(id = nil, name = nil, ns = nil, &block) ⇒ Saper::Recipe, Saper::DSL::Recipe

Parses block and returns a Recipe instance or a proxy object. If namespace is specified within options, full initialization of Recipe is delayed and a proxy object is returned (which supports `#to_recipe`).

Parameters:

  • id (Symbol) (defaults to: nil)

    recipe ID

Returns:


43
44
45
46
47
48
49
50
# File 'lib/saper/core/dsl.rb', line 43

def self.parse(id = nil, name = nil, ns = nil, &block)
  instance = self.new(id, name, ns, &block)
  if ns.is_a?(Namespace)
    instance
  else
    instance.to_recipe
  end
end

Instance Method Details

#to_recipe(*args) ⇒ Object


60
61
62
# File 'lib/saper/core/dsl.rb', line 60

def to_recipe(*args)
  self.instance_eval(&@block) if recipe.empty?; recipe
end