Commit 502cf12a21df6567b20de73698a6bb84935bf813

Authored by Andrew Kane
2 parents 9423b5af 4571649d

Merge pull request #594 from rorkjop/master

Use Module#prepend instead of deprecated alias_method_chain
Showing 1 changed file with 13 additions and 15 deletions   Show diff stats
lib/searchkick/logging.rb
1 # based on https://gist.github.com/mnutt/566725 1 # based on https://gist.github.com/mnutt/566725
2 2
3 module Searchkick 3 module Searchkick
4 - class Query  
5 - def execute_search_with_instrumentation 4 + module QueryWithInstrumentation
  5 + def execute_search
6 event = { 6 event = {
7 name: "#{searchkick_klass.name} Search", 7 name: "#{searchkick_klass.name} Search",
8 query: params 8 query: params
9 } 9 }
10 ActiveSupport::Notifications.instrument("search.searchkick", event) do 10 ActiveSupport::Notifications.instrument("search.searchkick", event) do
11 - execute_search_without_instrumentation 11 + super
12 end 12 end
13 end 13 end
14 - alias_method_chain :execute_search, :instrumentation  
15 end 14 end
16 15
17 - class Index  
18 - def store_with_instrumentation(record) 16 + module IndexWithInstrumentation
  17 + def store(record)
19 event = { 18 event = {
20 name: "#{record.searchkick_klass.name} Store", 19 name: "#{record.searchkick_klass.name} Store",
21 id: search_id(record) 20 id: search_id(record)
22 } 21 }
23 ActiveSupport::Notifications.instrument("request.searchkick", event) do 22 ActiveSupport::Notifications.instrument("request.searchkick", event) do
24 - store_without_instrumentation(record) 23 + super(record)
25 end 24 end
26 end 25 end
27 - alias_method_chain :store, :instrumentation  
28 26
29 - def remove_with_instrumentation(record) 27 +
  28 + def remove(record)
30 event = { 29 event = {
31 name: "#{record.searchkick_klass.name} Remove", 30 name: "#{record.searchkick_klass.name} Remove",
32 id: search_id(record) 31 id: search_id(record)
33 } 32 }
34 ActiveSupport::Notifications.instrument("request.searchkick", event) do 33 ActiveSupport::Notifications.instrument("request.searchkick", event) do
35 - remove_without_instrumentation(record) 34 + super(record)
36 end 35 end
37 end 36 end
38 - alias_method_chain :remove, :instrumentation  
39 37
40 - def import_with_instrumentation(records) 38 + def import(records)
41 if records.any? 39 if records.any?
42 event = { 40 event = {
43 name: "#{records.first.searchkick_klass.name} Import", 41 name: "#{records.first.searchkick_klass.name} Import",
44 count: records.size 42 count: records.size
45 } 43 }
46 ActiveSupport::Notifications.instrument("request.searchkick", event) do 44 ActiveSupport::Notifications.instrument("request.searchkick", event) do
47 - import_without_instrumentation(records) 45 + super(records)
48 end 46 end
49 end 47 end
50 end 48 end
51 - alias_method_chain :import, :instrumentation  
52 end 49 end
53 50
54 # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb 51 # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb
@@ -131,7 +128,8 @@ module Searchkick @@ -131,7 +128,8 @@ module Searchkick
131 end 128 end
132 end 129 end
133 end 130 end
134 - 131 +Searchkick::Query.send(:prepend, Searchkick::QueryWithInstrumentation)
  132 +Searchkick::Index.send(:prepend, Searchkick::IndexWithInstrumentation)
135 Searchkick::LogSubscriber.attach_to :searchkick 133 Searchkick::LogSubscriber.attach_to :searchkick
136 ActiveSupport.on_load(:action_controller) do 134 ActiveSupport.on_load(:action_controller) do
137 include Searchkick::ControllerRuntime 135 include Searchkick::ControllerRuntime