class Puppet::Interface::OptionBuilder

@api public

Attributes

option[R]

The option under construction @return [Puppet::Interface::Option] @api private

Public Class Methods

build(face, *declaration, &block) click to toggle source

Build an option @return [Puppet::Interface::Option] @api private

# File lib/puppet/interface/option_builder.rb, line 13
def self.build(face, *declaration, &block)
  new(face, *declaration, &block).option
end
new(face, *declaration, &block) click to toggle source
# File lib/puppet/interface/option_builder.rb, line 17
def initialize(face, *declaration, &block)
  @face   = face
  @option = Puppet::Interface::Option.new(face, *declaration)
  instance_eval(&block) if block_given?
  @option
end

Public Instance Methods

after_action(&block) click to toggle source

Sets a block to be executed after an action is invoked. !(see #before_action) @api public @dsl Faces

# 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
before_action(&block) click to toggle source

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. @yieldparam action [Puppet::Interface::Action] The action being

invoked

@yieldparam args [Array] The arguments given to the action @yieldparam options [Hash<Symbol=>Object>] Any options set @api public @dsl Faces

# 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
default_to(&block) click to toggle source

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. @api public @dsl Faces

# 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
required(value = true) click to toggle source

Sets whether the option is required. If no argument is given it defaults to setting it as a required option. @api public @dsl Faces

# File lib/puppet/interface/option_builder.rb, line 74
def required(value = true)
  @option.required = value
end