a_r_q_logger 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6114759f2f64fb1e746e8a923e7e44c0a27ed7bd
4
- data.tar.gz: a2ddaeec362030948e7a4e6af3319b180afe761a
3
+ metadata.gz: b9a251d9cfd3b33fcb329117f9ff040cee2ccad1
4
+ data.tar.gz: c4cfe26cbe924a0b3e0ec25f6c7e7afe80cdb699
5
5
  SHA512:
6
- metadata.gz: 5b5e549c08d77ffeec395f6740bfbbd655d339a3678d27a8a006eb575bb5e9defa1a532c56e8899e2fdfe8cc4917fdbb0c35e83ea712db9d9ef1f96f44974724
7
- data.tar.gz: 9e81078f265d2a3408d85c8c481ae8adbbab5bc38a4f510c0f9fbc3f2e1570cfa4686d26cb0a985f316c9f1b6ec41c2f06cf27fee6ac080053184a5c63eb089d
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
- actionmailer (4.2.7.1)
11
- actionpack (= 4.2.7.1)
12
- actionview (= 4.2.7.1)
13
- activejob (= 4.2.7.1)
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 (~> 1.0, >= 1.0.5)
16
- actionpack (4.2.7.1)
17
- actionview (= 4.2.7.1)
18
- activesupport (= 4.2.7.1)
19
- rack (~> 1.6)
20
- rack-test (~> 0.6.2)
21
- rails-dom-testing (~> 1.0, >= 1.0.5)
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 (4.2.7.1)
24
- activesupport (= 4.2.7.1)
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 (~> 1.0, >= 1.0.5)
31
+ rails-dom-testing (~> 2.0)
28
32
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- activejob (4.2.7.1)
30
- activesupport (= 4.2.7.1)
31
- globalid (>= 0.3.0)
32
- activemodel (4.2.7.1)
33
- activesupport (= 4.2.7.1)
34
- builder (~> 3.1)
35
- activerecord (4.2.7.1)
36
- activemodel (= 4.2.7.1)
37
- activesupport (= 4.2.7.1)
38
- arel (~> 6.0)
39
- activesupport (4.2.7.1)
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 (6.0.3)
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 (1.8.3)
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 (1.6.4)
81
+ rack (2.0.1)
78
82
  rack-test (0.6.3)
79
83
  rack (>= 1.0)
80
- rails (4.2.7.1)
81
- actionmailer (= 4.2.7.1)
82
- actionpack (= 4.2.7.1)
83
- actionview (= 4.2.7.1)
84
- activejob (= 4.2.7.1)
85
- activemodel (= 4.2.7.1)
86
- activerecord (= 4.2.7.1)
87
- activesupport (= 4.2.7.1)
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 (= 4.2.7.1)
90
- sprockets-rails
91
- rails-deprecated_sanitizer (1.0.3)
92
- activesupport (>= 4.2.0.alpha)
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 (4.2.7.1)
100
- actionpack (= 4.2.7.1)
101
- activesupport (= 4.2.7.1)
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
- ActiveRecord::LogSubscriber.duration_store_box = []
25
+ self.store = []
13
26
  end
14
27
 
15
28
  def finish
16
- logged = ActiveRecord::LogSubscriber.duration_store_box
17
- ActiveRecord::LogSubscriber.duration_store_box = nil
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
@@ -1,3 +1,3 @@
1
1
  module ARQLogger
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,3 @@
1
+ class TestChildModel < ActiveRecord::Base
2
+ belongs_to :test_model
3
+ end
@@ -0,0 +1,3 @@
1
+ class TestModel < ActiveRecord::Base
2
+ has_many :test_child_models, dependent: :destroy
3
+ end
@@ -7,9 +7,6 @@ require "action_mailer/railtie"
7
7
  require "sprockets/railtie"
8
8
  # require "rails/test_unit/railtie"
9
9
 
10
- Bundler.require(*Rails.groups)
11
- require "a_r_q_logger"
12
-
13
10
  module Dummy
14
11
  class Application < Rails::Application
15
12
  config.generators do |g|
@@ -0,0 +1,9 @@
1
+ class CreateTestModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :test_models do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateTestChildModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :test_child_models do |t|
4
+ t.integer :test_model_id
5
+ t.string :name
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -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.5
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