diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-15 15:34:24 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-15 15:34:24 -0700 |
| commit | 0d0318f9f0eadff7f9934d3d02a7081bba05164c (patch) | |
| tree | dfc6b3d976ac5acf822846c272bdb4451b10aeba /lib/puppet/interface/action.rb | |
| parent | 3fe01a34e8397c30a00e7d47b4ac0b93198e1fcf (diff) | |
| parent | d80500f42367fa30a00dc12ef4b32b55b350b1ca (diff) | |
| download | puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.tar.gz puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.tar.xz puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.zip | |
Merge branch 'feature/2.7.x/6978-face-and-action-options-should-have-hooks-for-various-actions' into 2.7.x
Diffstat (limited to 'lib/puppet/interface/action.rb')
| -rw-r--r-- | lib/puppet/interface/action.rb | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index 3c18c2aaf..b94298963 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -7,8 +7,9 @@ class Puppet::Interface::Action raise "#{name.inspect} is an invalid action name" unless name.to_s =~ /^[a-z]\w*$/ @face = face @name = name.to_sym - @options = {} attrs.each do |k, v| send("#{k}=", v) end + + @options = {} end # This is not nice, but it is the easiest way to make us behave like the @@ -84,11 +85,21 @@ class Puppet::Interface::Action internal_name = "#{@name} implementation, required on Ruby 1.8".to_sym file = __FILE__ + "+eval" line = __LINE__ + 1 - wrapper = "def #{@name}(*args, &block) - args << {} unless args.last.is_a? Hash - args << block if block_given? - self.__send__(#{internal_name.inspect}, *args) - end" + wrapper = <<WRAPPER +def #{@name}(*args, &block) + if args.last.is_a? Hash then + options = args.last + else + args << (options = {}) + end + + action = get_action(#{name.inspect}) + __invoke_decorations(:before, action, args, options) + rval = self.__send__(#{internal_name.inspect}, *args) + __invoke_decorations(:after, action, args, options) + return rval +end +WRAPPER if @face.is_a?(Class) @face.class_eval do eval wrapper, nil, file, line end @@ -123,7 +134,19 @@ class Puppet::Interface::Action (@options.keys + @face.options).sort end - def get_option(name) - @options[name.to_sym] || @face.get_option(name) + def get_option(name, with_inherited_options = true) + option = @options[name.to_sym] + if option.nil? and with_inherited_options + option = @face.get_option(name) + end + option + end + + ######################################################################## + # Support code for action decoration; see puppet/interface.rb for the gory + # details of why this is hidden away behind private. --daniel 2011-04-15 + private + def __decorate(type, name, proc) + @face.__send__ :__decorate, type, name, proc end end |
