Class: BetterRailsDebugger::Parser::Ruby::Processor

Inherits:
Parser::AST::Processor
  • Object
show all
Includes:
ProcessorExtension
Defined in:
lib/better_rails_debugger/parser/ruby/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ProcessorExtension

#get_full_class_name, #get_full_context_name, #params_to_hash

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



4
5
6
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 4

def initialize
  @information = ActiveSupport::HashWithIndifferentAccess.new
end

Instance Attribute Details

#informationObject (readonly)

Returns the value of attribute information.



3
4
5
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 3

def information
  @information
end

Instance Method Details

#cleanup_subscriptionsObject



38
39
40
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 38

def cleanup_subscriptions
  @subscriptions = Hash.new()
end

#emit_signal(signal_name, node) ⇒ Object

Call all subscriptions for the given signal

Parameters:

  • signal_name

    Symbol

  • args

    Hash



10
11
12
13
14
15
16
17
18
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 10

def emit_signal(signal_name, node)
  @subscriptions ||= Hash.new()
  @runner ||= BetterRailsDebugger::Parser::Ruby::ContextRunner.new self
  (@subscriptions[signal_name] || {}).values.each do |block|
    @runner.node = node
    @runner.instance_eval &block
    # block.call(node)
  end
end

#setupObject



42
43
44
45
46
47
48
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 42

def setup
  (@extensions = ::BetterRailsDebugger::Parser::Ruby::Extension.sorted_extensions).map do |klass|
    instance = klass.new self
    instance.setup
    instance
  end
end

#subscribe_signal(signal_name, step = :first_pass, &block) ⇒ Object

Subscribe to a particular signal

Parameters:

  • signal_name

    Symbol

  • step (defaults to: :first_pass)

    Symbol May be :first_pass or :second_pass

  • block

    Proc



24
25
26
27
28
29
30
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 24

def subscribe_signal(signal_name, step=:first_pass, &block)
  key = SecureRandom.hex(5)
  @subscriptions ||= Hash.new()
  @subscriptions[signal_name] ||= Hash.new
  @subscriptions[signal_name][key] = block
  key
end

#unsubscribe(signal_name, hash) ⇒ Object



32
33
34
35
36
# File 'lib/better_rails_debugger/parser/ruby/processor.rb', line 32

def unsubscribe(signal_name, hash)
  @subscriptions ||= Hash.new()
  @subscriptions[signal_name] ||= Hash.new
  @subscriptions[signal_name].delete hash
end