Sha256: a3b4ae767508f47e1642b70eda998f5344894552921a382aa321467e7fb15348

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 Bytes

Contents

module OptParseBuilder

  # Yielded by OptParseBuilder.bundle_arguments to create an
  # ArgumentBundle, a collection of arguments that can be treated as
  # through it is one argument.
  class ArgumentBundleBuilder

    def initialize # :nodoc:
      @argument_bundle = ArgumentBundle.new
    end

    # Add an argument to the bundle.  Takes either the argument to
    # add, or yields an ArgumentBuilder which builds a new argument
    # and adds it.
    #
    # If adding an existing argument, that argument may itself be an
    # ArgumentBundle.
    def add(argument = nil, &block)
      unless argument.nil? ^ block.nil?
        raise BuildError, "Need exactly 1 of arg and block"
      end
      if argument
        @argument_bundle << argument
      else
        @argument_bundle << OptParseBuilder.build_argument(&block)
      end
    end

    def argument # :nodoc:
      @argument_bundle.simplify
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opt_parse_builder-0.1.0 lib/opt_parse_builder/argument_bundle_builder.rb