summaryrefslogtreecommitdiffstats
path: root/lib/puppet/string
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-04 14:34:51 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-04 14:35:13 -0700
commit4d2a367b0cf5bf03588b1e6bbfafdf437bea249e (patch)
tree6f731f99d1e0e51ee4ba613851cc49b90633b27f /lib/puppet/string
parent75ef3af26fcd205f316358b2f23abe5e200f6eaf (diff)
downloadpuppet-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>
Diffstat (limited to 'lib/puppet/string')
-rw-r--r--lib/puppet/string/action.rb2
-rw-r--r--lib/puppet/string/action_builder.rb7
-rw-r--r--lib/puppet/string/action_manager.rb2
-rw-r--r--lib/puppet/string/catalog.rb4
-rw-r--r--lib/puppet/string/catalog/select.rb2
-rw-r--r--lib/puppet/string/certificate.rb6
-rw-r--r--lib/puppet/string/config.rb2
-rw-r--r--lib/puppet/string/configurer.rb2
-rw-r--r--lib/puppet/string/facts.rb2
-rw-r--r--lib/puppet/string/indirector.rb10
-rw-r--r--lib/puppet/string/report.rb2
11 files changed, 21 insertions, 20 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