Class: Bijou::Parse::ArgumentCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/bijou/backend.rb

Overview

A parser backend component for rendering the %args collection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArgumentCollection

Returns a new instance of ArgumentCollection.



16
17
18
19
# File 'lib/bijou/backend.rb', line 16

def initialize()
  super()
  @args = {}
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



21
22
23
# File 'lib/bijou/backend.rb', line 21

def args
  @args
end

Instance Method Details

#add_argument(name, expression, filename, line) ⇒ Object



23
24
25
26
# File 'lib/bijou/backend.rb', line 23

def add_argument(name, expression, filename, line)
  # TODO: Args should preserver order; change to array.
  @args[name] = [ expression, filename, line ]
end

#render_args(method, use_markers) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bijou/backend.rb', line 28

def render_args(method, use_markers)
  result = ''

  @args.each { |key, value|
    expression = value[0]
    filename = value[1]
    line = value[2]

    # REVIEW: This is a bit verbose.
    if expression
      result << "#line #{line} #{filename}\n" if use_markers
      result << "    #{key} = args.has_key?('#{key}') ? args['#{key}']" +
        " : #{expression}\n"
    else
      result << "#line #{line} #{filename}\n" if use_markers
      result << "    #{key} = args.has_key?('#{key}') ? args['#{key}']" +
        " : @context.argument_exception('#{method}', '#{key}')\n"
    end
  }

  return result
end