Class: Chef::Sugar::Filters::AtCompileTime

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/sugar/filters.rb

Overview

Evaluate resources at compile time instead of converge time.

Instance Method Summary collapse

Constructor Details

#initialize(recipe) ⇒ AtCompileTime

Returns a new instance of AtCompileTime.


8
9
10
# File 'lib/chef/sugar/filters.rb', line 8

def initialize(recipe)
  @recipe = recipe
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chef/sugar/filters.rb', line 16

def method_missing(m, *args, &block)
  resource = @recipe.send(m, *args, &block)

  if resource.is_a?(Chef::Resource)
    actions = Array(resource.action)
    resource.action(:nothing)

    actions.each do |action|
      resource.run_action(action)
    end
  end

  resource
end

Instance Method Details

#evaluate(&block) ⇒ Object


12
13
14
# File 'lib/chef/sugar/filters.rb', line 12

def evaluate(&block)
  instance_eval(&block)
end