spring_onion 0.1.2 → 0.1.3

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: 1a365d84922c1478abeb1ece890c64670ccbc148262362247d76f6b0d14e4fbe
4
- data.tar.gz: 9a121f4fd4e29c0f197abf019de3b83c32823f7dbfed4501a29d8a4d80da5463
3
+ metadata.gz: ce732c781280bd7df0bce88ccc8654d20efcf0d526fadeaa5ebcd263de43102d
4
+ data.tar.gz: 4d7b643b28a2afd962df5882bdef1d38ba4c12d00dc90ab8ce960d3b3f1f3e37
5
5
  SHA512:
6
- metadata.gz: 6ad8867bd4a3743844350ca26c6cf766283e5fb22ebe882b5fb807d016c18687339a26947408935bc582ea411307673da3c5fa3cb2ba9d28d7988e875fdabd2a
7
- data.tar.gz: 5a67f25e5e346f2b5f396ad366bade23dd03d695f487893daa21d167b52b66a89eabde482038aac80c4b612de0b32ac2a601f785da5ba75925038afa091cb5b9
6
+ metadata.gz: ea8d9b77ed18bd515b75bde75237cc3ab0384c7f9ea64ea3258cb73d66f22589e9320df6e557ac11a8496f8ec2d86a3fef15153c3a9b5eff789a08544be5b6e8
7
+ data.tar.gz: 75b6de58da35b12b310d30353203f679e930f79faca793c9ee7ec2007dd2d0db057a1cb2f80bbdb66f16a2621048bf15b5167a3a8693cfc2197abea1359c6f6c
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spring_onion (0.1.2)
4
+ spring_onion (0.1.3)
5
5
  activerecord
6
+ coderay
6
7
  mysql2
7
8
 
8
9
  GEM
@@ -24,6 +25,7 @@ GEM
24
25
  rake
25
26
  thor (>= 0.14.0)
26
27
  ast (2.4.1)
28
+ coderay (1.1.3)
27
29
  concurrent-ruby (1.1.6)
28
30
  diff-lcs (1.4.4)
29
31
  i18n (1.8.3)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'logger'
4
+ require 'coderay'
4
5
  require 'active_support'
5
6
 
6
7
  require 'spring_onion/config'
@@ -67,6 +67,8 @@ module SpringOnion
67
67
  end
68
68
 
69
69
  @trace_len = 3
70
+ @json_pretty = (/\A(1|true)\z/i =~ ENV['SPRING_ONION_JSON_PRETTY'])
71
+ @color = /\A(1|true)\z/i =~ ENV.fetch('SPRING_ONION_COLOR', $stdout.tty?.to_s)
70
72
 
71
73
  class << self
72
74
  attr_accessor :enabled,
@@ -75,6 +77,8 @@ module SpringOnion
75
77
  :sql_filter_re, :ignore_sql_filter_re, :sql_filter,
76
78
  :source_filter_re, :ignore_source_filter_re, :source_filter,
77
79
  :logger,
78
- :trace_len
80
+ :trace_len,
81
+ :json_pretty,
82
+ :color
79
83
  end
80
84
  end
@@ -43,12 +43,21 @@ module SpringOnion
43
43
 
44
44
  return if violation_names_by_line.empty?
45
45
 
46
- SpringOnion.logger.info({
46
+ h = {
47
47
  sql: sql,
48
48
  explain: exp.each_with_index.map { |r, i| { line: i + 1 }.merge(r) },
49
49
  violations: violation_names_by_line,
50
50
  backtrace: trace.slice(0, SpringOnion.trace_len),
51
- }.to_json)
51
+ }
52
+
53
+ line = if SpringOnion.json_pretty
54
+ JSON.pretty_generate(h)
55
+ else
56
+ JSON.dump(h)
57
+ end
58
+
59
+ line = CodeRay.scan(line, :json).terminal if SpringOnion.color
60
+ SpringOnion.logger.info(line)
52
61
  end
53
62
  end
54
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpringOnion
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.add_dependency 'activerecord'
27
+ spec.add_dependency 'coderay'
27
28
  spec.add_dependency 'mysql2'
28
29
  spec.add_development_dependency 'appraisal'
29
30
  spec.add_development_dependency 'bundler'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring_onion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coderay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mysql2
29
43
  requirement: !ruby/object:Gem::Requirement