dry-monitor 0.1.2 → 0.2.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
- SHA1:
3
- metadata.gz: ca2399eb8989f99e9840024b317599e731b2e357
4
- data.tar.gz: 01e127fab50b60edcc4ac61846907341fd826e23
2
+ SHA256:
3
+ metadata.gz: b939a7f5ab22ce4c3eccccbcd71346e42facb0f70f2cc047281721fdf681e234
4
+ data.tar.gz: 965e06b530acc58bf26b94595a345a04cc8a36c7b06851543e59b387da6ad06e
5
5
  SHA512:
6
- metadata.gz: 5175053c85e8ae01f9892a3e17fe3e2c54820379cfabde8624893ff35833d7aa9c34bc3c1bf741cab7be77fd519fd6c8bc825997934b58506a3769e63d3bc669
7
- data.tar.gz: f01dc548ac3b1f02f72d6b5c7ed875b3100e86af9d6168be33b6910c1170979675cd4634e393dc41c53bc404ec947d2e3c38a11b3ae6d0e132b91298d62900fb
6
+ metadata.gz: '09640a52032db43d45f511c7ddeab320d36174427c4414e013377d5c5091c569f195b187ea8db2228f5a27050ad6f553bdce7da2f8b43cf572f9adb80fdadf01'
7
+ data.tar.gz: d0074aa61334f545f291e99dcb7a1b9c311e8b3e25f49fa3e0f3bb230f0a8c2653660ab60a5f894e4e7a45c00c1c68644bf196062733cb08690b83a4ebf1da20
@@ -1,3 +1,9 @@
1
+ # v0.2.0 2018-01-21
2
+
3
+ ### Changed
4
+
5
+ * Make `rouge` an optional dependency (davydovanton & mensfeld)
6
+
1
7
  # v0.1.2 2018-01-04
2
8
 
3
9
  ### Fixed
@@ -15,11 +15,12 @@ Gem::Specification.new do |spec|
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ['lib']
17
17
 
18
- spec.add_runtime_dependency 'rouge', '~> 2.0', '>= 2.2.1'
19
18
  spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
20
19
  spec.add_runtime_dependency 'dry-configurable', '~> 0.5'
21
20
  spec.add_runtime_dependency 'dry-events', '~> 0.1'
21
+ spec.add_runtime_dependency 'dry-core', '~> 0.4'
22
22
 
23
+ spec.add_development_dependency 'rouge', '~> 2.0', '>= 2.2.1'
23
24
  spec.add_development_dependency 'bundler'
24
25
  spec.add_development_dependency 'rake'
25
26
  spec.add_development_dependency 'rspec'
@@ -3,15 +3,14 @@ require 'dry/events/publisher'
3
3
  module Dry
4
4
  module Monitor
5
5
  class Clock
6
- def measure(&block)
6
+ def measure
7
7
  start = current
8
- result = block.()
9
- stop = current
10
- [result, ((stop - start) * 1000).round(2)]
8
+ result = yield
9
+ [result, current - start]
11
10
  end
12
11
 
13
12
  def current
14
- Time.now
13
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
15
14
  end
16
15
  end
17
16
 
@@ -37,9 +36,9 @@ module Dry
37
36
  instrument(event_id, payload)
38
37
  end
39
38
 
40
- def instrument(event_id, payload = EMPTY_HASH, &block)
41
- if block
42
- result, time = clock.measure(&block)
39
+ def instrument(event_id, payload = EMPTY_HASH)
40
+ if block_given?
41
+ result, time = @clock.measure { yield }
43
42
  end
44
43
 
45
44
  process(event_id, payload) do |event, listener|
@@ -0,0 +1,16 @@
1
+ module Dry
2
+ module Monitor
3
+ module SQL
4
+ module Colorizers
5
+ class Default
6
+ def initialize(_theme)
7
+ end
8
+
9
+ def call(string)
10
+ string
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ require 'rouge/util'
2
+ require 'rouge/token'
3
+ require 'rouge/theme'
4
+ require 'rouge/themes/gruvbox'
5
+ require 'rouge/formatter'
6
+ require 'rouge/formatters/terminal256'
7
+ require 'rouge/lexer'
8
+ require 'rouge/regex_lexer'
9
+ require 'rouge/lexers/sql'
10
+
11
+ module Dry
12
+ module Monitor
13
+ module SQL
14
+ module Colorizers
15
+ class Rouge
16
+ attr_reader :formatter
17
+ attr_reader :lexer
18
+
19
+ def initialize(theme)
20
+ @formatter = ::Rouge::Formatters::Terminal256.new(theme || ::Rouge::Themes::Gruvbox.new)
21
+ @lexer = ::Rouge::Lexers::SQL.new
22
+ end
23
+
24
+ def call(string)
25
+ formatter.format(lexer.lex(string))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  require 'dry-configurable'
2
- require 'rouge'
2
+ require 'dry/core/extensions'
3
3
  require 'dry/monitor/notifications'
4
4
 
5
5
  module Dry
@@ -8,23 +8,37 @@ module Dry
8
8
 
9
9
  module SQL
10
10
  class Logger
11
+ extend Dry::Core::Extensions
11
12
  extend Dry::Configurable
12
13
 
13
- setting :theme, Rouge::Themes::Gruvbox.new
14
- setting :colorize, true
14
+ register_extension(:default_colorizer) do
15
+ require_relative './colorizers/default'
16
+
17
+ def colorizer
18
+ @colorizer ||= Colorizers::Default.new(config.theme)
19
+ end
20
+ end
21
+
22
+ register_extension(:rouge_colorizer) do
23
+ require_relative './colorizers/rouge'
24
+
25
+ def colorizer
26
+ @colorizer ||= Colorizers::Rouge.new(config.theme)
27
+ end
28
+ end
29
+
30
+ setting :theme, nil
15
31
  setting :message_template, %( Loaded %s in %sms %s).freeze
16
32
 
17
33
  attr_reader :config
18
34
  attr_reader :logger
19
- attr_reader :formatter
20
- attr_reader :lexer
21
35
  attr_reader :template
22
36
 
37
+ load_extensions(:default_colorizer)
38
+
23
39
  def initialize(logger, config = self.class.config)
24
40
  @logger = logger
25
41
  @config = config
26
- @formatter = Rouge::Formatters::Terminal256.new(config.theme)
27
- @lexer = Rouge::Lexers::SQL.new
28
42
  @template = config.message_template
29
43
  end
30
44
 
@@ -35,13 +49,7 @@ module Dry
35
49
  end
36
50
 
37
51
  def log_query(time, name, query)
38
- logger.info template % [name.inspect, time, colorize(query)]
39
- end
40
-
41
- private
42
-
43
- def colorize(string)
44
- config.colorize ? formatter.format(lexer.lex(string)) : string
52
+ logger.info template % [name.inspect, time, colorizer.call(query)]
45
53
  end
46
54
  end
47
55
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Monitor
3
- VERSION = '0.1.2'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -33,16 +33,17 @@ RSpec.describe Dry::Monitor::SQL::Logger do
33
33
 
34
34
  context 'without colors' do
35
35
  let(:sql_logger) do
36
- Class.new(Dry::Monitor::SQL::Logger) do
37
- configure do |config|
38
- config.colorize = false
39
- end
40
- end
36
+ Dry::Monitor::SQL::Logger.load_extensions(:rouge_colorizer)
37
+ Dry::Monitor::SQL::Logger
41
38
  end
42
39
 
43
40
  include_context '#subscribe' do
41
+ let(:colored_query) do
42
+ "\e[38;5;203mSELECT\e[39m\e[38;5;230m"
43
+ end
44
+
44
45
  it 'writes sql query in logs' do
45
- expect(log_file_content).to include(query)
46
+ expect(log_file_content).to include(colored_query)
46
47
  end
47
48
  end
48
49
  end
metadata CHANGED
@@ -1,77 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2019-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rouge
14
+ name: dry-equalizer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.2.1
19
+ version: '0.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.2.1
26
+ version: '0.2'
33
27
  - !ruby/object:Gem::Dependency
34
- name: dry-equalizer
28
+ name: dry-configurable
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '0.2'
33
+ version: '0.5'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '0.2'
40
+ version: '0.5'
47
41
  - !ruby/object:Gem::Dependency
48
- name: dry-configurable
42
+ name: dry-events
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0.5'
47
+ version: '0.1'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '0.5'
54
+ version: '0.1'
61
55
  - !ruby/object:Gem::Dependency
62
- name: dry-events
56
+ name: dry-core
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '0.1'
61
+ version: '0.4'
68
62
  type: :runtime
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: '0.1'
68
+ version: '0.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rouge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.2.1
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '2.0'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.2.1
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: bundler
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +153,8 @@ files:
139
153
  - lib/dry/monitor/notifications.rb
140
154
  - lib/dry/monitor/rack/logger.rb
141
155
  - lib/dry/monitor/rack/middleware.rb
156
+ - lib/dry/monitor/sql/colorizers/default.rb
157
+ - lib/dry/monitor/sql/colorizers/rouge.rb
142
158
  - lib/dry/monitor/sql/logger.rb
143
159
  - lib/dry/monitor/version.rb
144
160
  - rakelib/rubocop.rake
@@ -168,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
184
  version: '0'
169
185
  requirements: []
170
186
  rubyforge_project:
171
- rubygems_version: 2.6.11
187
+ rubygems_version: 2.7.6
172
188
  signing_key:
173
189
  specification_version: 4
174
190
  summary: Monitoring and instrumentation APIs