Class: VisualMigrateRipper
- Inherits:
-
Ripper::Filter
- Object
- Ripper::Filter
- VisualMigrateRipper
- Defined in:
- lib/visual_migrate_ripper.rb
Instance Attribute Summary collapse
-
#class ⇒ Object
readonly
Returns the value of attribute class.
Instance Method Summary collapse
-
#initialize(src) ⇒ VisualMigrateRipper
constructor
A new instance of VisualMigrateRipper.
- #on_comma(tok, f) ⇒ Object
- #on_const(tok, f) ⇒ Object
- #on_do_block(tok, f) ⇒ Object
- #on_ident(tok, f) ⇒ Object
- #on_int(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
- #on_tstring_content(tok, f) ⇒ Object
Constructor Details
#initialize(src) ⇒ VisualMigrateRipper
Returns a new instance of VisualMigrateRipper.
9 10 11 12 13 14 15 16 |
# File 'lib/visual_migrate_ripper.rb', line 9 def initialize(src) super src @is_class = false @is_method = false @is_func = false @is_do = false end |
Instance Attribute Details
#class ⇒ Object (readonly)
Returns the value of attribute class.
7 8 9 |
# File 'lib/visual_migrate_ripper.rb', line 7 def class @class end |
Instance Method Details
#on_comma(tok, f) ⇒ Object
134 135 136 |
# File 'lib/visual_migrate_ripper.rb', line 134 def on_comma(tok, f) @on_comma = true end |
#on_const(tok, f) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/visual_migrate_ripper.rb', line 92 def on_const(tok, f) if @is_ancestors @parent_name += '::' + tok elsif @is_super @parent_name = tok elsif @is_class @class_name = tok end end |
#on_do_block(tok, f) ⇒ Object
122 123 124 |
# File 'lib/visual_migrate_ripper.rb', line 122 def on_do_block(tok, f) @is_do = true end |
#on_ident(tok, f) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 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 83 84 85 86 87 88 89 90 |
# File 'lib/visual_migrate_ripper.rb', line 45 def on_ident(tok, f) if tok == 't' @is_option_type = true elsif @is_option_type if tok == 'timestamps' @class.methods[@method_name].funcs[@func_name].add_option(tok) @is_option_type = false @is_option = false else @option_type = tok @is_option = true end @is_option_type = false elsif @is_option if !@option_type.nil? @class.methods[@method_name].funcs[@func_name].add_option(@option_type, tok) @option_name = tok @is_option_option = true @option_type = nil elsif @option_option_name.nil? @option_option_name = tok @is_option_option = true end elsif @is_func_option if @func_option.nil? @func_option = tok else @func_class.option.set_option(@func_option, tok) @func_option = nil end elsif !@method_name.nil? && MigrationDefs::FuncName.has_key?(tok) @func_type = tok @is_func = true elsif @is_func if !@func_type.nil? @func_class = @class.methods[@method_name].add_func(@func_type, tok) @is_func_option = true @func_name = tok @func_type = nil end @is_func = false elsif MigrationDefs::MethodName.include?(tok) @method_name = tok @class.add_method(tok) end end |
#on_int(tok, f) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/visual_migrate_ripper.rb', line 148 def on_int(tok, f) if @is_option_option && !@option_option_name.nil? @class.methods[@method_name].funcs[@func_name]..last.set_option(@option_option_name, tok) @option_option_name = nil elsif @is_func_option && !@func_option.nil? @func_class.option.set_option(@func_option, tok) @func_option = nil end end |
#on_kw(tok, f) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/visual_migrate_ripper.rb', line 18 def on_kw(tok, f) if tok == 'class' @is_class = true elsif tok == 'def' @is_method = true @is_func = false elsif tok == 'end' if @is_option @is_option = false elsif @is_do @is_do = false elsif @is_func @is_func = false elsif @is_method @is_method = false end elsif tok == 'true' || tok == 'false' if @is_option_option && !@option_option_name.nil? @class.methods[@method_name].funcs[@func_name]..last.set_option(@option_option_name, "'" + tok + "'") @option_option_name = nil elsif @is_func_option && !@func_option.nil? @func_class.option.set_option(@func_option, tok) @func_option = nil end end end |
#on_lbrase(tok, f) ⇒ Object
126 127 128 |
# File 'lib/visual_migrate_ripper.rb', line 126 def on_lbrase(tok, f) @is_do = true end |
#on_nl(tok, f) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/visual_migrate_ripper.rb', line 110 def on_nl(tok, f) if @is_class @class = MigrationDefs::MigrationClass.new(@class_name, @parent_name) @is_class = false @is_ancestors = false @is_super = false end @is_func_option = false @is_option = false @is_option_option = false end |
#on_op(tok, f) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/visual_migrate_ripper.rb', line 102 def on_op(tok, f) if tok == '<' @is_super = true elsif @is_super && tok == '::' @is_ancestors = true end end |
#on_rbrase(tok, f) ⇒ Object
130 131 132 |
# File 'lib/visual_migrate_ripper.rb', line 130 def on_rbrase(tok, f) @is_do = false end |
#on_tstring_content(tok, f) ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/visual_migrate_ripper.rb', line 138 def on_tstring_content(tok, f) if @is_option_option && !@option_option_name.nil? @class.methods[@method_name].funcs[@func_name]..last.set_option(@option_option_name, "'" + tok + "'") @option_option_name = nil elsif @is_func_option && !@func_option.nil? @func_class.option.set_option(@func_option, "'" + tok + "'") @func_option = nil end end |