lib/vizsla/subscribers.rb in vizsla-0.0.2 vs lib/vizsla/subscribers.rb in vizsla-0.0.3
- old
+ new
@@ -72,24 +72,27 @@
# @logger = RequestLogger.new
collect_events_data
end
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
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
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
@@ -97,11 +100,11 @@
# ===---------------------------===
# Non-Rails Hooks
# ===---------------------------===
def postgres_hook
- if !defined? Rails
+ unless rails_app?
::Vizsla::Patches.patch_postgres do |event_data|
event = SQLEvent.new event_data
@events_data << event
end
end
@@ -117,8 +120,14 @@
render_template_hook
end
def report_events_data
@logger.log_events(@events_data)
+ end
+
+ private
+
+ def rails_app?
+ defined? ::Rails
end
end
end