diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-28 10:47:09 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-28 10:47:09 -0700 |
commit | 2ad8c96935ec53c2d98201ad77fd070dc40dadb6 (patch) | |
tree | f8f4d581c3b0445df836d5e55945f62547239598 /lib/puppet/string/action_builder.rb | |
parent | 88aeb04a50d8997b5e1e0ed7a5a2239508b174ee (diff) | |
parent | b859baa04737644e40002f511c5941d002a956e3 (diff) | |
download | puppet-2ad8c96935ec53c2d98201ad77fd070dc40dadb6.tar.gz puppet-2ad8c96935ec53c2d98201ad77fd070dc40dadb6.tar.xz puppet-2ad8c96935ec53c2d98201ad77fd070dc40dadb6.zip |
Merge branch 'maint/master/puppet-strings-is-the-official-api-name'
Diffstat (limited to 'lib/puppet/string/action_builder.rb')
-rw-r--r-- | lib/puppet/string/action_builder.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/puppet/string/action_builder.rb b/lib/puppet/string/action_builder.rb new file mode 100644 index 000000000..b3db51104 --- /dev/null +++ b/lib/puppet/string/action_builder.rb @@ -0,0 +1,27 @@ +require 'puppet/string' +require 'puppet/string/action' + +class Puppet::String::ActionBuilder + attr_reader :action + + def self.build(string, name, &block) + name = name.to_s + raise "Action '#{name}' must specify a block" unless block + builder = new(string, name, &block) + builder.action + end + + def initialize(string, name, &block) + @string = string + @action = Puppet::String::Action.new(string, name) + instance_eval(&block) + end + + # 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 + end +end |