sweet_notifications 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/sweet_notifications.rb +4 -2
- data/lib/sweet_notifications/log_subscriber.rb +5 -0
- data/lib/sweet_notifications/version.rb +1 -1
- data/sweet_notifications.gemspec +1 -1
- data/test/controller_runtime_test.rb +0 -5
- data/test/log_subscriber_test.rb +0 -1
- data/test/sweet_notifications_test.rb +25 -0
- data/test/test_helper.rb +3 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b10b735828800811baddaaf6234ccde5d4825d0c
|
4
|
+
data.tar.gz: f4a229a8c82c4fbd5d098cae36c945d32fe78c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46055d7192e980297c47042fd7c0d72a86e9c97fac56b02befc39055f7cfea05537fe79de7876e52406f03fea4bc309bff5035720a9492b0931ca0b5b12a24c7
|
7
|
+
data.tar.gz: 9244a85530d1b16dcb7ade6b656986f9a699d70c25d02a3fd2aaefde9b77efb81c64611c637df3f730116286ab8e092f9b255ad823da60a0bf401b5118aeda3f
|
data/Rakefile
CHANGED
data/lib/sweet_notifications.rb
CHANGED
@@ -16,6 +16,7 @@ module SweetNotifications
|
|
16
16
|
# initialized.
|
17
17
|
#
|
18
18
|
# @param name [Symbol] event namespace
|
19
|
+
# @param label [String] optional label for logging
|
19
20
|
# @return [Rails::Railtie, ActiveSupport::LogSubscriber] An array consisting
|
20
21
|
# of a Railtie and a LogSubscriber
|
21
22
|
# @yield event subscription
|
@@ -29,9 +30,10 @@ module SweetNotifications
|
|
29
30
|
# debug message(event, event.payload[:name], event.payload[:sql])
|
30
31
|
# end
|
31
32
|
# end
|
32
|
-
def self.subscribe(name, &block)
|
33
|
+
def self.subscribe(name, label: nil, &block)
|
34
|
+
label ||= name
|
33
35
|
log_subscriber = Class.new(SweetNotifications::LogSubscriber, &block)
|
34
|
-
controller_runtime = self.controller_runtime(
|
36
|
+
controller_runtime = self.controller_runtime(label, log_subscriber)
|
35
37
|
if Rails.try(:application).try(:initialized?)
|
36
38
|
initialize_rails(name, log_subscriber, controller_runtime)
|
37
39
|
[nil, log_subscriber]
|
@@ -7,6 +7,11 @@ module SweetNotifications
|
|
7
7
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
8
8
|
class_attribute :odd_color, :even_color
|
9
9
|
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
@odd = false
|
13
|
+
end
|
14
|
+
|
10
15
|
# Format a message for logging
|
11
16
|
#
|
12
17
|
# @param event [ActiveSupport::Notifications::Event] subscribed event
|
data/sweet_notifications.gemspec
CHANGED
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "yard", "~> 0.8.7"
|
31
31
|
spec.add_development_dependency "appraisal", "~> 1.0"
|
32
32
|
spec.add_development_dependency "simplecov", "~> 0.8.2"
|
33
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
33
|
+
spec.add_development_dependency "rubocop", "~> 0.23.0"
|
34
34
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
require 'active_support/test_case'
|
2
|
-
require 'active_support/log_subscriber'
|
3
|
-
require 'active_support/log_subscriber/test_helper'
|
4
|
-
require 'action_controller/log_subscriber'
|
5
|
-
require 'action_controller'
|
6
1
|
require 'test_helper'
|
7
2
|
|
8
3
|
describe SweetNotifications::ControllerRuntime do
|
data/test/log_subscriber_test.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
class SweetNotificationsController < ActionController::Base
|
4
|
+
def index
|
5
|
+
ActiveSupport::Notifications.instrument 'test.controller' do
|
6
|
+
'ok'
|
7
|
+
end
|
8
|
+
render nothing: true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
describe SweetNotifications do
|
4
13
|
include ActiveSupport::LogSubscriber::TestHelper
|
14
|
+
tests SweetNotificationsController
|
5
15
|
|
6
16
|
describe '.subscribe' do
|
7
17
|
it 'creates a railtie' do
|
@@ -56,5 +66,20 @@ describe SweetNotifications do
|
|
56
66
|
end
|
57
67
|
assert_match(/Direct \(\d\.\d{2}ms\) foo bar/, @logger.logged(:info)[0])
|
58
68
|
end
|
69
|
+
|
70
|
+
it 'logs to Rails logger' do
|
71
|
+
railtie, _ = SweetNotifications.subscribe 'controller', label: 'Label' do
|
72
|
+
event :test, runtime: true do |event|
|
73
|
+
info message(event, 'Test', 'logging')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
railtie.run_initializers
|
77
|
+
|
78
|
+
get :index
|
79
|
+
wait
|
80
|
+
assert_match(/Test \(\d\.\d{2}ms\) logging/, @logger.logged(:info)[0])
|
81
|
+
out = ActionController::Base.log_process_action(label_runtime: 1234)
|
82
|
+
assert_match(/Label: 1234\.0ms/, out[0])
|
83
|
+
end
|
59
84
|
end
|
60
85
|
end
|
data/test/test_helper.rb
CHANGED
@@ -11,6 +11,8 @@ require 'minitest/spec'
|
|
11
11
|
require 'minitest/pride'
|
12
12
|
require 'sweet_notifications'
|
13
13
|
require 'active_support/test_case'
|
14
|
+
require 'action_controller'
|
15
|
+
require 'active_support/log_subscriber/test_helper'
|
14
16
|
require 'securerandom'
|
15
17
|
|
16
18
|
class ActiveSupport::TestCase
|
@@ -19,6 +21,7 @@ class ActiveSupport::TestCase
|
|
19
21
|
end
|
20
22
|
|
21
23
|
extend MiniTest::Spec::DSL
|
24
|
+
register_spec_type(/SweetNotifications$/, ActionController::TestCase)
|
22
25
|
register_spec_type(/ControllerRuntime$/, ActionController::TestCase)
|
23
26
|
register_spec_type(self)
|
24
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sweet_notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ville Lautanala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.23.0
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 0.23.0
|
167
167
|
description: Syntactic sugar for ActiveSupport::LogSubscriber for easy instrumentation
|
168
168
|
and logging from third-party libraries.
|
169
169
|
email:
|