Class: Ramaze::Option::DSL

Inherits:
Object show all
Defined in:
lib/ramaze/option/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(holder, &block) ⇒ DSL

Returns a new instance of DSL.



9
10
11
12
13
# File 'lib/ramaze/option/dsl.rb', line 9

def initialize(holder, &block)
  @holder = holder
  @config = {}
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#holderObject (readonly)

Returns the value of attribute holder.



7
8
9
# File 'lib/ramaze/option/dsl.rb', line 7

def holder
  @holder
end

Instance Method Details

#o(doc, key, value, options = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/ramaze/option/dsl.rb', line 15

def o(doc, key, value, options = {})
  @config[key] = [doc, value, options]

  holder.add_option(key, value, complain = false)
  holder.trait[key] = options.merge(:doc => doc)
end

#outputObject

to generate a new sorted source file from the config, was only used to merge new and old DSL.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ramaze/option/dsl.rb', line 24

def output
  @config.keys.sort_by{|k,v| k.to_s }.each do |key|
    doc, value, options = @config[key]
    puts "o %s," % doc.dump

    if options.empty?
      puts "  %p, %p" % [key, value]
    else
      format = options.map{|(k,v)| '%p => %p' % [k,v]}.join(', ')
      puts "  %p, %p, %s" % [key, value, format]
    end

    puts
  end
end