Class: Optitron::MethodArgs

Inherits:
SexpProcessor
  • Object
show all
Defined in:
lib/optitron/class_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cls) ⇒ MethodArgs

Returns a new instance of MethodArgs.



10
11
12
13
14
15
# File 'lib/optitron/class_dsl.rb', line 10

def initialize(cls)
  @cls = cls
  @method_map = {}
  @current_class = []
  super()
end

Instance Attribute Details

#method_mapObject (readonly)

Returns the value of attribute method_map.



9
10
11
# File 'lib/optitron/class_dsl.rb', line 9

def method_map
  @method_map
end

Instance Method Details

#process_args(exp) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/optitron/class_dsl.rb', line 61

def process_args(exp)
  exp.shift
  arg_list = []
  while !exp.empty?
    t = exp.shift
    case t
    when Symbol
      arg_list << if t.to_s[0] == ?*
        [t.to_s[1, t.to_s.size].to_sym, :greedy]
      else
        [t, :required]
      end
    when Sexp
      case t.shift
      when :block
        lasgn = t.shift
        lasgn.shift
        name = lasgn.shift
        sub_part = arg_list.find{|arg| arg.first == name}
        sub_part.clear
        sub_part << name
        sub_part << :optional
        sub_part << @ruby2ruby.process(lasgn.last)
      end
    end
  end
  @cls
  @method_map[@current_method] = arg_list if @cls.name == @current_class.map{|c| c.to_s}.join('::')
end

#process_class(exp) ⇒ Object



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

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



52
53
54
55
56
57
58
59
# File 'lib/optitron/class_dsl.rb', line 52

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

#process_module(exp) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/optitron/class_dsl.rb', line 17

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