a_r_q_logger 0.0.6 → 0.0.7

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +53 -102
  3. data/README.md +75 -0
  4. data/a_r_q_logger.gemspec +3 -3
  5. data/lib/a_r_q_logger.rb +14 -5
  6. data/lib/a_r_q_logger/initializer.rb +4 -0
  7. data/lib/a_r_q_logger/version.rb +1 -1
  8. data/spec/{dummy/app/models → models}/test_child_model.rb +0 -0
  9. data/spec/{dummy/app/models → models}/test_model.rb +0 -0
  10. data/spec/supports/schema.rb +56 -0
  11. data/spec/test_model_spec.rb +73 -0
  12. metadata +26 -68
  13. data/spec/dummy/README.rdoc +0 -28
  14. data/spec/dummy/Rakefile +0 -6
  15. data/spec/dummy/app/assets/images/.keep +0 -0
  16. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  17. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  18. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  19. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  20. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  21. data/spec/dummy/app/mailers/.keep +0 -0
  22. data/spec/dummy/app/models/.keep +0 -0
  23. data/spec/dummy/app/models/concerns/.keep +0 -0
  24. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  25. data/spec/dummy/bin/bundle +0 -3
  26. data/spec/dummy/bin/rails +0 -4
  27. data/spec/dummy/bin/rake +0 -4
  28. data/spec/dummy/config.ru +0 -4
  29. data/spec/dummy/config/application.rb +0 -35
  30. data/spec/dummy/config/boot.rb +0 -5
  31. data/spec/dummy/config/database.def.yml +0 -25
  32. data/spec/dummy/config/environment.rb +0 -5
  33. data/spec/dummy/config/environments/development.rb +0 -29
  34. data/spec/dummy/config/environments/production.rb +0 -80
  35. data/spec/dummy/config/environments/test.rb +0 -36
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  37. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  38. data/spec/dummy/config/initializers/inflections.rb +0 -16
  39. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  40. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  41. data/spec/dummy/config/initializers/session_store.rb +0 -3
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  43. data/spec/dummy/config/locales/en.yml +0 -23
  44. data/spec/dummy/config/routes.rb +0 -56
  45. data/spec/dummy/db/migrate/20161016035357_create_test_models.rb +0 -9
  46. data/spec/dummy/db/migrate/20161016035434_create_test_child_models.rb +0 -10
  47. data/spec/dummy/db/schema.rb +0 -28
  48. data/spec/dummy/lib/assets/.keep +0 -0
  49. data/spec/dummy/log/.keep +0 -0
  50. data/spec/dummy/public/404.html +0 -58
  51. data/spec/dummy/public/422.html +0 -58
  52. data/spec/dummy/public/500.html +0 -57
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/spec/models/test_model_spec.rb +0 -45
  55. data/spec/rails_helper.rb +0 -67
  56. data/spec/spec_helper.rb +0 -101
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9a251d9cfd3b33fcb329117f9ff040cee2ccad1
4
- data.tar.gz: c4cfe26cbe924a0b3e0ec25f6c7e7afe80cdb699
3
+ metadata.gz: 587c44cd5557b786a6ca947c6298151549e5e718
4
+ data.tar.gz: 7d45eae570b94a4696c4a31b3a29c44de749d434
5
5
  SHA512:
6
- metadata.gz: 7f1e088ddf44627932e295bf012762e71b02eae9c071b67473e5d20bdea464184d359484cf4eadbc369df92ed918a1ef3edff8432b5d875c4cb00cd51e1cab0b
7
- data.tar.gz: 0709b43bc47bea5ec2c68fdffa7dc817417353e8c6de64fedb2db8060af3b91095f11bf348bc9c0af1c0ca4fdc6cdd7175e8286ec3d6e627dc41a2027b16fdb0
6
+ metadata.gz: 4030ec645bb89b1ce33d492f552121218a49bb40a5144c0270567e978e2f1c35ef0c5aea2b3f451abc44c00beecac3828f47d89b442e9e4b42050e2fcd56a8b3
7
+ data.tar.gz: 40bec1f18818cfaea50ceaf6c821d6bc08bb1725088bd32fa862072c92d5a03d8ae83ff441ab2fbd8d89754bc21196de5bb55cf91b2253fc1bedda66473a8f2f
data/Gemfile.lock CHANGED
@@ -1,111 +1,81 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- a_r_q_logger (0.0.5)
5
- rails (>= 4.0)
4
+ a_r_q_logger (0.0.6)
5
+ activerecord (>= 4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
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)
18
- mail (~> 2.5, >= 2.5.4)
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)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.0.0.1)
28
- activesupport (= 5.0.0.1)
10
+ actionpack (4.2.0)
11
+ actionview (= 4.2.0)
12
+ activesupport (= 4.2.0)
13
+ rack (~> 1.6.0)
14
+ rack-test (~> 0.6.2)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
17
+ actionview (4.2.0)
18
+ activesupport (= 4.2.0)
29
19
  builder (~> 3.1)
30
20
  erubis (~> 2.7.0)
31
- rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
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)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ activemodel (4.2.0)
24
+ activesupport (= 4.2.0)
25
+ builder (~> 3.1)
26
+ activerecord (4.2.0)
27
+ activemodel (= 4.2.0)
28
+ activesupport (= 4.2.0)
29
+ arel (~> 6.0)
30
+ activesupport (4.2.0)
44
31
  i18n (~> 0.7)
32
+ json (~> 1.7, >= 1.7.7)
45
33
  minitest (~> 5.1)
34
+ thread_safe (~> 0.3, >= 0.3.4)
46
35
  tzinfo (~> 1.1)
47
- arel (7.1.3)
48
- builder (3.2.2)
49
- concurrent-ruby (1.0.2)
50
- coveralls (0.8.15)
36
+ arel (6.0.4)
37
+ builder (3.2.3)
38
+ coveralls (0.8.19)
51
39
  json (>= 1.8, < 3)
52
40
  simplecov (~> 0.12.0)
53
41
  term-ansicolor (~> 1.3)
54
42
  thor (~> 0.19.1)
55
- tins (>= 1.6.0, < 2)
56
- diff-lcs (1.2.5)
43
+ tins (~> 1.6)
44
+ diff-lcs (1.3)
57
45
  docile (1.1.5)
58
46
  erubis (2.7.0)
59
- factory_girl (4.7.0)
47
+ factory_girl (4.8.0)
60
48
  activesupport (>= 3.0.0)
61
- factory_girl_rails (4.7.0)
62
- factory_girl (~> 4.7.0)
49
+ factory_girl_rails (4.8.0)
50
+ factory_girl (~> 4.8.0)
63
51
  railties (>= 3.0.0)
64
- globalid (0.3.7)
65
- activesupport (>= 4.1.0)
66
- i18n (0.7.0)
67
- json (2.0.2)
52
+ i18n (0.8.0)
53
+ json (1.8.6)
68
54
  loofah (2.0.3)
69
55
  nokogiri (>= 1.5.9)
70
- mail (2.6.4)
71
- mime-types (>= 1.16, < 4)
72
- method_source (0.8.2)
73
- mime-types (3.1)
74
- mime-types-data (~> 3.2015)
75
- mime-types-data (3.2016.0521)
76
56
  mini_portile2 (2.1.0)
77
- minitest (5.9.1)
78
- nio4r (1.2.1)
79
- nokogiri (1.6.8.1)
57
+ minitest (5.10.1)
58
+ mysql (2.9.1)
59
+ nokogiri (1.7.0.1)
80
60
  mini_portile2 (~> 2.1.0)
81
- rack (2.0.1)
61
+ rack (1.6.5)
82
62
  rack-test (0.6.3)
83
63
  rack (>= 1.0)
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)
93
- bundler (>= 1.3.0, < 2.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)
98
- nokogiri (~> 1.6.0)
64
+ rails-deprecated_sanitizer (1.0.3)
65
+ activesupport (>= 4.2.0.alpha)
66
+ rails-dom-testing (1.0.8)
67
+ activesupport (>= 4.2.0.beta, < 5.0)
68
+ nokogiri (~> 1.6)
69
+ rails-deprecated_sanitizer (>= 1.0.1)
99
70
  rails-html-sanitizer (1.0.3)
100
71
  loofah (~> 2.0)
101
- railties (5.0.0.1)
102
- actionpack (= 5.0.0.1)
103
- activesupport (= 5.0.0.1)
104
- method_source
72
+ railties (4.2.0)
73
+ actionpack (= 4.2.0)
74
+ activesupport (= 4.2.0)
105
75
  rake (>= 0.8.7)
106
76
  thor (>= 0.18.1, < 2.0)
107
77
  rake (10.5.0)
108
- rb-readline (0.5.3)
78
+ rb-readline (0.5.4)
109
79
  rspec (3.5.0)
110
80
  rspec-core (~> 3.5.0)
111
81
  rspec-expectations (~> 3.5.0)
@@ -115,59 +85,40 @@ GEM
115
85
  rspec-expectations (3.5.0)
116
86
  diff-lcs (>= 1.2.0, < 2.0)
117
87
  rspec-support (~> 3.5.0)
118
- rspec-html-matchers (0.8.1)
88
+ rspec-html-matchers (0.9.1)
119
89
  nokogiri (~> 1)
120
90
  rspec (>= 3.0.0.a, < 4)
121
91
  rspec-mocks (3.5.0)
122
92
  diff-lcs (>= 1.2.0, < 2.0)
123
93
  rspec-support (~> 3.5.0)
124
- rspec-rails (3.5.2)
125
- actionpack (>= 3.0)
126
- activesupport (>= 3.0)
127
- railties (>= 3.0)
128
- rspec-core (~> 3.5.0)
129
- rspec-expectations (~> 3.5.0)
130
- rspec-mocks (~> 3.5.0)
131
- rspec-support (~> 3.5.0)
132
94
  rspec-support (3.5.0)
133
95
  simplecov (0.12.0)
134
96
  docile (~> 1.1.0)
135
97
  json (>= 1.8, < 3)
136
98
  simplecov-html (~> 0.10.0)
137
99
  simplecov-html (0.10.0)
138
- sprockets (3.7.0)
139
- concurrent-ruby (~> 1.0)
140
- rack (> 1, < 3)
141
- sprockets-rails (3.2.0)
142
- actionpack (>= 4.0)
143
- activesupport (>= 4.0)
144
- sprockets (>= 3.0.0)
145
- sqlite3 (1.3.12)
146
100
  term-ansicolor (1.4.0)
147
101
  tins (~> 1.0)
148
- thor (0.19.1)
102
+ thor (0.19.4)
149
103
  thread_safe (0.3.5)
150
- tins (1.12.0)
104
+ tins (1.13.2)
151
105
  tzinfo (1.2.2)
152
106
  thread_safe (~> 0.1)
153
- websocket-driver (0.6.4)
154
- websocket-extensions (>= 0.1.0)
155
- websocket-extensions (0.1.2)
156
107
 
157
108
  PLATFORMS
158
109
  ruby
159
110
 
160
111
  DEPENDENCIES
161
112
  a_r_q_logger!
113
+ activerecord (= 4.2)
162
114
  bundler (~> 1.10)
163
115
  coveralls
164
116
  factory_girl_rails
117
+ mysql
165
118
  rake (~> 10.0)
166
119
  rb-readline
167
120
  rspec
168
121
  rspec-html-matchers
169
- rspec-rails
170
- sqlite3
171
122
 
172
123
  BUNDLED WITH
173
- 1.11.2
124
+ 1.13.7
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # ARQLogger
2
+
3
+ This is ActiveRecord Query Logger.
4
+
5
+ This gem logs count of query and duration of only querying.
6
+
7
+ # Installation
8
+
9
+ ```
10
+ gem 'a_r_q_logger'
11
+ ```
12
+
13
+ or
14
+
15
+ ```
16
+ gem 'a_r_q_logger', require: false
17
+
18
+ require 'a_r_q_logger'
19
+ ```
20
+
21
+ # Usage
22
+
23
+ ## In tests
24
+
25
+ ## count queries
26
+
27
+ ```
28
+ before :all do
29
+ 10.times {
30
+ TestChildModel.create!(test_model: TestModel.create!, name: SecureRandom.hex(4))
31
+ }
32
+ end
33
+
34
+ it do
35
+ expect(ARQLogger.log {
36
+ TestModel.includes(:test_child_models).all.each { |m| m.test_child_models.map(&:name) }
37
+ }.count).to eq(2)
38
+ end
39
+
40
+ it do
41
+ expect(ARQLogger.log {
42
+ TestModel.all.each { |m| m.test_child_models.map(&:name) }
43
+ }.count).to eq(11)
44
+ end
45
+ ```
46
+
47
+ ## count instantiating
48
+
49
+ ```
50
+ before :all do
51
+ 10.times {
52
+ TestChildModel.create!(test_model: TestModel.create!, name: SecureRandom.hex(4))
53
+ }
54
+ end
55
+
56
+ it do
57
+ expect(ARQLogger.log {
58
+ TestModel.includes(:test_child_models).load
59
+ }.instances).to eq(20)
60
+ end
61
+
62
+ it do
63
+ expect(ARQLogger.log {
64
+ TestModel.joins(:test_child_models).select('test_child_models.id as as_id').load
65
+ }.instances).to eq(10)
66
+ end
67
+ ```
68
+
69
+
70
+ ## In Anywhere
71
+
72
+ ```
73
+ pry(main)> ARQLogger.log { 3.times { TestModel.has_children(10).map(&:children_count) } }
74
+ => #<struct ARQLogger::Result count=3, msec=1508.4>
75
+ ```
data/a_r_q_logger.gemspec CHANGED
@@ -17,13 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
- spec.add_dependency "rails", ">= 4.0"
20
+ spec.add_dependency "activerecord", ">= 4.2"
21
21
 
22
+ spec.add_development_dependency "activerecord", "4.2"
22
23
  spec.add_development_dependency "bundler", "~> 1.10"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "sqlite3"
25
+ spec.add_development_dependency "mysql"
25
26
  spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "rspec-rails"
27
27
  spec.add_development_dependency "rspec-html-matchers"
28
28
  spec.add_development_dependency "factory_girl_rails"
29
29
  spec.add_development_dependency "coveralls"
data/lib/a_r_q_logger.rb CHANGED
@@ -2,7 +2,7 @@ require 'a_r_q_logger/initializer'
2
2
 
3
3
  module ARQLogger
4
4
  class << self
5
- attr_accessor :store
5
+ attr_accessor :store, :instantiating
6
6
 
7
7
  def pass(event)
8
8
  return unless store
@@ -13,6 +13,10 @@ module ARQLogger
13
13
  end
14
14
  end
15
15
 
16
+ def instantiate
17
+ self.instantiating += 1 if instantiating
18
+ end
19
+
16
20
  def log(&block)
17
21
  start
18
22
  block.call
@@ -23,22 +27,27 @@ module ARQLogger
23
27
 
24
28
  def start
25
29
  self.store = []
30
+ self.instantiating = 0
26
31
  end
27
32
 
28
33
  def finish
29
34
  logged = store
35
+ instances = instantiating
36
+
30
37
  self.store = nil
38
+ self.instantiating = nil
31
39
 
32
40
  Result.new(
33
41
  count: logged.size,
34
- msec: logged.sum.round(1)
42
+ msec: logged.sum.round(1),
43
+ instances: instances
35
44
  )
36
45
  end
37
46
  end
38
47
 
39
- class Result < Struct.new(:count, :msec)
40
- def initialize(count:, msec:)
41
- super(count, msec)
48
+ class Result < Struct.new(:count, :msec, :instances)
49
+ def initialize(count:, msec:, instances:)
50
+ super(count, msec, instances)
42
51
  end
43
52
  end
44
53
  end
@@ -10,6 +10,10 @@ module ARQLogger
10
10
  real_sql(event)
11
11
  end
12
12
  end
13
+
14
+ class ActiveRecord::Base
15
+ after_initialize ->{ ARQLogger.instantiate }
16
+ end
13
17
  EOS
14
18
  end
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module ARQLogger
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
File without changes
@@ -0,0 +1,56 @@
1
+ DATABASE_NAME = :a_r_q_logger_test_database
2
+ DATABASE_CONFIGURATION_BASE = {
3
+ adapter: :mysql2,
4
+ host: :localhost,
5
+ username: ENV['MYSQL_USER_NAME'],
6
+ password: ENV['MYSQL_USER_PASSWORD'],
7
+ }
8
+
9
+ class DummyCreator < ActiveRecord::Migration
10
+ class << self
11
+ def up
12
+ create_table "test_child_models", force: :cascade do |t|
13
+ t.integer "test_model_id"
14
+ t.string "name"
15
+ t.datetime "created_at", null: false
16
+ t.datetime "updated_at", null: false
17
+ end
18
+
19
+ create_table "test_models", force: :cascade do |t|
20
+ t.string "name"
21
+ t.datetime "created_at", null: false
22
+ t.datetime "updated_at", null: false
23
+ end
24
+ rescue
25
+ nil
26
+ end
27
+
28
+ def down
29
+ drop_table(:test_child_models)
30
+ drop_table(:test_models)
31
+ rescue
32
+ nil
33
+ end
34
+ end
35
+ end
36
+
37
+ RSpec.configure do |config|
38
+ config.before :suite do
39
+ ActiveRecord::Base.establish_connection(DATABASE_CONFIGURATION_BASE)
40
+ begin
41
+ ActiveRecord::Base.connection.create_database(DATABASE_NAME)
42
+ rescue ActiveRecord::StatementInvalid => e
43
+ # yay
44
+ end
45
+
46
+ ActiveRecord::Base.establish_connection(DATABASE_CONFIGURATION_BASE.merge(
47
+ database: DATABASE_NAME,
48
+ ))
49
+
50
+ DummyCreator.up rescue nil
51
+ end
52
+
53
+ config.after :suite do
54
+ DummyCreator.down
55
+ end
56
+ end