Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
more readable inspect output
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Valodzka authored and danielsdeleo committed Jul 15, 2010
1 parent ae801e4 commit a770f7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chef/lib/chef/node/attribute.rb
Expand Up @@ -426,6 +426,15 @@ def method_missing(symbol, *args)
end
end

def inspect
determine_value(current_automatic, current_override, current_normal, current_default)
exclude_attrs = ["@override", "@attribute", "@default", "@normal", "@automatic"]

"#<#{self.class} " << instance_variables.map{|iv|
iv + '=' + (exclude_attrs.include?(iv) ? "{...}" : instance_variable_get(iv).inspect)
}.join(', ') << ">"
end

def to_hash
result = determine_value(current_automatic, current_override, current_normal, current_default)
if result.class == Hash
Expand Down
7 changes: 7 additions & 0 deletions chef/spec/unit/node/attribute_spec.rb
Expand Up @@ -975,4 +975,11 @@
@attributes.should_not be_a_kind_of(Chef::Node)
end
end

describe "inspect" do
it "should be readable" do
@attributes.inspect.should =~ /@automatic=\{\.\.\.\}/
@attributes.inspect.should =~ /@normal=\{\.\.\.\}/
end
end
end

0 comments on commit a770f7c

Please sign in to comment.