summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2010-06-18 12:32:27 -0700
committerDaniel DeLeo <dan@opscode.com>2010-06-18 12:32:27 -0700
commitb6c6e631cc8814d47534d9f78e63807b34d0194f (patch)
treedb51b3b173bc472787ffd36b213ec13c1ac75fbe
parent603a5dd5700692243f2bb6b28a1dfa2d196070a3 (diff)
downloadchef-b6c6e631cc8814d47534d9f78e63807b34d0194f.tar.gz
[CHEF-1358] set resources' source_line in DSL core so it's correct
-rw-r--r--chef/lib/chef/mixin/recipe_definition_dsl_core.rb1
-rw-r--r--chef/lib/chef/resource.rb24
2 files changed, 19 insertions, 6 deletions
diff --git a/chef/lib/chef/mixin/recipe_definition_dsl_core.rb b/chef/lib/chef/mixin/recipe_definition_dsl_core.rb
index aa31b09183..d21914a264 100644
--- a/chef/lib/chef/mixin/recipe_definition_dsl_core.rb
+++ b/chef/lib/chef/mixin/recipe_definition_dsl_core.rb
@@ -65,6 +65,7 @@ class Chef
# Chef::Provider.
# resource.recipe_name = @recipe_name
resource.params = @params
+ resource.source_line = caller[0]
# Determine whether this resource is being created in the context of an enclosing Provider
resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil
resource.instance_eval(&block) if block
diff --git a/chef/lib/chef/resource.rb b/chef/lib/chef/resource.rb
index 0d726ba0ce..fe1c734d49 100644
--- a/chef/lib/chef/resource.rb
+++ b/chef/lib/chef/resource.rb
@@ -26,6 +26,7 @@ require 'chef/node'
class Chef
class Resource
+ HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name]
include Chef::Mixin::CheckHelper
include Chef::Mixin::ParamsValidate
@@ -33,7 +34,8 @@ class Chef
include Chef::Mixin::ConvertToClassName
attr_accessor :params, :provider, :updated, :allowed_actions, :run_context, :cookbook_name, :recipe_name, :enclosing_provider
- attr_reader :resource_name, :source_line, :not_if_args, :only_if_args
+ attr_accessor :source_line
+ attr_reader :resource_name, :not_if_args, :only_if_args
# Each notify entry is a resource/action pair, modeled as an
# OpenStruct with a .resource and .action member
@@ -57,11 +59,7 @@ class Chef
@only_if_args = {}
@notifies_immediate = Array.new
@notifies_delayed = Array.new
- sline = caller(4).shift
- if sline
- @source_line = sline.gsub!(/^(.+):(.+):.+$/, '\1 line \2')
- @source_line = ::File.expand_path(@source_line) if @source_line
- end
+ @source_line = nil
end
def node
@@ -206,6 +204,20 @@ class Chef
def to_s
"#{@resource_name}[#{@name}]"
end
+
+ def to_text
+ skip =
+ ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
+ text = "# Declared in #{@source_line}\n"
+ text << convert_to_snake_case(self.class.name, 'Chef::Resource') + "(#{name}) do\n"
+ ivars.each do |ivar|
+ #next if skip.include?(ivar)
+ if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
+ text << " #{ivar.to_s.sub(/^@/,'')}(#{value.inspect})\n"
+ end
+ end
+ text << "end\n"
+ end
# Serialize this object as a hash
def to_json(*a)