Class: ClassFilter
- Inherits:
-
Ripper::Filter
- Object
- Ripper::Filter
- ClassFilter
- Defined in:
- lib/class_filter.rb
Instance Attribute Summary collapse
-
#class ⇒ Object
Returns the value of attribute class.
-
#class_str ⇒ Object
Returns the value of attribute class_str.
-
#method_filters ⇒ Object
Returns the value of attribute method_filters.
-
#methods_str ⇒ Object
Returns the value of attribute methods_str.
Instance Method Summary collapse
- #add_tok(tok) ⇒ Object
-
#initialize(src) ⇒ ClassFilter
constructor
A new instance of ClassFilter.
- #on_const(tok, f) ⇒ Object
- #on_default(event, tok, f) ⇒ Object
- #on_do_block(tok, f) ⇒ Object
- #on_ident(tok, f) ⇒ Object
- #on_kw(tok, f) ⇒ Object
- #on_lbrase(tok, f) ⇒ Object
- #on_nl(tok, f) ⇒ Object
- #on_op(tok, f) ⇒ Object
- #on_rbrase(tok, f) ⇒ Object
Constructor Details
#initialize(src) ⇒ ClassFilter
Returns a new instance of ClassFilter.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/class_filter.rb', line 12 def initialize(src) super src @class_str = '' @methods_str = Array.new @method_filters = Array.new @methods = Array.new @is_class = false @is_method = false end |
Instance Attribute Details
#class ⇒ Object
Returns the value of attribute class.
10 11 12 |
# File 'lib/class_filter.rb', line 10 def class @class end |
#class_str ⇒ Object
Returns the value of attribute class_str.
10 11 12 |
# File 'lib/class_filter.rb', line 10 def class_str @class_str end |
#method_filters ⇒ Object
Returns the value of attribute method_filters.
10 11 12 |
# File 'lib/class_filter.rb', line 10 def method_filters @method_filters end |
#methods_str ⇒ Object
Returns the value of attribute methods_str.
10 11 12 |
# File 'lib/class_filter.rb', line 10 def methods_str @methods_str end |
Instance Method Details
#add_tok(tok) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/class_filter.rb', line 23 def add_tok tok if @is_method @methods_str[-1] += tok elsif @is_class @class_str += tok end end |
#on_const(tok, f) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/class_filter.rb', line 76 def on_const(tok, f) if @is_ancestors @parent_name += '::' + tok elsif @is_super @parent_name = tok elsif @is_class @class_name = tok end add_tok tok end |
#on_default(event, tok, f) ⇒ Object
31 32 33 |
# File 'lib/class_filter.rb', line 31 def on_default(event, tok, f) add_tok tok end |
#on_do_block(tok, f) ⇒ Object
111 112 113 114 |
# File 'lib/class_filter.rb', line 111 def on_do_block(tok, f) @is_do = true add_tok tok end |
#on_ident(tok, f) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/class_filter.rb', line 67 def on_ident(tok, f) if @is_method && MigrationDefs::MethodName.include?(tok) @method_name = tok @class.add_method(tok) end add_tok tok end |
#on_kw(tok, f) ⇒ Object
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/class_filter.rb', line 35 def on_kw(tok, f) if tok == 'class' @is_class = true elsif tok == 'def' @is_method = true @methods_str << '' elsif tok == 'do' @is_do = true end add_tok tok if tok == 'end' if @is_do @is_do = false elsif @is_func @is_func = false elsif @is_method @methods << @class.add_method(@method_name) @is_method = false elsif @is_class index = 0 @methods_str.each do |m| @method_filters << MethodFilter.new(m, @methods[index]) @method_filters.last.parse index += 1 end @is_class = false end end end |
#on_lbrase(tok, f) ⇒ Object
116 117 118 119 |
# File 'lib/class_filter.rb', line 116 def on_lbrase(tok, f) @is_do = true add_tok tok end |
#on_nl(tok, f) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/class_filter.rb', line 100 def on_nl(tok, f) if @is_class && !@class_name.nil? @class = MigrationDefs::MigrationClass.new(@class_name, @parent_name) @class_name = nil @is_ancestors = false @is_super = false end add_tok tok end |
#on_op(tok, f) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/class_filter.rb', line 88 def on_op(tok, f) if @is_class if tok == '<' @is_super = true elsif @is_super && tok == '::' @is_ancestors = true end end add_tok tok end |
#on_rbrase(tok, f) ⇒ Object
121 122 123 124 |
# File 'lib/class_filter.rb', line 121 def on_rbrase(tok, f) @is_do = false add_tok tok end |