Module: Chef::DSL::Recipe

Defined in:
lib/toaster/chef/failsafe_resource_parser.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/toaster/chef/failsafe_resource_parser.rb', line 76

def method_missing(method_symbol, *args, &block)
  begin

    # code copied from chef/dsl/recipe.rb
    
    # If we have a definition that matches, we want to use that instead.  This should
    # let you do some really crazy over-riding of "native" types, if you really want
    # to.
    if has_resource_definition?(method_symbol)
      evaluate_resource_definition(method_symbol, *args, &block)
    elsif have_resource_class_for?(method_symbol)
      # Otherwise, we're rocking the regular resource call route.
      declare_resource(method_symbol, args[0] && !args[0].empty? ? args[0] : "__some_name__", caller[0], &block)
    else
      begin
        super
      rescue NoMethodError
        raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}"
      rescue NameError
        raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}"
      end
    end

    if caller.size > 250
      puts $old_mm.object_id
      puts "--"
      puts ::Chef::DSL::Recipe.instance_method(:method_missing).object_id
      puts "-------"
      return nil
    end
  rescue Object => ex
      proxy = @attributes_proxy ? @attributes_proxy : $new_node
      proxy.send(method_symbol, *args, &block)
  end
end

Instance Method Details

#attributes_proxy=(attrs) ⇒ Object



59
60
61
# File 'lib/toaster/chef/failsafe_resource_parser.rb', line 59

def attributes_proxy=(attrs)
  @attributes_proxy = attrs
end

#instance_eval(string, filename = nil, lineno = nil, &block) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/toaster/chef/failsafe_resource_parser.rb', line 68

def instance_eval(string, filename=nil, lineno=nil, &block)
  begin
    super
  rescue Object => ex
    puts "WARN: cannot run instance_eval on recipe: #{ex} - #{ex.backtrace.join("\n")}"
    puts "WARN: eval string was: #{string}"
  end
end

#respond_to?(sym, included_privates = false) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/toaster/chef/failsafe_resource_parser.rb', line 62

def respond_to?(sym, included_privates = false)
  true
end

#respond_to_missing?(sym, included_privates = false) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/toaster/chef/failsafe_resource_parser.rb', line 65

def respond_to_missing?(sym, included_privates = false)
  true
end