pg-eyeballs 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8318a41826d020850ea248b42562f98495e7b319
4
- data.tar.gz: cb5b794673a55abde012a232b2d21660c58f2b73
3
+ metadata.gz: 3ecb0ed349340e392cd51a2d08f8a3fb406718ee
4
+ data.tar.gz: d88af55b891ed2700cadaac3e952f1fcbb9db2c4
5
5
  SHA512:
6
- metadata.gz: 421cc9c3588a38bfc9c9d0ac05c43e068012f407cb9eca5d03fae6e17e8635f7cfe57daed87509efd632586ef37632bd050cff69be93550faef7c6fd57a67d59
7
- data.tar.gz: b668d16c03dc16e7d5f7b1b6f3ccb97f9b64c5c4c4c7166785025bbe2858465bb6a398f8195c700353c32f31c0c992a88789643ea5c124cbfcdb792037307af0
6
+ metadata.gz: fe3eb5223f725effb48c363429741ae5c4e9722067c8871b2eefb0acaa338f133b1d8d15ef2e81395ed3541e827f0d4305cd82a9b0d5d70a5cb15b4473f936b3
7
+ data.tar.gz: 49d459f9e8b2de48050bb791a03223ba619172dde4484c04b934272f10081caae16347aa1ad1fc88487b6488efdcb871f12e2485f975b323ae546f4c42033727
@@ -0,0 +1,7 @@
1
+ appraise "activerecord-4" do
2
+ gem "activerecord", ">= 4.0.0", "< 5.0.0"
3
+ end
4
+
5
+ appraise "activerecord-5" do
6
+ gem "activerecord", ">= 5.0.0", "< 6.0.0"
7
+ end
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'pry'
4
4
  gem 'pry-byebug'
5
5
  gem 'awesome_print'
6
+ gem 'appraisal'
6
7
 
7
8
  # Specify your gem's dependencies in pg-eyeballs.gemspec
8
9
  gemspec
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  `pg-eyeballs` is a ruby gem that gives you detailed information about how the
5
5
  SQL queries created by the active record code you write are executed by the database.
6
6
  It gives you an easy, ruby friendly way to see the output of the Postgres
7
- [`EXPLAIN` command](https://www.postgresql.org/docs/9.4/static/using-explain.html) and integrates with the popular query analysis tool [`gocmdpev`](https://github.com/simon-engledew/gocmdpev).
7
+ [`EXPLAIN` command](https://www.postgresql.org/docs/9.4/static/using-explain.html) and integrates with the popular query analysis tool [`gocmdpev`](https://github.com/simon-engledew/gocmdpev).
8
8
 
9
9
  Using it you can see:
10
10
  - What queries were run
@@ -48,7 +48,7 @@ more than one query, for instance when it has a `preload` or with certain
48
48
  subqueries
49
49
  ```ruby
50
50
  User.all.preload(:profiles).eyeballs.explain(options: [:verbose], format: :yaml)
51
- ['- Plan:
51
+ ['- Plan:
52
52
  Node Type: "Seq Scan"
53
53
  Relation Name: "users"
54
54
  Schema: "public"
@@ -57,10 +57,10 @@ User.all.preload(:profiles).eyeballs.explain(options: [:verbose], format: :yaml)
57
57
  Total Cost: 22.30
58
58
  Plan Rows: 1230
59
59
  Plan Width: 36
60
- Output:
60
+ Output:
61
61
  - "id"
62
- - "email"',
63
- '- Plan:
62
+ - "email"',
63
+ '- Plan:
64
64
  Node Type: "Seq Scan"
65
65
  Relation Name: "profiles"
66
66
  Schema: "public"
@@ -69,7 +69,7 @@ User.all.preload(:profiles).eyeballs.explain(options: [:verbose], format: :yaml)
69
69
  Total Cost: 36.75
70
70
  Plan Rows: 11
71
71
  Plan Width: 8
72
- Output:
72
+ Output:
73
73
  - "id"
74
74
  - "user_id"
75
75
  Filter: "(profiles.user_id = 1)"'
@@ -179,6 +179,11 @@ To use, also from inside your Rails project directory, run
179
179
  eyeballs User.preload(:profiles)
180
180
  ```
181
181
 
182
+ ## Compatibility
183
+
184
+ `pg-eyeballs` has been tested with Rails versions 4 and 5. It may work on
185
+ earlier versions, but I haven't tried it.
186
+
182
187
  ## Development
183
188
 
184
189
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -189,8 +194,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
189
194
 
190
195
  Bug reports and pull requests are welcome on GitHub at https://github.com/bradurani/pg-eyeballs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
191
196
 
197
+ ### Running the tests
198
+
199
+ First, `bundle install`. After this, if you are using the default
200
+ database, first thing is to run `createdb eyeballs_test`. After this
201
+ you can run the tests with `rake`.
202
+
192
203
 
193
204
  ## License
194
205
 
195
206
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
196
-
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "pry-byebug"
7
+ gem "awesome_print"
8
+ gem "appraisal"
9
+ gem "activerecord", ">= 4.0.0", "<= 5.0.0"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ pg-eyeballs (1.0.1)
5
+ activerecord (>= 4.0, < 6.0)
6
+ pg
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.2.7.1)
12
+ activesupport (= 4.2.7.1)
13
+ builder (~> 3.1)
14
+ activerecord (4.2.7.1)
15
+ activemodel (= 4.2.7.1)
16
+ activesupport (= 4.2.7.1)
17
+ arel (~> 6.0)
18
+ activesupport (4.2.7.1)
19
+ i18n (~> 0.7)
20
+ json (~> 1.7, >= 1.7.7)
21
+ minitest (~> 5.1)
22
+ thread_safe (~> 0.3, >= 0.3.4)
23
+ tzinfo (~> 1.1)
24
+ appraisal (2.1.0)
25
+ bundler
26
+ rake
27
+ thor (>= 0.14.0)
28
+ arel (6.0.3)
29
+ awesome_print (1.7.0)
30
+ builder (3.2.2)
31
+ byebug (9.0.6)
32
+ coderay (1.1.1)
33
+ database_cleaner (1.5.3)
34
+ diff-lcs (1.2.5)
35
+ i18n (0.7.0)
36
+ json (1.8.3)
37
+ method_source (0.8.2)
38
+ minitest (5.9.1)
39
+ pg (0.19.0)
40
+ pry (0.10.4)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ pry-byebug (3.4.0)
45
+ byebug (~> 9.0)
46
+ pry (~> 0.10)
47
+ rake (10.5.0)
48
+ rspec (3.5.0)
49
+ rspec-core (~> 3.5.0)
50
+ rspec-expectations (~> 3.5.0)
51
+ rspec-mocks (~> 3.5.0)
52
+ rspec-core (3.5.4)
53
+ rspec-support (~> 3.5.0)
54
+ rspec-expectations (3.5.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.5.0)
57
+ rspec-mocks (3.5.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.5.0)
60
+ rspec-support (3.5.0)
61
+ slop (3.6.0)
62
+ thor (0.19.1)
63
+ thread_safe (0.3.5)
64
+ tzinfo (1.2.2)
65
+ thread_safe (~> 0.1)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ activerecord (>= 4.0.0, <= 5.0.0)
72
+ appraisal
73
+ awesome_print
74
+ bundler (~> 1.12)
75
+ database_cleaner
76
+ pg-eyeballs!
77
+ pry
78
+ pry-byebug
79
+ rake (~> 10.0)
80
+ rspec (~> 3.0)
81
+
82
+ BUNDLED WITH
83
+ 1.13.2
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "pry-byebug"
7
+ gem "awesome_print"
8
+ gem "appraisal"
9
+ gem "activerecord", ">= 5.0.0", "<=6.0.0"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ pg-eyeballs (1.0.1)
5
+ activerecord (>= 4.0, < 6.0)
6
+ pg
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.0.0.1)
12
+ activesupport (= 5.0.0.1)
13
+ activerecord (5.0.0.1)
14
+ activemodel (= 5.0.0.1)
15
+ activesupport (= 5.0.0.1)
16
+ arel (~> 7.0)
17
+ activesupport (5.0.0.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (~> 0.7)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ appraisal (2.1.0)
23
+ bundler
24
+ rake
25
+ thor (>= 0.14.0)
26
+ arel (7.1.2)
27
+ awesome_print (1.7.0)
28
+ byebug (9.0.6)
29
+ coderay (1.1.1)
30
+ concurrent-ruby (1.0.2)
31
+ database_cleaner (1.5.3)
32
+ diff-lcs (1.2.5)
33
+ i18n (0.7.0)
34
+ method_source (0.8.2)
35
+ minitest (5.9.1)
36
+ pg (0.19.0)
37
+ pry (0.10.4)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.8.1)
40
+ slop (~> 3.4)
41
+ pry-byebug (3.4.0)
42
+ byebug (~> 9.0)
43
+ pry (~> 0.10)
44
+ rake (10.5.0)
45
+ rspec (3.5.0)
46
+ rspec-core (~> 3.5.0)
47
+ rspec-expectations (~> 3.5.0)
48
+ rspec-mocks (~> 3.5.0)
49
+ rspec-core (3.5.4)
50
+ rspec-support (~> 3.5.0)
51
+ rspec-expectations (3.5.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.5.0)
54
+ rspec-mocks (3.5.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.5.0)
57
+ rspec-support (3.5.0)
58
+ slop (3.6.0)
59
+ thor (0.19.1)
60
+ thread_safe (0.3.5)
61
+ tzinfo (1.2.2)
62
+ thread_safe (~> 0.1)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activerecord (>= 5.0.0, <= 6.0.0)
69
+ appraisal
70
+ awesome_print
71
+ bundler (~> 1.12)
72
+ database_cleaner
73
+ pg-eyeballs!
74
+ pry
75
+ pry-byebug
76
+ rake (~> 10.0)
77
+ rspec (~> 3.0)
78
+
79
+ BUNDLED WITH
80
+ 1.13.2
@@ -23,9 +23,9 @@ module Eyeballs
23
23
  end
24
24
 
25
25
  def queries
26
- @queries ||= query_array.map do |query_binding|
27
- build_sql(query_binding)
28
- end
26
+ @relation.connection.to_sql(query_array).map { |query|
27
+ build_sql(query)
28
+ }
29
29
  end
30
30
 
31
31
  def to_s(options: OPTIONS)
@@ -53,7 +53,7 @@ module Eyeballs
53
53
  to_hash_array.each do |h|
54
54
  system("echo '#{h.to_json}' | gocmdpev")
55
55
  end
56
- nil
56
+ nil
57
57
  end
58
58
 
59
59
  private
@@ -66,20 +66,20 @@ module Eyeballs
66
66
 
67
67
  def validate_format!(format)
68
68
  unless FORMATS.include?(format)
69
- raise Eyeballs::UnknownFormatError, "Unknown Format #{format}"
69
+ raise Eyeballs::UnknownFormatError, "Unknown Format #{format}"
70
70
  end
71
71
  end
72
72
 
73
73
  def validate_options!(options)
74
74
  options.each do |option|
75
75
  unless OPTIONS.include?(option)
76
- raise Eyeballs::UnknownOptionError, "Unknown Option #{option}"
76
+ raise Eyeballs::UnknownOptionError, "Unknown Option #{option}"
77
77
  end
78
78
  end
79
79
  end
80
80
 
81
81
  def explain_query(query, format, options)
82
- "EXPLAIN (#{explain_options(format, options)}) #{query}"
82
+ "EXPLAIN (#{explain_options(format, options)}) #{query}"
83
83
  end
84
84
 
85
85
  def explain_options(format, options)
@@ -91,15 +91,18 @@ module Eyeballs
91
91
  end
92
92
 
93
93
  def build_sql(query_binding)
94
- sql = query_binding[0]
95
- values = query_binding[1].map do |b|
96
- cast_type = b[0].cast_type
97
- cast_value = cast_type.type_cast_for_database(b[1])
98
- quoted_value = @relation.connection.quote(cast_value)
94
+ query_binding[1].each.with_index.reduce(query_binding[0]) do |sql,(value, index)|
95
+ sql.sub("$#{index + 1}", @relation.connection.quote(extract_value(value)))
99
96
  end
100
- values.each.with_index.reduce(sql) do |sql,(value, index)|
101
- sql.sub("$#{index + 1}", value.to_s)
97
+ end
98
+
99
+ def extract_value(value)
100
+ if value.is_a?(Array) #Rails 4
101
+ value.last
102
+ elsif value.is_a?(ActiveRecord::Relation::QueryAttribute) #Rails 5
103
+ value.value
102
104
  end
103
105
  end
106
+
104
107
  end
105
108
  end
@@ -1,3 +1,3 @@
1
1
  module Eyeballs
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "rspec", "~> 3.0"
33
33
  spec.add_development_dependency "database_cleaner"
34
34
 
35
- spec.add_dependency "activerecord", ">=4.0", "<5.0"
35
+ spec.add_dependency "activerecord", ">=4.0", "<6.0"
36
36
  spec.add_dependency "pg"
37
37
 
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg-eyeballs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Urani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: '4.0'
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
- version: '5.0'
78
+ version: '6.0'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: '4.0'
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
- version: '5.0'
88
+ version: '6.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pg
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -113,6 +113,7 @@ files:
113
113
  - ".gitignore"
114
114
  - ".rspec"
115
115
  - ".travis.yml"
116
+ - Appraisals
116
117
  - CODE_OF_CONDUCT.md
117
118
  - Gemfile
118
119
  - LICENSE
@@ -122,6 +123,10 @@ files:
122
123
  - bin/gocmdpev
123
124
  - bin/setup
124
125
  - circle.yml
126
+ - gemfiles/activerecord_4.gemfile
127
+ - gemfiles/activerecord_4.gemfile.lock
128
+ - gemfiles/activerecord_5.gemfile
129
+ - gemfiles/activerecord_5.gemfile.lock
125
130
  - gocmdpev.png
126
131
  - lib/eyeballs/errors.rb
127
132
  - lib/eyeballs/includes.rb