Method: Puppet::Interface::OptionBuilder#before_action
- Defined in:
- lib/puppet/interface/option_builder.rb
#before_action {|action, args, options| ... } ⇒ Object
Sets a block to be executed when an action is invoked before the main action code. This is most commonly used to validate an option.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/interface/option_builder.rb', line 42 def before_action(&block) unless block #TRANSLATORS 'before_action' is a method name and should not be translated raise ArgumentError, _("%{option} before_action requires a block") % { option: @option } end if @option.before_action #TRANSLATORS 'before_action' is a method name and should not be translated raise ArgumentError, _("%{option} already has a before_action set") % { option: @option } end unless block.arity == 3 then #TRANSLATORS 'before_action' is a method name and should not be translated raise ArgumentError, _("before_action takes three arguments, action, args, and options") end @option.before_action = block end |