Class: Vizsla::Subscribers

Inherits:
Object
  • Object
show all
Defined in:
lib/vizsla/subscribers.rb

Instance Method Summary collapse

Constructor Details

#initializeSubscribers

Returns a new instance of Subscribers.



70
71
72
73
# File 'lib/vizsla/subscribers.rb', line 70

def initialize
  @events_data = Recorder
  collect_events_data
end

Instance Method Details

#collect_events_dataObject

—————————===

Aux

—————————===



116
117
118
119
120
121
# File 'lib/vizsla/subscribers.rb', line 116

def collect_events_data
  sql_hook
  process_action_hook
  render_template_hook
  postgres_hook
end

#postgres_hookObject

—————————===

Non-Rails Hooks

—————————===



103
104
105
106
107
108
109
110
# File 'lib/vizsla/subscribers.rb', line 103

def postgres_hook
  unless rails_app?
    ::Vizsla::Patches.patch_postgres do |event_data|
      event = SQLEvent.new event_data
      @events_data << event
    end
  end
end

#process_action_hookObject



83
84
85
86
87
88
89
# File 'lib/vizsla/subscribers.rb', line 83

def process_action_hook
  return unless rails_app?
  ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
    event = ControllerEvent.new(args)
    @events_data << event
  end
end

#render_template_hookObject



91
92
93
94
95
96
97
# File 'lib/vizsla/subscribers.rb', line 91

def render_template_hook
  return unless rails_app?
  ActiveSupport::Notifications.subscribe "render_template.action_view" do |*args|
    event = ViewEvent.new(args)
    @events_data << event
  end
end

#report_events_dataObject



123
124
125
# File 'lib/vizsla/subscribers.rb', line 123

def report_events_data
  @logger.log_events(@events_data)
end

#sql_hookObject



75
76
77
78
79
80
81
# File 'lib/vizsla/subscribers.rb', line 75

def sql_hook
  return unless rails_app?
  ActiveSupport::Notifications.subscribe "sql.active_record" do |*args|
    event = SQLEvent.new(args)
    @events_data << event if event.valid?
  end
end