Class: Cany::Recipe::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/cany/recipe.rb

Overview

This superclass helps recipes to create easily an own mini DSL to let the user configure the recipe with it.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipe) ⇒ DSL

Returns a new instance of DSL.



265
266
267
# File 'lib/cany/recipe.rb', line 265

def initialize(recipe)
  @recipe = recipe
end

Class Method Details

.delegate(*methods) ⇒ Object

This is a simple delegate helper. It can be used to pass option directly to recipe instance.

Parameters:

  • param1 (Symbol)

    Multiple symbol names



276
277
278
279
280
281
282
283
284
# File 'lib/cany/recipe.rb', line 276

def self.delegate(*methods)
  methods.each do |method|
    module_eval("    def \#{method}(*args, &block)\n      @recipe.send :'\#{method}=', *args, &block\n    end\n    EOS\n  end\nend\n", __FILE__, __LINE__)

Instance Method Details

#after(hook_name, &block) ⇒ Object



290
291
292
# File 'lib/cany/recipe.rb', line 290

def after(hook_name, &block)
  @recipe.hook(hook_name)[:after] << block
end

#around(hook_name, &block) ⇒ Object



294
295
296
# File 'lib/cany/recipe.rb', line 294

def around(hook_name, &block)
  @recipe.hook(hook_name)[:around] << block
end

#before(hook_name, &block) ⇒ Object



286
287
288
# File 'lib/cany/recipe.rb', line 286

def before(hook_name, &block)
  @recipe.hook(hook_name)[:before] << block
end

#exec(&block) ⇒ Object

Evaluate a given block inside the dsl.



270
271
272
# File 'lib/cany/recipe.rb', line 270

def exec(&block)
  instance_eval(&block)
end