Class: MethodFilter

Inherits:
Ripper::Filter
  • Object
show all
Defined in:
lib/method_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, mclass) ⇒ MethodFilter

Returns a new instance of MethodFilter.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/method_filter.rb', line 10

def initialize(src, mclass)
  super src

  @method_str = ''
  @funcs_str = Array.new
  @mclass = mclass
  @func_filters = Array.new
  @is_method = false
  @is_func = false
  @is_do = false
end

Instance Attribute Details

#func_filtersObject

Returns the value of attribute func_filters.



8
9
10
# File 'lib/method_filter.rb', line 8

def func_filters
  @func_filters
end

#funcs_strObject

Returns the value of attribute funcs_str.



8
9
10
# File 'lib/method_filter.rb', line 8

def funcs_str
  @funcs_str
end

#mclassObject

Returns the value of attribute mclass.



8
9
10
# File 'lib/method_filter.rb', line 8

def mclass
  @mclass
end

#method_strObject

Returns the value of attribute method_str.



8
9
10
# File 'lib/method_filter.rb', line 8

def method_str
  @method_str
end

Instance Method Details

#add_tok(tok) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/method_filter.rb', line 22

def add_tok tok
  if @is_func
    @funcs_str[-1] += tok
  elsif @is_method
    @method_str += tok
  end
end

#on_default(event, tok, f) ⇒ Object



30
31
32
# File 'lib/method_filter.rb', line 30

def on_default(event, tok, f)
  add_tok tok
end

#on_ident(tok, f) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/method_filter.rb', line 67

def on_ident(tok, f)
  if !@method_name.nil? && MigrationDefs::FuncName.has_key?(tok)
    @func_type = tok
    @is_func = true
    @funcs_str << ''
  elsif !@func_type.nil?
    @func_class = @mclass.add_func(@func_type, tok)
    @func_type = nil
  elsif MigrationDefs::MethodName.include?(tok)
    @method_name = tok
  end
  add_tok tok
end

#on_kw(tok, f) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/method_filter.rb', line 34

def on_kw(tok, f)
  if tok == 'def'
    @is_method = true
    @is_func = false
  end

  if tok == 'do'
    if !@is_do
      @is_do = true
    end
  end

  if tok == 'end'
    if @is_do
      add_tok tok
      @is_do = false
    elsif @is_func
      add_tok tok
      @is_func = false
    elsif @is_method
      index = 0
      @mclass.funcs.each do |func|
        @func_filters << FuncFilterFactory.get(func, @funcs_str[index])
        @func_filters.last.parse
        index += 1
      end
      @is_method = false
    end
  end

  add_tok tok
end

#on_lbrase(tok, f) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/method_filter.rb', line 86

def on_lbrase(tok, f)
  if !@is_func
    @is_func = true
  elsif !@is_do
    @is_do = true
  end
  add_tok tok
end

#on_nl(tok, f) ⇒ Object



81
82
83
84
# File 'lib/method_filter.rb', line 81

def on_nl(tok, f)
  @is_func = false if !@is_do
  Rails.logger.debug "on_nl2-----#{@is_do.inspect} / #{@is_func.to_s} / #{@is_method.to_s}-----"
end

#on_rbrase(tok, f) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/method_filter.rb', line 95

def on_rbrase(tok, f)
  if @is_do
    @is_do = false
  elsif @is_func
    @is_func = false
  end
  add_tok tok
end