a_r_q_logger 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +54 -48
- data/lib/a_r_q_logger.rb +16 -21
- data/lib/a_r_q_logger/initializer.rb +24 -0
- data/lib/a_r_q_logger/version.rb +1 -1
- data/spec/dummy/app/models/test_child_model.rb +3 -0
- data/spec/dummy/app/models/test_model.rb +3 -0
- data/spec/dummy/config/application.rb +0 -3
- data/spec/dummy/db/migrate/20161016035357_create_test_models.rb +9 -0
- data/spec/dummy/db/migrate/20161016035434_create_test_child_models.rb +10 -0
- data/spec/dummy/db/schema.rb +28 -0
- data/spec/dummy/spec/models/test_model_spec.rb +45 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a251d9cfd3b33fcb329117f9ff040cee2ccad1
|
4
|
+
data.tar.gz: c4cfe26cbe924a0b3e0ec25f6c7e7afe80cdb699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1e088ddf44627932e295bf012762e71b02eae9c071b67473e5d20bdea464184d359484cf4eadbc369df92ed918a1ef3edff8432b5d875c4cb00cd51e1cab0b
|
7
|
+
data.tar.gz: 0709b43bc47bea5ec2c68fdffa7dc817417353e8c6de64fedb2db8060af3b91095f11bf348bc9c0af1c0ca4fdc6cdd7175e8286ec3d6e627dc41a2027b16fdb0
|
data/Gemfile.lock
CHANGED
@@ -7,42 +7,44 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
actionpack (=
|
12
|
-
|
13
|
-
|
10
|
+
actioncable (5.0.0.1)
|
11
|
+
actionpack (= 5.0.0.1)
|
12
|
+
nio4r (~> 1.2)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.0.0.1)
|
15
|
+
actionpack (= 5.0.0.1)
|
16
|
+
actionview (= 5.0.0.1)
|
17
|
+
activejob (= 5.0.0.1)
|
14
18
|
mail (~> 2.5, >= 2.5.4)
|
15
|
-
rails-dom-testing (~>
|
16
|
-
actionpack (
|
17
|
-
actionview (=
|
18
|
-
activesupport (=
|
19
|
-
rack (~>
|
20
|
-
rack-test (~> 0.6.
|
21
|
-
rails-dom-testing (~>
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.0.0.1)
|
21
|
+
actionview (= 5.0.0.1)
|
22
|
+
activesupport (= 5.0.0.1)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
22
26
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
23
|
-
actionview (
|
24
|
-
activesupport (=
|
27
|
+
actionview (5.0.0.1)
|
28
|
+
activesupport (= 5.0.0.1)
|
25
29
|
builder (~> 3.1)
|
26
30
|
erubis (~> 2.7.0)
|
27
|
-
rails-dom-testing (~>
|
31
|
+
rails-dom-testing (~> 2.0)
|
28
32
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
29
|
-
activejob (
|
30
|
-
activesupport (=
|
31
|
-
globalid (>= 0.3.
|
32
|
-
activemodel (
|
33
|
-
activesupport (=
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
activejob (5.0.0.1)
|
34
|
+
activesupport (= 5.0.0.1)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.0.0.1)
|
37
|
+
activesupport (= 5.0.0.1)
|
38
|
+
activerecord (5.0.0.1)
|
39
|
+
activemodel (= 5.0.0.1)
|
40
|
+
activesupport (= 5.0.0.1)
|
41
|
+
arel (~> 7.0)
|
42
|
+
activesupport (5.0.0.1)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
40
44
|
i18n (~> 0.7)
|
41
|
-
json (~> 1.7, >= 1.7.7)
|
42
45
|
minitest (~> 5.1)
|
43
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
44
46
|
tzinfo (~> 1.1)
|
45
|
-
arel (
|
47
|
+
arel (7.1.3)
|
46
48
|
builder (3.2.2)
|
47
49
|
concurrent-ruby (1.0.2)
|
48
50
|
coveralls (0.8.15)
|
@@ -62,43 +64,44 @@ GEM
|
|
62
64
|
globalid (0.3.7)
|
63
65
|
activesupport (>= 4.1.0)
|
64
66
|
i18n (0.7.0)
|
65
|
-
json (
|
67
|
+
json (2.0.2)
|
66
68
|
loofah (2.0.3)
|
67
69
|
nokogiri (>= 1.5.9)
|
68
70
|
mail (2.6.4)
|
69
71
|
mime-types (>= 1.16, < 4)
|
72
|
+
method_source (0.8.2)
|
70
73
|
mime-types (3.1)
|
71
74
|
mime-types-data (~> 3.2015)
|
72
75
|
mime-types-data (3.2016.0521)
|
73
76
|
mini_portile2 (2.1.0)
|
74
77
|
minitest (5.9.1)
|
78
|
+
nio4r (1.2.1)
|
75
79
|
nokogiri (1.6.8.1)
|
76
80
|
mini_portile2 (~> 2.1.0)
|
77
|
-
rack (
|
81
|
+
rack (2.0.1)
|
78
82
|
rack-test (0.6.3)
|
79
83
|
rack (>= 1.0)
|
80
|
-
rails (
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
rails (5.0.0.1)
|
85
|
+
actioncable (= 5.0.0.1)
|
86
|
+
actionmailer (= 5.0.0.1)
|
87
|
+
actionpack (= 5.0.0.1)
|
88
|
+
actionview (= 5.0.0.1)
|
89
|
+
activejob (= 5.0.0.1)
|
90
|
+
activemodel (= 5.0.0.1)
|
91
|
+
activerecord (= 5.0.0.1)
|
92
|
+
activesupport (= 5.0.0.1)
|
88
93
|
bundler (>= 1.3.0, < 2.0)
|
89
|
-
railties (=
|
90
|
-
sprockets-rails
|
91
|
-
rails-
|
92
|
-
activesupport (>= 4.2.0.
|
93
|
-
rails-dom-testing (1.0.7)
|
94
|
-
activesupport (>= 4.2.0.beta, < 5.0)
|
94
|
+
railties (= 5.0.0.1)
|
95
|
+
sprockets-rails (>= 2.0.0)
|
96
|
+
rails-dom-testing (2.0.1)
|
97
|
+
activesupport (>= 4.2.0, < 6.0)
|
95
98
|
nokogiri (~> 1.6.0)
|
96
|
-
rails-deprecated_sanitizer (>= 1.0.1)
|
97
99
|
rails-html-sanitizer (1.0.3)
|
98
100
|
loofah (~> 2.0)
|
99
|
-
railties (
|
100
|
-
actionpack (=
|
101
|
-
activesupport (=
|
101
|
+
railties (5.0.0.1)
|
102
|
+
actionpack (= 5.0.0.1)
|
103
|
+
activesupport (= 5.0.0.1)
|
104
|
+
method_source
|
102
105
|
rake (>= 0.8.7)
|
103
106
|
thor (>= 0.18.1, < 2.0)
|
104
107
|
rake (10.5.0)
|
@@ -147,6 +150,9 @@ GEM
|
|
147
150
|
tins (1.12.0)
|
148
151
|
tzinfo (1.2.2)
|
149
152
|
thread_safe (~> 0.1)
|
153
|
+
websocket-driver (0.6.4)
|
154
|
+
websocket-extensions (>= 0.1.0)
|
155
|
+
websocket-extensions (0.1.2)
|
150
156
|
|
151
157
|
PLATFORMS
|
152
158
|
ruby
|
data/lib/a_r_q_logger.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
+
require 'a_r_q_logger/initializer'
|
2
|
+
|
1
3
|
module ARQLogger
|
2
4
|
class << self
|
5
|
+
attr_accessor :store
|
6
|
+
|
7
|
+
def pass(event)
|
8
|
+
return unless store
|
9
|
+
|
10
|
+
payload = event.payload
|
11
|
+
if payload[:name] && !ActiveRecord::LogSubscriber::IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
12
|
+
store.push(event.duration)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
3
16
|
def log(&block)
|
4
17
|
start
|
5
18
|
block.call
|
@@ -9,12 +22,12 @@ module ARQLogger
|
|
9
22
|
private
|
10
23
|
|
11
24
|
def start
|
12
|
-
|
25
|
+
self.store = []
|
13
26
|
end
|
14
27
|
|
15
28
|
def finish
|
16
|
-
logged =
|
17
|
-
|
29
|
+
logged = store
|
30
|
+
self.store = nil
|
18
31
|
|
19
32
|
Result.new(
|
20
33
|
count: logged.size,
|
@@ -29,21 +42,3 @@ module ARQLogger
|
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
32
|
-
|
33
|
-
class ARQLoggerApplicationProxy < ::Rails::Railtie
|
34
|
-
initializer 'set data store for ARQLogger' do
|
35
|
-
class ::ActiveRecord::LogSubscriber
|
36
|
-
cattr_accessor :duration_store_box
|
37
|
-
|
38
|
-
alias_method :real_sql, :sql
|
39
|
-
|
40
|
-
def sql(event)
|
41
|
-
payload = event.payload
|
42
|
-
if payload[:name] && !IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
43
|
-
self.class.duration_store_box.push(event.duration) if self.class.duration_store_box
|
44
|
-
end
|
45
|
-
real_sql(event)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ARQLogger
|
2
|
+
module Initializer
|
3
|
+
def self.patch
|
4
|
+
class_eval <<-EOS
|
5
|
+
class ActiveRecord::LogSubscriber
|
6
|
+
alias_method :real_sql, :sql
|
7
|
+
|
8
|
+
def sql(event)
|
9
|
+
ARQLogger.pass(event)
|
10
|
+
real_sql(event)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if defined?(ActiveRecord::LogSubscriber)
|
19
|
+
ARQLogger::Initializer.patch
|
20
|
+
else
|
21
|
+
class ARQLoggerApplicationProxy < ::Rails::Railtie
|
22
|
+
initializer('add pass method') { ARQLogger::Initializer.patch }
|
23
|
+
end
|
24
|
+
end
|
data/lib/a_r_q_logger/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 20161016035434) do
|
14
|
+
|
15
|
+
create_table "test_child_models", force: :cascade do |t|
|
16
|
+
t.integer "test_model_id"
|
17
|
+
t.string "name"
|
18
|
+
t.datetime "created_at", null: false
|
19
|
+
t.datetime "updated_at", null: false
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "test_models", force: :cascade do |t|
|
23
|
+
t.string "name"
|
24
|
+
t.datetime "created_at", null: false
|
25
|
+
t.datetime "updated_at", null: false
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'a_r_q_logger'
|
3
|
+
|
4
|
+
RSpec.describe TestModel, type: :model do
|
5
|
+
it do
|
6
|
+
TestModel.create!
|
7
|
+
end
|
8
|
+
|
9
|
+
it do
|
10
|
+
expect(ARQLogger.log {
|
11
|
+
TestModel.create!
|
12
|
+
}.count).to eq(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it do
|
16
|
+
expect(ARQLogger.log {
|
17
|
+
TestModel.create!
|
18
|
+
TestModel.create!
|
19
|
+
}.count).to eq(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with associations' do
|
23
|
+
before :all do
|
24
|
+
10.times {
|
25
|
+
TestChildModel.create!(test_model: TestModel.create!, name: SecureRandom.hex(4))
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
after :all do
|
30
|
+
TestModel.destroy_all
|
31
|
+
end
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect(ARQLogger.log {
|
35
|
+
TestModel.includes(:test_child_models).all.each { |m| m.test_child_models.map(&:name) }
|
36
|
+
}.count).to eq(2)
|
37
|
+
end
|
38
|
+
|
39
|
+
it do
|
40
|
+
expect(ARQLogger.log {
|
41
|
+
TestModel.all.each { |m| m.test_child_models.map(&:name) }
|
42
|
+
}.count).to eq(11)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a_r_q_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmmpa
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- Rakefile
|
168
168
|
- a_r_q_logger.gemspec
|
169
169
|
- lib/a_r_q_logger.rb
|
170
|
+
- lib/a_r_q_logger/initializer.rb
|
170
171
|
- lib/a_r_q_logger/version.rb
|
171
172
|
- spec/dummy/README.rdoc
|
172
173
|
- spec/dummy/Rakefile
|
@@ -179,6 +180,8 @@ files:
|
|
179
180
|
- spec/dummy/app/mailers/.keep
|
180
181
|
- spec/dummy/app/models/.keep
|
181
182
|
- spec/dummy/app/models/concerns/.keep
|
183
|
+
- spec/dummy/app/models/test_child_model.rb
|
184
|
+
- spec/dummy/app/models/test_model.rb
|
182
185
|
- spec/dummy/app/views/layouts/application.html.erb
|
183
186
|
- spec/dummy/bin/bundle
|
184
187
|
- spec/dummy/bin/rails
|
@@ -200,12 +203,16 @@ files:
|
|
200
203
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
201
204
|
- spec/dummy/config/locales/en.yml
|
202
205
|
- spec/dummy/config/routes.rb
|
206
|
+
- spec/dummy/db/migrate/20161016035357_create_test_models.rb
|
207
|
+
- spec/dummy/db/migrate/20161016035434_create_test_child_models.rb
|
208
|
+
- spec/dummy/db/schema.rb
|
203
209
|
- spec/dummy/lib/assets/.keep
|
204
210
|
- spec/dummy/log/.keep
|
205
211
|
- spec/dummy/public/404.html
|
206
212
|
- spec/dummy/public/422.html
|
207
213
|
- spec/dummy/public/500.html
|
208
214
|
- spec/dummy/public/favicon.ico
|
215
|
+
- spec/dummy/spec/models/test_model_spec.rb
|
209
216
|
- spec/rails_helper.rb
|
210
217
|
- spec/spec_helper.rb
|
211
218
|
homepage: http://mmmpa.net
|