-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from kirillshevch/feature/custom-handlers
Add custom notifications (handlers)
Showing
8 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module QueryTrack | ||
module Notifications | ||
class Custom | ||
attr_reader :code, :duration | ||
|
||
def initialize(code, duration) | ||
@code = code.strip | ||
@duration = duration | ||
end | ||
|
||
def call | ||
return unless QueryTrack::Settings.config.notifications.custom_handler | ||
|
||
trace = QueryTrack::Trace.new(caller).call | ||
|
||
QueryTrack::Settings.config.notifications.custom_handler.call(code, duration, trace) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module QueryTrack | ||
VERSION = '0.0.8' | ||
VERSION = '0.0.9' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
RSpec.describe QueryTrack::Notifications::Custom do | ||
let(:code) { 'COMMIT' } | ||
let(:duration) { 5 } | ||
|
||
subject { described_class.new(code, duration) } | ||
|
||
context 'custom handler not specified' do | ||
before do | ||
QueryTrack::Settings.configure do |config| | ||
config.duration = 1.0 | ||
end | ||
end | ||
|
||
it 'should not return anything' do | ||
expect(subject.call).to be_nil | ||
end | ||
end | ||
|
||
context 'custom handler specified' do | ||
before do | ||
QueryTrack::Settings.configure do |config| | ||
config.duration = 1.0 | ||
config.notifications.custom_handler = -> (sql, duration, trace) {} | ||
end | ||
end | ||
|
||
it 'should call custom handler' do | ||
expect(QueryTrack::Settings.config.notifications.custom_handler).to receive(:call) | ||
subject.call | ||
end | ||
end | ||
end |