summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/option_builder.rb
blob: 83a1906b0bd7e230f1e369e290e0c38c8c8f5502 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'puppet/interface/option'

class Puppet::Interface::OptionBuilder
  attr_reader :option

  def self.build(face, *declaration, &block)
    new(face, *declaration, &block).option
  end

  private
  def initialize(face, *declaration, &block)
    @face   = face
    @option = Puppet::Interface::Option.new(face, *declaration)
    block and instance_eval(&block)
    @option
  end

  # Metaprogram the simple DSL from the option class.
  Puppet::Interface::Option.instance_methods.grep(/=$/).each do |setter|
    next if setter =~ /^=/      # special case, darn it...

    dsl = setter.sub(/=$/, '')
    define_method(dsl) do |value| @option.send(setter, value) end
  end
end