Sha256: a0702175d8872f62538417acd01119a7646842b86b7fdbb75966269e29180874

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

module Ramaze
  CLIOption = Struct.new('CLIOption', :name, :default, :doc, :cli, :short)
  OPTIONS     = {}
  CLI_OPTIONS = []

  # DSL for specifying Globap options before initializing Global

  module GlobalDSL
    class << self

      # The method that takes the block containing the DSL, used like in
      # lib/ramaze/global.rb

      def option_dsl(&block)
        instance_eval(&block)
      end

      # Takes a doc-string and then the option as hash, another :cli key can
      # be given that will expose this option via the bin/ramaze.

      def o(doc, options = {})
        cli_given = options.has_key?(:cli)
        cli = options.delete(:cli)
        short = options.delete(:short)
        name, default = options.to_a.flatten

        if cli_given
          option = CLIOption.new(name, default, doc, cli, short)
          CLI_OPTIONS << option
        end

        OPTIONS.merge!(options)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ramaze-0.1.4 lib/ramaze/global/dsl.rb
ramaze-0.2.0 lib/ramaze/global/dsl.rb
ramaze-0.2.1 lib/ramaze/global/dsl.rb