diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 14:34:51 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 14:35:13 -0700 |
commit | 4d2a367b0cf5bf03588b1e6bbfafdf437bea249e (patch) | |
tree | 6f731f99d1e0e51ee4ba613851cc49b90633b27f | |
parent | 75ef3af26fcd205f316358b2f23abe5e200f6eaf (diff) | |
download | puppet-4d2a367b0cf5bf03588b1e6bbfafdf437bea249e.tar.gz puppet-4d2a367b0cf5bf03588b1e6bbfafdf437bea249e.tar.xz puppet-4d2a367b0cf5bf03588b1e6bbfafdf437bea249e.zip |
(#6964) use 'when_invoked' rather than 'invoke' for actions.
In the DSL we want to use 'when_invoked do' because it reads much more
naturally for users.
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
-rw-r--r-- | lib/puppet/string/action.rb | 2 | ||||
-rw-r--r-- | lib/puppet/string/action_builder.rb | 7 | ||||
-rw-r--r-- | lib/puppet/string/action_manager.rb | 2 | ||||
-rw-r--r-- | lib/puppet/string/catalog.rb | 4 | ||||
-rw-r--r-- | lib/puppet/string/catalog/select.rb | 2 | ||||
-rw-r--r-- | lib/puppet/string/certificate.rb | 6 | ||||
-rw-r--r-- | lib/puppet/string/config.rb | 2 | ||||
-rw-r--r-- | lib/puppet/string/configurer.rb | 2 | ||||
-rw-r--r-- | lib/puppet/string/facts.rb | 2 | ||||
-rw-r--r-- | lib/puppet/string/indirector.rb | 10 | ||||
-rw-r--r-- | lib/puppet/string/report.rb | 2 | ||||
-rwxr-xr-x | spec/unit/application/string_base_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/string/action_builder_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/string/action_manager_spec.rb | 50 | ||||
-rwxr-xr-x | spec/unit/string/action_spec.rb | 16 | ||||
-rwxr-xr-x | spec/unit/string_spec.rb | 2 |
16 files changed, 57 insertions, 56 deletions
diff --git a/lib/puppet/string/action.rb b/lib/puppet/string/action.rb index ee3b2991b..0f5032ffb 100644 --- a/lib/puppet/string/action.rb +++ b/lib/puppet/string/action.rb @@ -51,7 +51,7 @@ class Puppet::String::Action # @string.send(name, *args, &block) # end - def invoke=(block) + def when_invoked=(block) # We need to build an instance method as a wrapper, using normal code, to # be able to expose argument defaulting between the caller and definer in # the Ruby API. An extra method is, sadly, required for Ruby 1.8 to work. diff --git a/lib/puppet/string/action_builder.rb b/lib/puppet/string/action_builder.rb index e76044470..e7c03273b 100644 --- a/lib/puppet/string/action_builder.rb +++ b/lib/puppet/string/action_builder.rb @@ -9,6 +9,7 @@ class Puppet::String::ActionBuilder new(string, name, &block).action end + private def initialize(string, name, &block) @string = string @action = Puppet::String::Action.new(string, name) @@ -18,9 +19,9 @@ class Puppet::String::ActionBuilder # Ideally the method we're defining here would be added to the action, and a # method on the string would defer to it, but we can't get scope correct, # so we stick with this. --daniel 2011-03-24 - def invoke(&block) - raise "Invoke called on an ActionBuilder with no corresponding Action" unless @action - @action.invoke = block + def when_invoked(&block) + raise "when_invoked on an ActionBuilder with no corresponding Action" unless @action + @action.when_invoked = block end def option(*declaration, &block) diff --git a/lib/puppet/string/action_manager.rb b/lib/puppet/string/action_manager.rb index 7d22a0c52..9f0aa7582 100644 --- a/lib/puppet/string/action_manager.rb +++ b/lib/puppet/string/action_manager.rb @@ -15,7 +15,7 @@ module Puppet::String::ActionManager def script(name, &block) @actions ||= {} raise "Action #{name} already defined for #{self}" if action?(name) - @actions[name] = Puppet::String::Action.new(self, name, :invoke => block) + @actions[name] = Puppet::String::Action.new(self, name, :when_invoked => block) end def actions diff --git a/lib/puppet/string/catalog.rb b/lib/puppet/string/catalog.rb index c6de47708..441c7ee7d 100644 --- a/lib/puppet/string/catalog.rb +++ b/lib/puppet/string/catalog.rb @@ -2,7 +2,7 @@ require 'puppet/string/indirector' Puppet::String::Indirector.define(:catalog, '0.0.1') do action(:apply) do - invoke do |catalog, options| + when_invoked do |catalog, options| report = Puppet::Transaction::Report.new("apply") report.configuration_version = catalog.version @@ -23,7 +23,7 @@ Puppet::String::Indirector.define(:catalog, '0.0.1') do end action(:download) do - invoke do |certname, facts, options| + when_invoked do |certname, facts, options| Puppet::Resource::Catalog.terminus_class = :rest facts_to_upload = {:facts_format => :b64_zlib_yaml, :facts => CGI.escape(facts.render(:b64_zlib_yaml))} catalog = nil diff --git a/lib/puppet/string/catalog/select.rb b/lib/puppet/string/catalog/select.rb index a8f4480cd..11670e2e7 100644 --- a/lib/puppet/string/catalog/select.rb +++ b/lib/puppet/string/catalog/select.rb @@ -1,7 +1,7 @@ # Select and show a list of resources of a given type. Puppet::String.define(:catalog, '0.0.1') do action :select do - invoke do |host, type, options| + when_invoked do |host, type, options| catalog = Puppet::Resource::Catalog.indirection.find(host) catalog.resources.reject { |res| res.type != type }.each { |res| puts res } diff --git a/lib/puppet/string/certificate.rb b/lib/puppet/string/certificate.rb index 53f731e81..7b72b112c 100644 --- a/lib/puppet/string/certificate.rb +++ b/lib/puppet/string/certificate.rb @@ -4,7 +4,7 @@ require 'puppet/ssl/host' Puppet::String::Indirector.define(:certificate, '0.0.1') do action :generate do - invoke do |name, options| + when_invoked do |name, options| host = Puppet::SSL::Host.new(name) host.generate_certificate_request host.certificate_request.class.indirection.save(host.certificate_request) @@ -12,7 +12,7 @@ Puppet::String::Indirector.define(:certificate, '0.0.1') do end action :list do - invoke do |options| + when_invoked do |options| Puppet::SSL::Host.indirection.search("*", { :for => :certificate_request, }).map { |h| h.inspect } @@ -20,7 +20,7 @@ Puppet::String::Indirector.define(:certificate, '0.0.1') do end action :sign do - invoke do |name, options| + when_invoked do |name, options| Puppet::SSL::Host.indirection.save(Puppet::SSL::Host.new(name)) end end diff --git a/lib/puppet/string/config.rb b/lib/puppet/string/config.rb index 49a1688fc..8a9417148 100644 --- a/lib/puppet/string/config.rb +++ b/lib/puppet/string/config.rb @@ -2,7 +2,7 @@ require 'puppet/string' Puppet::String.define(:config, '0.0.1') do action(:print) do - invoke do |*args| + when_invoked do |*args| options = args.pop Puppet.settings[:configprint] = args.join(",") Puppet.settings.print_config_options diff --git a/lib/puppet/string/configurer.rb b/lib/puppet/string/configurer.rb index 2520d4188..257f97e90 100644 --- a/lib/puppet/string/configurer.rb +++ b/lib/puppet/string/configurer.rb @@ -2,7 +2,7 @@ require 'puppet/string' Puppet::String.define(:configurer, '0.0.1') do action(:synchronize) do - invoke do |certname, options| + when_invoked do |certname, options| facts = Puppet::String[:facts, '0.0.1'].find(certname) catalog = Puppet::String[:catalog, '0.0.1'].download(certname, facts) report = Puppet::String[:catalog, '0.0.1'].apply(catalog) diff --git a/lib/puppet/string/facts.rb b/lib/puppet/string/facts.rb index 31298813b..6bd9904b0 100644 --- a/lib/puppet/string/facts.rb +++ b/lib/puppet/string/facts.rb @@ -6,7 +6,7 @@ Puppet::String::Indirector.define(:facts, '0.0.1') do # Upload our facts to the server action(:upload) do - invoke do |options| + when_invoked do |options| Puppet::Node::Facts.indirection.terminus_class = :facter facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) Puppet::Node::Facts.indirection.terminus_class = :rest diff --git a/lib/puppet/string/indirector.rb b/lib/puppet/string/indirector.rb index bb081533f..0c7d043bb 100644 --- a/lib/puppet/string/indirector.rb +++ b/lib/puppet/string/indirector.rb @@ -31,24 +31,24 @@ that we should describe in this file somehow." end action :destroy do - invoke { |*args| call_indirection_method(:destroy, *args) } + when_invoked { |*args| call_indirection_method(:destroy, *args) } end action :find do - invoke { |*args| call_indirection_method(:find, *args) } + when_invoked { |*args| call_indirection_method(:find, *args) } end action :save do - invoke { |*args| call_indirection_method(:save, *args) } + when_invoked { |*args| call_indirection_method(:save, *args) } end action :search do - invoke { |*args| call_indirection_method(:search, *args) } + when_invoked { |*args| call_indirection_method(:search, *args) } end # Print the configuration for the current terminus class action :info do - invoke do |*args| + when_invoked do |*args| options = args.pop options.has_key?(:terminus) and set_terminus(options[:terminus]) diff --git a/lib/puppet/string/report.rb b/lib/puppet/string/report.rb index 5b617e49e..da3ca8504 100644 --- a/lib/puppet/string/report.rb +++ b/lib/puppet/string/report.rb @@ -2,7 +2,7 @@ require 'puppet/string/indirector' Puppet::String::Indirector.define(:report, '0.0.1') do action(:submit) do - invoke do |report, options| + when_invoked do |report, options| begin Puppet::Transaction::Report.terminus_class = :rest report.save diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb index 71e67283d..753d911d1 100755 --- a/spec/unit/application/string_base_spec.rb +++ b/spec/unit/application/string_base_spec.rb @@ -23,7 +23,7 @@ describe Puppet::Application::StringBase do action :foo do option("--action") - invoke { |*args| args.length } + when_invoked { |*args| args.length } end end end diff --git a/spec/unit/string/action_builder_spec.rb b/spec/unit/string/action_builder_spec.rb index fde010d51..5f6f1c08f 100755 --- a/spec/unit/string/action_builder_spec.rb +++ b/spec/unit/string/action_builder_spec.rb @@ -15,7 +15,7 @@ describe Puppet::String::ActionBuilder do it "should define a method on the string which invokes the action" do string = Puppet::String.new(:action_builder_test_string, '0.0.1') action = Puppet::String::ActionBuilder.build(string, :foo) do - invoke do + when_invoked do "invoked the method" end end diff --git a/spec/unit/string/action_manager_spec.rb b/spec/unit/string/action_manager_spec.rb index 5ca55b387..b8baf80a5 100755 --- a/spec/unit/string/action_manager_spec.rb +++ b/spec/unit/string/action_manager_spec.rb @@ -15,7 +15,7 @@ describe Puppet::String::ActionManager do describe "when included in a class" do it "should be able to define an action" do subject.action(:foo) do - invoke { "something "} + when_invoked { "something "} end end @@ -27,10 +27,10 @@ describe Puppet::String::ActionManager do it "should be able to list defined actions" do subject.action(:foo) do - invoke { "something" } + when_invoked { "something" } end subject.action(:bar) do - invoke { "something" } + when_invoked { "something" } end subject.actions.should =~ [:foo, :bar] @@ -43,7 +43,7 @@ describe Puppet::String::ActionManager do it "should list both script and normal actions" do subject.action :foo do - invoke do "foo" end + when_invoked do "foo" end end subject.script :bar do "a bar is where beer is found" end @@ -52,7 +52,7 @@ describe Puppet::String::ActionManager do it "should be able to indicate when an action is defined" do subject.action(:foo) do - invoke { "something" } + when_invoked { "something" } end subject.should be_action(:foo) @@ -65,7 +65,7 @@ describe Puppet::String::ActionManager do it "should correctly treat action names specified as strings" do subject.action(:foo) do - invoke { "something" } + when_invoked { "something" } end subject.should be_action("foo") @@ -77,16 +77,16 @@ describe Puppet::String::ActionManager do it "should be able to define an action" do subject.action(:foo) do - invoke { "something "} + when_invoked { "something "} end end it "should be able to list defined actions" do subject.action(:foo) do - invoke { "something" } + when_invoked { "something" } end subject.action(:bar) do - invoke { "something" } + when_invoked { "something" } end subject.actions.should include(:bar) @@ -110,36 +110,36 @@ describe Puppet::String::ActionManager do it "should be able to define an action at the class level" do @klass.action(:foo) do - invoke { "something "} + when_invoked { "something "} end end it "should create an instance method when an action is defined at the class level" do @klass.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.foo.should == "something" end it "should be able to define an action at the instance level" do @instance.action(:foo) do - invoke { "something "} + when_invoked { "something "} end end it "should create an instance method when an action is defined at the instance level" do @instance.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.foo.should == "something" end it "should be able to list actions defined at the class level" do @klass.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @klass.action(:bar) do - invoke { "something" } + when_invoked { "something" } end @klass.actions.should include(:bar) @@ -148,10 +148,10 @@ describe Puppet::String::ActionManager do it "should be able to list actions defined at the instance level" do @instance.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.action(:bar) do - invoke { "something" } + when_invoked { "something" } end @instance.actions.should include(:bar) @@ -160,10 +160,10 @@ describe Puppet::String::ActionManager do it "should be able to list actions defined at both instance and class level" do @klass.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.action(:bar) do - invoke { "something" } + when_invoked { "something" } end @instance.actions.should include(:bar) @@ -172,14 +172,14 @@ describe Puppet::String::ActionManager do it "should be able to indicate when an action is defined at the class level" do @klass.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.should be_action(:foo) end it "should be able to indicate when an action is defined at the instance level" do @klass.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.should be_action(:foo) end @@ -189,13 +189,13 @@ describe Puppet::String::ActionManager do @instance = @subclass.new @klass.action(:parent) do - invoke { "a" } + when_invoked { "a" } end @subclass.action(:sub) do - invoke { "a" } + when_invoked { "a" } end @instance.action(:instance) do - invoke { "a" } + when_invoked { "a" } end @instance.should be_action(:parent) @@ -208,7 +208,7 @@ describe Puppet::String::ActionManager do @instance = @subclass.new @klass.action(:foo) do - invoke { "something" } + when_invoked { "something" } end @instance.foo.should == "something" end diff --git a/spec/unit/string/action_spec.rb b/spec/unit/string/action_spec.rb index 1d25ff156..b6fe87a63 100755 --- a/spec/unit/string/action_spec.rb +++ b/spec/unit/string/action_spec.rb @@ -17,11 +17,11 @@ describe Puppet::String::Action do it "should be able to call other actions on the same object" do string = Puppet::String.new(:my_string, '0.0.1') do action(:foo) do - invoke { 25 } + when_invoked { 25 } end action(:bar) do - invoke { "the value of foo is '#{foo}'" } + when_invoked { "the value of foo is '#{foo}'" } end end string.foo.should == 25 @@ -35,25 +35,25 @@ describe Puppet::String::Action do it "should be able to call other actions on the same object when defined on a class" do class Puppet::String::MyStringBaseClass < Puppet::String action(:foo) do - invoke { 25 } + when_invoked { 25 } end action(:bar) do - invoke { "the value of foo is '#{foo}'" } + when_invoked { "the value of foo is '#{foo}'" } end action(:quux) do - invoke { "qux told me #{qux}" } + when_invoked { "qux told me #{qux}" } end end string = Puppet::String::MyStringBaseClass.new(:my_inherited_string, '0.0.1') do action(:baz) do - invoke { "the value of foo in baz is '#{foo}'" } + when_invoked { "the value of foo in baz is '#{foo}'" } end action(:qux) do - invoke { baz } + when_invoked { baz } end end string.foo.should == 25 @@ -67,7 +67,7 @@ describe Puppet::String::Action do let :string do Puppet::String.new(:ruby_api, '1.0.0') do action :bar do - invoke do |options| + when_invoked do |options| options end end diff --git a/spec/unit/string_spec.rb b/spec/unit/string_spec.rb index ddf855475..358668f9b 100755 --- a/spec/unit/string_spec.rb +++ b/spec/unit/string_spec.rb @@ -43,7 +43,7 @@ describe Puppet::String do it "should instance-eval any provided block" do face = Puppet::String.new(:string_test_block, '0.0.1') do action(:something) do - invoke { "foo" } + when_invoked { "foo" } end end |