spring_onion 0.2.2 → 1.0.1

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
  SHA256:
3
- metadata.gz: 54ea2a17b7ab30f6e646ed61b125dcc22e82cf304c946d26c70222a6e5a78341
4
- data.tar.gz: af308c44d05e7b58048e5c29bd8f708a14d7067111210338ec52296ae9e00f16
3
+ metadata.gz: adf8950ce1f2d7c9c7d7c0d41d3472a833d37a046b9aa31848257a879c261c38
4
+ data.tar.gz: 23f8d10722ac30ce2a7c0c01236001ecde43c31ec47c81ad2fe0225495282252
5
5
  SHA512:
6
- metadata.gz: 1d5fcd164189c1a47126b009f0d058baffc306958cb2dcbd3bbf8e0f0bd4d54f49b9f862204b0d46bb4f68e44cd24257a2f62dced99f93b900d620f7871f2cc4
7
- data.tar.gz: 0cae3be0dc5e774d092b3e2624bc943604dc8a0aac30dadf645a86f736f13f80978d0ec5a4a5bf595c7eff150f047f79a95769ab9d344bc15917d2ca4dd9b0c1
6
+ metadata.gz: 4508747cc4ba4b0f4b2bea885b14877e6f7128afad83d0731cbe87b4160159acf13f39e8872d41c9c49328df80e92026900cde9280f8979de03d979a1d7d168e
7
+ data.tar.gz: 1a6634398984d1c7d317ed9685f9df6beca9c1377d564f90c70904aa646c90ef7d9b80586b79ff65d73253b327d1b711fdd7b7639eee10087ba4c2aa35a9d969
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
 
13
13
  # Appraisal Gemfile.lock
14
14
  /gemfiles/*.lock
15
+
16
+ /test.rb
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
@@ -1,9 +1,12 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - "gemfiles/**/*"
4
+ - "test.rb"
4
5
  TargetRubyVersion: 2.5
5
6
  Style/Documentation:
6
7
  Enabled: false
8
+ Style/TrailingCommaInArrayLiteral:
9
+ EnforcedStyleForMultiline: consistent_comma
7
10
  Style/TrailingCommaInHashLiteral:
8
11
  EnforcedStyleForMultiline: consistent_comma
9
12
  Metrics/AbcSize:
@@ -12,6 +15,8 @@ Metrics/CyclomaticComplexity:
12
15
  Enabled: false
13
16
  Metrics/MethodLength:
14
17
  Enabled: false
18
+ Metrics/BlockLength:
19
+ Enabled: false
15
20
  Layout/LineLength:
16
21
  Enabled: false
17
22
 
@@ -2,5 +2,21 @@
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
+ - 2.5.8
5
6
  - 2.6.6
6
- before_install: gem install bundler -v 2.1.2
7
+ - 2.7.1
8
+ gemfile:
9
+ - gemfiles/ar52.gemfile
10
+ - gemfiles/ar60.gemfile
11
+ services:
12
+ - mysql
13
+ env:
14
+ - DATABASE_URL=mysql2://travis@localhost/sakila
15
+ before_install:
16
+ - gem install bundler -v 2.1.2
17
+ - curl -sSfL https://downloads.mysql.com/docs/sakila-db.tar.gz -o - | tar zxf -
18
+ - cd sakila-db
19
+ - mysql < sakila-schema.sql
20
+ - mysql < sakila-data.sql
21
+ script:
22
+ - bundle exec rake
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'ar52' do
4
+ gem 'activerecord', '~> 5.2.1'
5
+ end
6
+
7
+ appraise 'ar60' do
8
+ gem 'activerecord', '~> 5.2.1'
9
+ end
@@ -0,0 +1,14 @@
1
+ FROM rubylang/ruby:2.5-bionic
2
+
3
+ RUN apt-get update && \
4
+ apt-get install -y \
5
+ mysql-client \
6
+ libmysqlclient-dev \
7
+ rubygems \
8
+ curl
9
+
10
+ COPY ./ /mnt/
11
+ WORKDIR /mnt
12
+ RUN gem update bundler -f && \
13
+ bundle install && \
14
+ bundle exec appraisal install
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spring_onion (0.2.2)
4
+ spring_onion (1.0.1)
5
5
  activerecord
6
6
  coderay
7
7
  mysql2
@@ -83,4 +83,4 @@ DEPENDENCIES
83
83
  spring_onion!
84
84
 
85
85
  BUNDLED WITH
86
- 2.1.2
86
+ 2.1.4
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # SpringOnion
2
2
 
3
3
  Log MySQL queries with EXPLAIN that may be slow.
4
+
4
5
  Inspired by [MySQLCasualLog.pm](https://gist.github.com/kamipo/839e8a5b6d12bddba539).
5
6
 
7
+ [![Build Status](https://travis-ci.org/winebarrel/spring_onion.svg?branch=master)](https://travis-ci.org/winebarrel/spring_onion)
8
+
6
9
  ## Installation
7
10
 
8
11
  Add this line to your application's Gemfile:
@@ -25,12 +28,11 @@ Or install it yourself as:
25
28
  #!/usr/bin/env ruby
26
29
  require 'active_record'
27
30
  require 'spring_onion'
28
- require 'logger'
29
31
 
30
32
  ActiveRecord::Base.establish_connection(
31
33
  adapter: 'mysql2',
32
34
  username: 'root',
33
- database: 'employees',
35
+ database: 'employees'
34
36
  )
35
37
 
36
38
  SpringOnion.enabled = true # or `SPRING_ONION_ENABLED=1`
@@ -75,3 +77,10 @@ p Employee.all.to_a.count
75
77
  ]
76
78
  }
77
79
  ```
80
+
81
+ ## Test
82
+
83
+ ```sh
84
+ docker-compose build
85
+ docker-compose run client bundle exec appraisal ar60 rake
86
+ ```
data/Rakefile CHANGED
@@ -2,7 +2,12 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
8
- task default: :spec
9
+ RuboCop::RakeTask.new do |task|
10
+ task.options = %w[-c .rubocop.yml]
11
+ end
12
+
13
+ task default: %i[rubocop spec]
@@ -0,0 +1,15 @@
1
+ version: "3.8"
2
+ services:
3
+ client:
4
+ build: .
5
+ environment:
6
+ MYSQL_PING_ATTEMPTS: "10"
7
+ DATABASE_URL: mysql2://root@db/sakila
8
+ volumes:
9
+ - ./:/mnt
10
+ depends_on:
11
+ - db
12
+ db:
13
+ image: budougumi0617/mysql-sakila:5.7
14
+ environment:
15
+ MYSQL_ALLOW_EMPTY_PASSWORD: "1"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 5.2.1"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 5.2.1"
8
+
9
+ gemspec path: "../"
@@ -28,13 +28,13 @@ module SpringOnion
28
28
  @enabled = (/\A(1|true)\z/i =~ ENV['SPRING_ONION_ENABLED'])
29
29
 
30
30
  @sql_filter_re = ENV['SPRING_ONION_SQL_FILTER_RE'].yield_self do |re|
31
- re ? Regexp.new(re) : //
31
+ re ? Regexp.new(re, Regexp::IGNORECASE) : //
32
32
  end
33
33
 
34
34
  @ignore_sql_filter_re = Regexp.union(
35
35
  [/\binformation_schema\b/].tap do |ary|
36
36
  re = ENV['SPRING_ONION_IGNORE_SQL_FILTER_RE']
37
- ary << Regexp.new(re) if re
37
+ ary << Regexp.new(re, Regexp::IGNORECASE) if re
38
38
  end
39
39
  )
40
40
 
@@ -3,14 +3,16 @@
3
3
  module SpringOnion
4
4
  module Explainer
5
5
  def execute(*args)
6
- _with_explain(args.first) do
6
+ _with_explain(sql: args.first) do
7
7
  super
8
8
  end
9
9
  end
10
10
 
11
- def _with_explain(sql)
11
+ private
12
+
13
+ def _with_explain(sql:)
12
14
  begin
13
- if SpringOnion.enabled && sql =~ /^SELECT\b/ && SpringOnion.sql_filter.call(sql)
15
+ if SpringOnion.enabled && sql =~ /\A\s*SELECT\b/i && SpringOnion.sql_filter.call(sql)
14
16
  trace = SpringOnion.source_filter.call(caller)
15
17
 
16
18
  unless trace.length.zero?
@@ -19,9 +21,11 @@ module SpringOnion
19
21
 
20
22
  exp = conn.query("EXPLAIN #{sql}", as: :hash).to_a
21
23
  exp.each { |r| r.delete('id') }
22
- _validate_explain(exp, sql, trace)
24
+ _validate_explain(sql: sql, exp: exp, trace: trace)
23
25
  end
24
26
  end
27
+ rescue SpringOnion::Error
28
+ raise
25
29
  rescue StandardError => e
26
30
  SpringOnion.logger.error(e)
27
31
  end
@@ -29,7 +33,7 @@ module SpringOnion
29
33
  yield
30
34
  end
31
35
 
32
- def _validate_explain(exp, sql, trace)
36
+ def _validate_explain(sql:, exp:, trace:)
33
37
  warnings = SpringOnion.warnings
34
38
  warning_names_by_index = {}
35
39
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpringOnion
4
- VERSION = '0.2.2'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring_onion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-18 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -133,11 +133,16 @@ files:
133
133
  - ".rspec"
134
134
  - ".rubocop.yml"
135
135
  - ".travis.yml"
136
+ - Appraisals
137
+ - Dockerfile
136
138
  - Gemfile
137
139
  - Gemfile.lock
138
140
  - LICENSE.txt
139
141
  - README.md
140
142
  - Rakefile
143
+ - docker-compose.yml
144
+ - gemfiles/ar52.gemfile
145
+ - gemfiles/ar60.gemfile
141
146
  - lib/spring_onion.rb
142
147
  - lib/spring_onion/config.rb
143
148
  - lib/spring_onion/error.rb