Module: Remnant::Rails::ClassMethods

Included in:
Remnant::Rails
Defined in:
lib/remnant/rails.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject



4
5
6
# File 'lib/remnant/rails.rb', line 4

def logger
  ::Rails.logger
end

#setup!Object



8
9
10
11
12
13
14
15
16
17
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
44
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
# File 'lib/remnant/rails.rb', line 8

def setup!
  Remnant.configure do
    environment ::Rails.env
  end

  #
  # helper hooks
  #

  # hook into dependency unloading
  ::ActiveSupport::Dependencies.class_eval do
    class << self
      alias_method :clear_without_remnant_rediscover, :clear

      def clear(*args, &block)
        clear_without_remnant_rediscover(*args, &block).tap do
          Remnant::Discover.rediscover!
        end
      end
    end
  end


  #
  # stat collection below
  #

  # hook remnants
  Remnant::Discover.find('action',   ActionController::Base,                  :process_action)
  Remnant::Discover.find('view',     ActionController::Base,                  :render)

  #
  # Filter capturing
  #
  # TODO

  #
  # Template rendering
  #
  if defined?(ActionView) && defined?(ActionView::Template)
    Remnant::Discover.find_with(ActionView::Template) do
      ActionView::Template.class_eval do
        alias_method :render_without_remnant, :render

        def render(*args, &block)
          ::Remnant::Template.record(@virtual_path) do
            render_without_remnant(*args, &block)
          end
        end
      end
    end
  end

  #
  # database query time
  #
  ActiveSupport::Notifications.subscribe("sql.active_record") do |name, started, ended, id, payload|
    duration = ended - started
    trace = ::Rails.backtrace_cleaner.clean(Kernel.caller[1..-1])

    ::Remnant::Database.queries << ::Remnant::Database::Query.new(payload[:sql], duration, trace)
  end
end