Class: Puppet::Interface::OptionBuilder
- Inherits:
-
Object
- Object
- Puppet::Interface::OptionBuilder
- Defined in:
- lib/puppet/interface/option_builder.rb
Instance Attribute Summary (collapse)
-
- (Puppet::Interface::Option) option
readonly
private
The option under construction.
Class Method Summary (collapse)
-
+ (Puppet::Interface::Option) build(face, *declaration, &block)
private
Build an option.
Instance Method Summary (collapse)
-
- (Object) after_action(&block)
DSL
Sets a block to be executed after an action is invoked.
-
- (Object) before_action {|action, args, options| ... }
DSL
Sets a block to be executed when an action is invoked before the main action code.
-
- (Object) default_to(&block)
DSL
Sets a block that will be used to compute the default value for this option.
-
- (Object) required(value = true)
DSL
Sets whether the option is required.
Instance Attribute Details
- (Puppet::Interface::Option) option (readonly) private
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The option under construction
8 9 10 |
# File 'lib/puppet/interface/option_builder.rb', line 8 def option @option end |
Class Method Details
+ (Puppet::Interface::Option) build(face, *declaration, &block) private
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build an option
13 14 15 |
# File 'lib/puppet/interface/option_builder.rb', line 13 def self.build(face, *declaration, &block) new(face, *declaration, &block).option end |
Instance Method Details
- (Object) after_action(&block) DSL
Sets a block to be executed after an action is invoked. !(see before_action)
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/interface/option_builder.rb', line 59 def after_action(&block) block or raise ArgumentError, "#{@option} after_action requires a block" if @option.after_action raise ArgumentError, "#{@option} already has a after_action set" end unless block.arity == 3 then raise ArgumentError, "after_action takes three arguments, action, args, and options" end @option.after_action = block end |
- (Object) before_action {|action, args, options| ... } DSL
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.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppet/interface/option_builder.rb', line 44 def before_action(&block) block or raise ArgumentError, "#{@option} before_action requires a block" if @option.before_action raise ArgumentError, "#{@option} already has a before_action set" end unless block.arity == 3 then raise ArgumentError, "before_action takes three arguments, action, args, and options" end @option.before_action = block end |
- (Object) default_to(&block) DSL
Sets a block that will be used to compute the default value for this option. It will be evaluated when the action is invoked. The block should take no arguments.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/puppet/interface/option_builder.rb', line 83 def default_to(&block) block or raise ArgumentError, "#{@option} default_to requires a block" if @option.has_default? raise ArgumentError, "#{@option} already has a default value" end # Ruby 1.8 treats a block without arguments as accepting any number; 1.9 # gets this right, so we work around it for now... --daniel 2011-07-20 unless block.arity == 0 or (RUBY_VERSION =~ /^1\.8/ and block.arity == -1) raise ArgumentError, "#{@option} default_to block should not take any arguments" end @option.default = block end |
- (Object) required(value = true) DSL
Sets whether the option is required. If no argument is given it defaults to setting it as a required option.
74 75 76 |
# File 'lib/puppet/interface/option_builder.rb', line 74 def required(value = true) @option.required = value end |