Class: ParametersExtra::Processor

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/parameters_extra/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



6
7
8
9
10
# File 'lib/parameters_extra/processor.rb', line 6

def initialize
  @methods = Hash.new{|h,k| h[k] = []}
  @current_class = []
  super()
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



4
5
6
# File 'lib/parameters_extra/processor.rb', line 4

def methods
  @methods
end

Instance Method Details

#current_classnameObject



84
85
86
# File 'lib/parameters_extra/processor.rb', line 84

def current_classname
  @current_class.map{|c| c.to_s}.join('::')
end

#process_args(exp) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/parameters_extra/processor.rb', line 56

def process_args(exp)
  exp.shift
  arg_list = Args.new(@current_class.clone)
  while !exp.empty?
    t = exp.shift
    case t
    when Symbol
      arg_list << case t.to_s[0]
      when ?* then Args::Arg.new(t.to_s[1, t.to_s.size].to_sym, :splat)
      when ?& then Args::Arg.new(t.to_s[1, t.to_s.size].to_sym, :block)
      else         Args::Arg.new(t, :required)
      end
    when Sexp
      case t.shift
      when :block
        while lasgn = t.shift
          lasgn.shift
          name = lasgn.shift
          new_arg = Args::Arg.new(name, :optional, @ruby2ruby.process(lasgn.last))
          arg_list.each_with_index{|arg, idx| arg_list[idx] = new_arg if arg.name == name}
        end
      end
    end
  end
  @methods[current_classname] << [@current_method, arg_list]
  exp
end

#process_class(exp) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/parameters_extra/processor.rb', line 21

def process_class(exp)
  exp.shift
  current_class_size = @current_class.size
  case exp.first
  when Symbol
    @current_class << exp.first.to_sym
    process(exp)
  else
    if exp.first.first == :colon2
      exp.first.shift
      class_exp = exp.shift
      class_exp[0, class_exp.size - 1].each do |const|
        @current_class << const.last
      end
      @current_class << class_exp.last
    else
      raise
    end
    exp.shift
    process(exp.first)
  end
  @current_class.slice!(current_class_size, @current_class.size)
  exp.clear
  exp
end

#process_defn(exp) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/parameters_extra/processor.rb', line 47

def process_defn(exp)
  exp.shift
  @current_method = exp.shift
  @ruby2ruby = Ruby2Ruby.new
  process_args(exp.shift)
  exp.shift
  exp
end

#process_module(exp) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/parameters_extra/processor.rb', line 12

def process_module(exp)
  exp.shift
  @current_class << exp.first.to_sym
  process(exp)
  @current_class.pop
  exp.clear
  exp
end