diff options
Diffstat (limited to 'lib/ohai/dsl/plugin.rb')
-rw-r--r-- | lib/ohai/dsl/plugin.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb index adcb6f82..b9fe9910 100644 --- a/lib/ohai/dsl/plugin.rb +++ b/lib/ohai/dsl/plugin.rb @@ -152,8 +152,19 @@ module Ohai end end - def set_attribute(name, *values) - @data[name] = Array18(*values) + def set_attribute(name, *attrs, value) + # Initialize the path in the @data Mash with new Mashes, if needed. + # Will raise a TypeError if we hit a subattribute that is not a + # Hash, Mash, or Array. + keys = [name] + attrs + attribute = keys[0..-2].inject(@data) do |attrs, key| + attrs[key] ||= Mash.new + attrs[key] + end + + # Set the subattribute to the value. + attr_name = attrs.empty? ? name : attrs[-1] + attribute[attr_name] = value @data[name] end @@ -196,12 +207,6 @@ module Ohai # NoMethodError occurs when trying to access a key on nil nil end - - def Array18(*args) - return nil if args.empty? - return args.first if args.length == 1 - return *args - end end end end |