diff options
author | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-04-26 16:07:21 -0700 |
---|---|---|
committer | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-04-26 16:07:21 -0700 |
commit | bbf777f5f47b98d35fbbc7b8e3983d79af559017 (patch) | |
tree | 846830ee089eb6823d903ac9576551c58943adba /lib/puppet/interface/action_builder.rb | |
parent | 95ed9aadad1e694614fd47a6d56888b26ded08ed (diff) | |
download | puppet-bbf777f5f47b98d35fbbc7b8e3983d79af559017.tar.gz puppet-bbf777f5f47b98d35fbbc7b8e3983d79af559017.tar.xz puppet-bbf777f5f47b98d35fbbc7b8e3983d79af559017.zip |
(#7249) Publicize ActionBuilder DSL methods.
This change permits users to call functions with a reference to
`self` that can augment the in-progress action declaration, which can
be helpful in some more involved cases.
Reviewed-By: Max Martin
Reviewed-By: Daniel Pittman
Diffstat (limited to 'lib/puppet/interface/action_builder.rb')
-rw-r--r-- | lib/puppet/interface/action_builder.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb index 2ffa38709..afc49e945 100644 --- a/lib/puppet/interface/action_builder.rb +++ b/lib/puppet/interface/action_builder.rb @@ -9,13 +9,6 @@ class Puppet::Interface::ActionBuilder 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 @@ -56,18 +49,25 @@ class Puppet::Interface::ActionBuilder # Metaprogram the simple DSL from the target class. Puppet::Interface::Action.instance_methods.grep(/=$/).each do |setter| next if setter =~ /^=/ - dsl = setter.sub(/=$/, '') + property = setter.sub(/=$/, '') - unless private_instance_methods.include? dsl + unless public_instance_methods.include? property # Using eval because the argument handling semantics are less awful than # when we use the define_method/block version. The later warns on older # Ruby versions if you pass the wrong number of arguments, but carries # on, which is totally not what we want. --daniel 2011-04-18 - eval <<METHOD -def #{dsl}(value) - @action.#{dsl} = value -end -METHOD + eval <<-METHOD + def #{property}(value) + @action.#{property} = value + end + METHOD end end + + private + def initialize(face, name, &block) + @face = face + @action = Puppet::Interface::Action.new(face, name) + instance_eval(&block) + end end |