diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 17:58:07 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 18:01:33 -0700 |
| commit | 0f24db1c3fd0aa6601ba032aedbe25be36010954 (patch) | |
| tree | 08af1180a4468145af66ee429ce3a80236e08fff /lib/puppet/interface/action_builder.rb | |
| parent | af792351a62399f8bbeba0d2425f2b88eabb3dff (diff) | |
| parent | 79f4774182046d2fdf392c1eb27ee78505659199 (diff) | |
| download | puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.tar.gz puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.tar.xz puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.zip | |
Merge puppet-interfaces into puppet.
This joins the two repositories, including full history, into a single run, as
well as landing the interfaces work on the next branch ready for release.
Diffstat (limited to 'lib/puppet/interface/action_builder.rb')
| -rw-r--r-- | lib/puppet/interface/action_builder.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb new file mode 100644 index 000000000..b08c3d023 --- /dev/null +++ b/lib/puppet/interface/action_builder.rb @@ -0,0 +1,31 @@ +require 'puppet/interface' +require 'puppet/interface/action' + +class Puppet::Interface::ActionBuilder + attr_reader :action + + def self.build(face, name, &block) + raise "Action #{name.inspect} must specify a block" unless block + new(face, name, &block).action + end + + private + def initialize(face, name, &block) + @face = face + @action = Puppet::Interface::Action.new(face, name) + instance_eval(&block) + end + + # Ideally the method we're defining here would be added to the action, and a + # method on the face would defer to it, but we can't get scope correct, so + # we stick with this. --daniel 2011-03-24 + 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) + option = Puppet::Interface::OptionBuilder.build(@action, *declaration, &block) + @action.add_option(option) + end +end |
