Class: BetterRailsDebugger::Parser::Ruby::ContextDefiner
- Defined in:
- lib/better_rails_debugger/parser/ruby/basic_extensions/context_definer.rb
Instance Method Summary collapse
Methods inherited from Extension
config_for, #initialize, name, position, #run, sorted_extensions
Constructor Details
This class inherits a constructor from BetterRailsDebugger::Parser::Ruby::Extension
Instance Method Details
#setup ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/better_rails_debugger/parser/ruby/basic_extensions/context_definer.rb', line 99 def setup # Module processor.subscribe_signal :begin_module do full_name = processor.get_full_context_name(node) full_name.split('::').each do |name| push_context name end end processor.subscribe_signal :end_module do full_name = processor.get_full_context_name(node) full_name.split('::').size.times do pop_context end end # CLASS processor.subscribe_signal :begin_class do klass, superclass, _ = *node full_name = processor.get_full_context_name(klass) # get basic information before_context = (current_context || []).join('::') if full_name['::'].present? complete_current_context = "#{before_context}::#{full_name}" else complete_current_context = full_name end class_info = (get complete_current_context) || HashWithIndifferentAccess.new class_info[:type] = 'class' class_info[:full_type] = 'class' class_info[:location] = klass.loc # Detect superclass class_info[:superclass] = processor.get_full_context_name superclass full_name.split('::').each do |name| push_context name end set complete_current_context, class_info end processor.subscribe_signal :end_class do full_name = processor.get_full_context_name(node) full_name.split('::').size.times do pop_context end end # SELF CLASS(class << self; end) processor.subscribe_signal :begin_sclass do # get basic information before_context = current_context.join('::') # set current context and information about it push_context 'self' if before_context.present? complete_current_context = "#{before_context}::self" else complete_current_context = 'self' end class_info = (get complete_current_context) || HashWithIndifferentAccess.new class_info[:type] = 'class' class_info[:full_type] = 'sclass' class_info[:location] = node.loc set complete_current_context, class_info end processor.subscribe_signal :end_sclass do pop_context end # def processor.subscribe_signal :begin_def do name, args, _ = *node # Class or module method if current_context.present? method_context = current_context.join('::') info = (get method_context) || HashWithIndifferentAccess.new info[:methods] ||= HashWithIndifferentAccess.new info[:methods][name] ||= HashWithIndifferentAccess.new info[:methods][name][:location] = node.loc info[:methods][name][:arguments] = processor.params_to_hash(args) else # Global methods method_context = "##{name}" info = HashWithIndifferentAccess.new info[:location] = node.loc info[:arguments] = processor.params_to_hash(args) set method_context, info end # set current context and information about it push_context "##{name}" end processor.subscribe_signal :end_def do pop_context end # defs (def self.method_name) processor.subscribe_signal :begin_defs do _, name, _, args= *node # Class or module method if current_context.present? # Push the method inside self definition, this is MyClass::Self methods => [] method_context = current_context.join('::') + '::self' info = (get method_context) || HashWithIndifferentAccess.new info[:methods] ||= HashWithIndifferentAccess.new info[:methods][name] ||= HashWithIndifferentAccess.new info[:methods][name][:location] = node.loc info[:methods][name][:arguments] = processor.params_to_hash(args) else # Global methods method_context = "##{name}" info = HashWithIndifferentAccess.new info[:location] = node.loc info[:arguments] = processor.params_to_hash(args) set method_context, info end # set current context and information about it push_context 'self' push_context "##{name}" end processor.subscribe_signal :end_defs do pop_context # method name pop_context # self end # block (like map, each lambda or any other block param) # Context format $block#<method name, like each, map or lambda> processor.subscribe_signal :begin_block do method, _, _ = *node push_context "$block##{method.to_sexp_array[2]}" end processor.subscribe_signal :end_block do pop_context end # lambda (TODO) processor.subscribe_signal :begin_lambda do end processor.subscribe_signal :end_lambda do end # while processor.subscribe_signal :begin_while do push_context '$while' end processor.subscribe_signal :end_while do pop_context end # until processor.subscribe_signal :begin_until do push_context '$until' end processor.subscribe_signal :end_until do pop_context end # for processor.subscribe_signal :begin_for do push_context '$for' end processor.subscribe_signal :end_for do pop_context end end |