diff options
author | danielsdeleo <dan@opscode.com> | 2013-12-03 12:19:59 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-12-04 15:46:35 -0800 |
commit | 449843c1e376c2bd271c2b7922330d1e0ffc9845 (patch) | |
tree | 3269e383a68b32d589311ae7edf70578dfbd512a | |
parent | c16c5046c5c62d86be74471e003dd44b4a2cb726 (diff) | |
download | ohai-449843c1e376c2bd271c2b7922330d1e0ffc9845.tar.gz |
Rename variables/methods for ProvidesMap to provides_map
The name "attributes" to refer to the map of attributes<->plugins
providing attributes was confusing because it was inaccurate and often
used near a local variable named "attributes" containing a very
different kind of data (such as an Array of strings referring to
attributes another plugin depended on). Renaming to "provides_map"
clears up the confusion.
-rw-r--r-- | lib/ohai/dsl/plugin.rb | 7 | ||||
-rw-r--r-- | lib/ohai/loader.rb | 7 | ||||
-rw-r--r-- | lib/ohai/runner.rb | 4 | ||||
-rw-r--r-- | lib/ohai/system.rb | 6 | ||||
-rw-r--r-- | spec/ohai/dsl/plugin_spec.rb | 9 | ||||
-rw-r--r-- | spec/unit/loader_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/plugins/fail_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/runner_spec.rb | 24 | ||||
-rw-r--r-- | spec/unit/system_spec.rb | 12 |
9 files changed, 41 insertions, 40 deletions
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb index cbfb85e8..2b15cae3 100644 --- a/lib/ohai/dsl/plugin.rb +++ b/lib/ohai/dsl/plugin.rb @@ -114,9 +114,8 @@ module Ohai @has_run = false end - # TODO: rename - def attributes - @controller.attributes + def provides_map + @controller.provides_map end def run @@ -231,7 +230,7 @@ module Ohai end def provides(*paths) - attributes.set_providers_for(self, paths) + provides_map.set_providers_for(self, paths) end def require_plugin(*args) diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index aea67183..bd698fcc 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -25,7 +25,10 @@ module Ohai def initialize(controller) @controller = controller - @attributes = controller.attributes + end + + def provides_map + @controller.provides_map end # @note: plugin_name is used only by version 6 plugins and is the @@ -68,7 +71,7 @@ module Ohai def collect_provides(plugin) plugin_provides = plugin.class.provides_attrs - @attributes.set_providers_for(plugin, plugin_provides) + provides_map.set_providers_for(plugin, plugin_provides) end end diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb index 205b924b..0ead9718 100644 --- a/lib/ohai/runner.rb +++ b/lib/ohai/runner.rb @@ -25,7 +25,7 @@ module Ohai # safe_run: set to true if this runner will run plugins in # safe-mode. default false. def initialize(controller, safe_run = false) - @attributes = controller.attributes + @provides_map = controller.provides_map @safe_run = safe_run end @@ -59,7 +59,7 @@ module Ohai # returns a list of plugins which provide the given attributes def fetch_plugins(attributes) - @attributes.find_providers_for(attributes) + @provides_map.find_providers_for(attributes) end # given a list of plugins and the first plugin in the cycle, diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index baae9f2e..a5029c29 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -34,13 +34,13 @@ module Ohai class System attr_accessor :data - attr_reader :attributes + attr_reader :provides_map attr_reader :hints attr_reader :v6_dependency_solver def initialize @data = Mash.new - @attributes = ProvidesMap.new + @provides_map = ProvidesMap.new @hints = Hash.new @v6_dependency_solver = Hash.new @@ -95,7 +95,7 @@ module Ohai end # collect and run version 7 plugins - plugins = @attributes.all_plugins + plugins = @provides_map.all_plugins begin plugins.each { |plugin| @runner.run_plugin(plugin, force) } diff --git a/spec/ohai/dsl/plugin_spec.rb b/spec/ohai/dsl/plugin_spec.rb index 0fdb265a..072e293a 100644 --- a/spec/ohai/dsl/plugin_spec.rb +++ b/spec/ohai/dsl/plugin_spec.rb @@ -271,8 +271,7 @@ describe Ohai::DSL::Plugin::VersionVI do plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "") plugin.provides("attribute") - #@ohai.attributes.should have_key(:attribute) - @ohai.attributes.find_providers_for(["attribute"]).should eq([plugin]) + @ohai.provides_map.find_providers_for(["attribute"]).should eq([plugin]) end it "should collect a list of attributes" do @@ -280,7 +279,7 @@ describe Ohai::DSL::Plugin::VersionVI do plugin.provides("attr1", "attr2", "attr3") %w[attr1 attr2 attr3].each do |attr| - @ohai.attributes.find_providers_for([attr]).should eq([plugin]) + @ohai.provides_map.find_providers_for([attr]).should eq([plugin]) end end @@ -288,7 +287,7 @@ describe Ohai::DSL::Plugin::VersionVI do plugin = Ohai::DSL::Plugin::VersionVI.new(@ohai, "") plugin.provides("attr/subattr") - @ohai.attributes.find_providers_for(["attr/subattr"]).should eq([plugin]) + @ohai.provides_map.find_providers_for(["attr/subattr"]).should eq([plugin]) end it "should collect all unique providers for an attribute" do @@ -299,7 +298,7 @@ describe Ohai::DSL::Plugin::VersionVI do plugins << p end - @ohai.attributes.find_providers_for(["attribute"]).should =~ plugins + @ohai.provides_map.find_providers_for(["attribute"]).should =~ plugins end end diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb index c95bb12d..8587d721 100644 --- a/spec/unit/loader_spec.rb +++ b/spec/unit/loader_spec.rb @@ -105,14 +105,14 @@ EOF klass = Ohai.plugin(@name) { provides("attr") } plugin = klass.new(@ohai, @path) @loader.collect_provides(plugin) - @ohai.attributes.find_providers_for(["attr"]).should eq([plugin]) + @ohai.provides_map.find_providers_for(["attr"]).should eq([plugin]) end it "should add provided subattributes to Ohai" do klass = Ohai.plugin(@name) { provides("attr/sub") } plugin = klass.new(@ohai, @plath) @loader.collect_provides(plugin) - @ohai.attributes.find_providers_for([ "attr/sub" ]).should include(plugin) + @ohai.provides_map.find_providers_for([ "attr/sub" ]).should include(plugin) end it "should collect the unique providers for an attribute" do @@ -125,7 +125,7 @@ EOF end plugins.each { |plugin| @loader.collect_provides(plugin) } - @ohai.attributes.find_providers_for(["attr"]).should =~ plugins + @ohai.provides_map.find_providers_for(["attr"]).should =~ plugins end end end diff --git a/spec/unit/plugins/fail_spec.rb b/spec/unit/plugins/fail_spec.rb index 17d8f84d..de77c6f2 100644 --- a/spec/unit/plugins/fail_spec.rb +++ b/spec/unit/plugins/fail_spec.rb @@ -56,7 +56,7 @@ shared_examples "a v7 loading failure" do it "should not have attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb") #@ohai.attributes.should_not have_key("fail") - lambda { @ohai.attributes.find_providers_for(["fail"]) }.should raise_error(Ohai::Exceptions::AttributeNotFound) + lambda { @ohai.provides_map.find_providers_for(["fail"]) }.should raise_error(Ohai::Exceptions::AttributeNotFound) end it "should not have source key" do @@ -104,7 +104,7 @@ shared_examples "a v7 loading success" do it "should have attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb") - @ohai.attributes.should have_key("fail") + @ohai.provides_map.should have_key("fail") end it "should have source key" do @@ -152,7 +152,7 @@ shared_examples "a v7 run failure" do it "should not have new attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run - @ohai.attributes.should_not have_key("other") + @ohai.provides_map.should_not have_key("other") end it "should write to Ohai::Log" do diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index 5d5f03c6..fbcaccfb 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -101,7 +101,7 @@ describe Ohai::Runner, "run_plugin" do end @plugin1, @plugin2 = @plugins - @ohai.attributes.set_providers_for(@plugin1, ["thing"]) + @ohai.provides_map.set_providers_for(@plugin1, ["thing"]) end it "should run the plugins" do @@ -134,8 +134,8 @@ describe Ohai::Runner, "run_plugin" do end @plugin1, @plugin2, @plugin3 = @plugins - @ohai.attributes.set_providers_for(@plugin1, ["thing"]) - @ohai.attributes.set_providers_for(@plugin2, ["thing"]) + @ohai.provides_map.set_providers_for(@plugin1, ["thing"]) + @ohai.provides_map.set_providers_for(@plugin2, ["thing"]) end it "should run the plugins" do @@ -177,8 +177,8 @@ describe Ohai::Runner, "run_plugin" do @plugins << klass.new(@ohai, "/tmp/plugins/number.rb") end @plugin1, @plugin2, @plugin3 = @plugins - @ohai.attributes.set_providers_for(@plugin1, ["one", "two"]) - @ohai.attributes.set_providers_for(@plugin2, ["one", "two"]) + @ohai.provides_map.set_providers_for(@plugin1, ["one", "two"]) + @ohai.provides_map.set_providers_for(@plugin2, ["one", "two"]) end it "should run the plugins" do @@ -251,9 +251,9 @@ describe Ohai::Runner, "run_plugin" do end it "should not detect a cycle when B is the first provider returned" do - @ohai.attributes.set_providers_for(@pluginA, ["A"]) - @ohai.attributes.set_providers_for(@pluginB, ["B"]) - @ohai.attributes.set_providers_for(@pluginC, ["C"]) + @ohai.provides_map.set_providers_for(@pluginA, ["A"]) + @ohai.provides_map.set_providers_for(@pluginB, ["B"]) + @ohai.provides_map.set_providers_for(@pluginC, ["C"]) Ohai::Log.should_not_receive(:error).with(/DependencyCycleError/) @runner.run_plugin(@pluginA) @@ -264,9 +264,9 @@ describe Ohai::Runner, "run_plugin" do end it "should not detect a cycle when C is the first provider returned" do - @ohai.attributes.set_providers_for(@pluginA, ["A"]) - @ohai.attributes.set_providers_for(@pluginC, ["C"]) - @ohai.attributes.set_providers_for(@pluginB, ["B"]) + @ohai.provides_map.set_providers_for(@pluginA, ["A"]) + @ohai.provides_map.set_providers_for(@pluginC, ["C"]) + @ohai.provides_map.set_providers_for(@pluginB, ["B"]) Ohai::Log.should_not_receive(:error).with(/DependencyCycleError/) @runner.run_plugin(@pluginA) @@ -287,7 +287,7 @@ describe Ohai::Runner, "fetch_plugins" do it "should collect the provider" do plugin = Ohai::DSL::Plugin.new(@ohai, "") - @ohai.attributes.set_providers_for(plugin, ["top/middle/bottom"]) + @ohai.provides_map.set_providers_for(plugin, ["top/middle/bottom"]) dependency_providers = @runner.fetch_plugins(["top/middle/bottom"]) dependency_providers.should eql([plugin]) diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index e002962a..c4b640b8 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -30,7 +30,7 @@ describe "Ohai::System" do end it "should set @attributes to a ProvidesMap" do - @ohai.attributes.should be_a_kind_of(Ohai::ProvidesMap) + @ohai.provides_map.should be_a_kind_of(Ohai::ProvidesMap) end it "should set @v6_dependency_solver to a Hash" do @@ -128,7 +128,7 @@ describe "Ohai::System" do @ohai = Ohai::System.new klass = Ohai.plugin(:Empty) { } plugin = klass.new(@ohai, "/tmp/plugins/empty.rb") - @ohai.attributes.should_receive(:all_plugins).and_return([plugin]) + @ohai.provides_map.should_receive(:all_plugins).and_return([plugin]) end describe "when AttributeNotFound is received" do @@ -165,7 +165,7 @@ describe "Ohai::System" do @plugins << klass.new(@ohai, "") end - @ohai.attributes.should_receive(:all_plugins).and_return(@plugins) + @ohai.provides_map.should_receive(:all_plugins).and_return(@plugins) end it "should run each plugin once from Ohai::System" do @@ -254,7 +254,7 @@ EOF end it "should find all the plugins providing attributes" do - provides_map = @ohai.attributes + provides_map = @ohai.provides_map provides_map.set_providers_for(@plugins[0], ["zero"]) provides_map.set_providers_for(@plugins[1], ["one"]) provides_map.set_providers_for(@plugins[2], ["two"]) @@ -349,7 +349,7 @@ EOF @ohai.v6_dependency_solver['v6plugin'] = @v6plugin @ohai.v6_dependency_solver['v7plugin'] = @v7plugin - @ohai.attributes.set_providers_for(@v7plugin, ["message"]) + @ohai.provides_map.set_providers_for(@v7plugin, ["message"]) end it "should run the plugin it requires" do @@ -394,7 +394,7 @@ EOF vds['v7plugin'] = @v7plugin vds['other'] = @other - dependency_map = @ohai.attributes + dependency_map = @ohai.provides_map #dependency_map[:message][:_plugins] = [@v7plugin] dependency_map.set_providers_for(@v7plugin, ["message"]) #dependency_map[:other][:_plugins] = [@other] |