bullet 2.0.0.rc3 → 2.0.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.
- data/lib/bullet.rb +21 -35
- data/lib/bullet/notification/base.rb +7 -9
- data/lib/bullet/rack.rb +1 -1
- data/lib/bullet/version.rb +1 -1
- metadata +21 -16
- data/lib/bullet/presenter.rb +0 -13
- data/lib/bullet/presenter/base.rb +0 -9
- data/lib/bullet/presenter/bullet_logger.rb +0 -28
- data/lib/bullet/presenter/growl.rb +0 -40
- data/lib/bullet/presenter/javascript_alert.rb +0 -15
- data/lib/bullet/presenter/javascript_console.rb +0 -28
- data/lib/bullet/presenter/javascript_helpers.rb +0 -13
- data/lib/bullet/presenter/rails_logger.rb +0 -15
- data/lib/bullet/presenter/xmpp.rb +0 -56
data/lib/bullet.rb
CHANGED
@@ -12,11 +12,10 @@ module Bullet
|
|
12
12
|
autoload :Rack, 'bullet/rack'
|
13
13
|
autoload :BulletLogger, 'bullet/logger'
|
14
14
|
autoload :Notification, 'bullet/notification'
|
15
|
-
autoload :Presenter, 'bullet/presenter'
|
16
15
|
autoload :Detector, 'bullet/detector'
|
17
16
|
autoload :Registry, 'bullet/registry'
|
18
17
|
autoload :NotificationCollector, 'bullet/notification_collector'
|
19
|
-
|
18
|
+
|
20
19
|
if defined? Rails::Railtie
|
21
20
|
# compatible with rails 3.0.0.beta4
|
22
21
|
class BulletRailtie < Rails::Railtie
|
@@ -27,23 +26,18 @@ module Bullet
|
|
27
26
|
end
|
28
27
|
|
29
28
|
class <<self
|
30
|
-
attr_accessor :enable, :
|
29
|
+
attr_accessor :enable, :disable_browser_cache
|
31
30
|
attr_reader :notification_collector
|
32
|
-
|
33
|
-
|
31
|
+
|
32
|
+
delegate :alert=, :console=, :growl=, :rails_logger=, :xmpp=, :to => UniformNotifier
|
33
|
+
|
34
|
+
DETECTORS = [ Bullet::Detector::NPlusOneQuery,
|
34
35
|
Bullet::Detector::UnusedEagerAssociation,
|
35
36
|
Bullet::Detector::Counter ]
|
36
37
|
|
37
|
-
PRESENTERS = [ Bullet::Presenter::JavascriptAlert,
|
38
|
-
Bullet::Presenter::JavascriptConsole,
|
39
|
-
Bullet::Presenter::Growl,
|
40
|
-
Bullet::Presenter::Xmpp,
|
41
|
-
Bullet::Presenter::RailsLogger,
|
42
|
-
Bullet::Presenter::BulletLogger ]
|
43
|
-
|
44
38
|
def enable=(enable)
|
45
39
|
@enable = enable
|
46
|
-
if enable?
|
40
|
+
if enable?
|
47
41
|
Bullet::ActiveRecord.enable
|
48
42
|
if Rails.version =~ /^2./
|
49
43
|
Bullet::ActionController.enable
|
@@ -55,16 +49,12 @@ module Bullet
|
|
55
49
|
@enable == true
|
56
50
|
end
|
57
51
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def bullet_logger=(bullet_logger)
|
67
|
-
Bullet::Presenter::BulletLogger.setup if bullet_logger
|
52
|
+
def bullet_logger=(active)
|
53
|
+
if active
|
54
|
+
bullet_log_file = File.open( 'log/bullet.log', 'a+' )
|
55
|
+
bullet_log_file.sync
|
56
|
+
UniformNotifier.customized_logger = bullet_log_file
|
57
|
+
end
|
68
58
|
end
|
69
59
|
|
70
60
|
def start_request
|
@@ -75,15 +65,11 @@ module Bullet
|
|
75
65
|
def end_request
|
76
66
|
DETECTORS.each {|bullet| bullet.end_request}
|
77
67
|
end
|
78
|
-
|
68
|
+
|
79
69
|
def clear
|
80
70
|
DETECTORS.each {|bullet| bullet.clear}
|
81
71
|
end
|
82
72
|
|
83
|
-
def active_presenters
|
84
|
-
PRESENTERS.select { |presenter| presenter.send :active? }
|
85
|
-
end
|
86
|
-
|
87
73
|
def notification_collector
|
88
74
|
@notification_collector ||= Bullet::NotificationCollector.new
|
89
75
|
end
|
@@ -95,23 +81,23 @@ module Bullet
|
|
95
81
|
|
96
82
|
def gather_inline_notifications
|
97
83
|
responses = []
|
98
|
-
|
99
|
-
responses << notification.
|
84
|
+
for_each_active_notifier_with_notification do |notification|
|
85
|
+
responses << notification.notify_inline
|
100
86
|
end
|
101
87
|
responses.join( "\n" )
|
102
88
|
end
|
103
89
|
|
104
90
|
def perform_out_of_channel_notifications
|
105
|
-
|
106
|
-
notification.
|
91
|
+
for_each_active_notifier_with_notification do |notification|
|
92
|
+
notification.notify_out_of_channel
|
107
93
|
end
|
108
94
|
end
|
109
95
|
|
110
96
|
private
|
111
|
-
def
|
112
|
-
|
97
|
+
def for_each_active_notifier_with_notification
|
98
|
+
UniformNotifier.active_notifiers.each do |notifier|
|
113
99
|
notification_collector.collection.each do |notification|
|
114
|
-
notification.
|
100
|
+
notification.notifier = notifier
|
115
101
|
yield notification
|
116
102
|
end
|
117
103
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Bullet
|
2
2
|
module Notification
|
3
3
|
class Base
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :notifier
|
5
5
|
attr_reader :base_class, :associations, :path
|
6
6
|
|
7
7
|
def initialize( base_class, associations, path = nil )
|
@@ -15,11 +15,11 @@ module Bullet
|
|
15
15
|
|
16
16
|
def body
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def body_with_caller
|
20
20
|
body
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def standard_notice
|
24
24
|
@standard_notifice ||= title + "\n" + body
|
25
25
|
end
|
@@ -28,14 +28,12 @@ module Bullet
|
|
28
28
|
@full_notice ||= title + "\n" + body_with_caller
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
33
|
-
self.presenter.send( :inline_notify, self )
|
31
|
+
def notify_inline
|
32
|
+
self.notifier.inline_notify( self.full_notice )
|
34
33
|
end
|
35
34
|
|
36
|
-
def
|
37
|
-
|
38
|
-
self.presenter.send( :out_of_channel_notify, self )
|
35
|
+
def notify_out_of_channel
|
36
|
+
self.notifier.out_of_channel_notify( self.full_notice )
|
39
37
|
end
|
40
38
|
|
41
39
|
def eql?( other )
|
data/lib/bullet/rack.rb
CHANGED
@@ -30,7 +30,7 @@ module Bullet
|
|
30
30
|
(response.is_a?(Array) && response.size <= 1) ||
|
31
31
|
!response.body.is_a?(String) || response.body.empty?
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def check_html?(headers, response)
|
35
35
|
headers['Content-Type'] and headers['Content-Type'].include? 'text/html' and response.body =~ %r{<html.*</html>}m
|
36
36
|
end
|
data/lib/bullet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
|
11
|
-
version: 2.0.0.rc3
|
10
|
+
version: 2.0.0
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Richard Huang
|
@@ -16,10 +15,25 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-19 00:00:00 +08:00
|
20
19
|
default_executable:
|
21
|
-
dependencies:
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 23
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
requirement: *id001
|
34
|
+
name: uniform_notifier
|
35
|
+
prerelease: false
|
36
|
+
type: :runtime
|
23
37
|
description: A rails plugin to kill N+1 queries and unused eager loading.
|
24
38
|
email:
|
25
39
|
- flyerhzm@gmail.com
|
@@ -47,15 +61,6 @@ files:
|
|
47
61
|
- lib/bullet/notification/unused_eager_loading.rb
|
48
62
|
- lib/bullet/notification.rb
|
49
63
|
- lib/bullet/notification_collector.rb
|
50
|
-
- lib/bullet/presenter/base.rb
|
51
|
-
- lib/bullet/presenter/bullet_logger.rb
|
52
|
-
- lib/bullet/presenter/growl.rb
|
53
|
-
- lib/bullet/presenter/javascript_alert.rb
|
54
|
-
- lib/bullet/presenter/javascript_console.rb
|
55
|
-
- lib/bullet/presenter/javascript_helpers.rb
|
56
|
-
- lib/bullet/presenter/rails_logger.rb
|
57
|
-
- lib/bullet/presenter/xmpp.rb
|
58
|
-
- lib/bullet/presenter.rb
|
59
64
|
- lib/bullet/rack.rb
|
60
65
|
- lib/bullet/registry/association.rb
|
61
66
|
- lib/bullet/registry/base.rb
|
data/lib/bullet/presenter.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
autoload :Base, 'bullet/presenter/base'
|
4
|
-
autoload :JavascriptAlert, 'bullet/presenter/javascript_alert'
|
5
|
-
autoload :JavascriptConsole, 'bullet/presenter/javascript_console'
|
6
|
-
autoload :Growl, 'bullet/presenter/growl'
|
7
|
-
autoload :Xmpp, 'bullet/presenter/xmpp'
|
8
|
-
autoload :RailsLogger, 'bullet/presenter/rails_logger'
|
9
|
-
autoload :BulletLogger, 'bullet/presenter/bullet_logger'
|
10
|
-
|
11
|
-
autoload :JavascriptHelpers, 'bullet/presenter/javascript_helpers'
|
12
|
-
end
|
13
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
class BulletLogger < Base
|
4
|
-
@logger_file = nil
|
5
|
-
@logger = nil
|
6
|
-
|
7
|
-
def self.active?
|
8
|
-
@logger
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.out_of_channel_notify( notice )
|
12
|
-
return unless active?
|
13
|
-
@logger.info notice.full_notice
|
14
|
-
@logger_file.flush
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.setup
|
18
|
-
@logger_file = File.open( Rails.root.join('log/bullet.log'), 'a+' )
|
19
|
-
@logger = Logger.new( @logger_file )
|
20
|
-
|
21
|
-
def @logger.format_message( severity, timestamp, progname, msg )
|
22
|
-
"#{timestamp.to_formatted_s(:db)}[#{severity}] #{msg}\n"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
class Growl < Base
|
4
|
-
@growl = nil
|
5
|
-
|
6
|
-
def self.active?
|
7
|
-
@growl
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.out_of_channel_notify( notice )
|
11
|
-
return unless active?
|
12
|
-
notify( notice.standard_notice )
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.setup_connection( password )
|
16
|
-
require 'ruby-growl'
|
17
|
-
@password = password
|
18
|
-
@growl = connect
|
19
|
-
|
20
|
-
notify 'Bullet Growl notifications have been turned on'
|
21
|
-
rescue MissingSourceFile
|
22
|
-
@growl = nil
|
23
|
-
raise NotificationError.new( 'You must install the ruby-growl gem to use Growl notifications: `sudo gem install ruby-growl`' )
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def self.connect
|
28
|
-
::Growl.new 'localhost',
|
29
|
-
'ruby-growl',
|
30
|
-
[ 'Bullet Notification' ],
|
31
|
-
nil,
|
32
|
-
@password
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.notify( message )
|
36
|
-
@growl.notify( 'Bullet Notification', 'Bullet Notification', message )
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
class JavascriptAlert < Base
|
4
|
-
def self.active?
|
5
|
-
Bullet.alert
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.inline_notify( notice )
|
9
|
-
return '' unless self.active?
|
10
|
-
|
11
|
-
JavascriptHelpers::wrap_js_association "alert( #{notice.standard_notice.inspect} ); "
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
class JavascriptConsole < Base
|
4
|
-
def self.active?
|
5
|
-
Bullet.console
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.inline_notify( notice )
|
9
|
-
return '' unless active?
|
10
|
-
|
11
|
-
code = <<-CODE
|
12
|
-
if (typeof(console) !== 'undefined') {
|
13
|
-
if (console.groupCollapsed && console.groupEnd && console.log) {
|
14
|
-
console.groupCollapsed(#{notice.title.inspect});
|
15
|
-
console.log(#{notice.body_with_caller.inspect});
|
16
|
-
console.groupEnd();
|
17
|
-
|
18
|
-
} else if (console.log) {
|
19
|
-
console.log(#{notice.full_notice.inspect});
|
20
|
-
}
|
21
|
-
}
|
22
|
-
CODE
|
23
|
-
|
24
|
-
JavascriptHelpers::wrap_js_association code
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
class RailsLogger < Base
|
4
|
-
def self.active?
|
5
|
-
Bullet.rails_logger
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.out_of_channel_notify( notice )
|
9
|
-
return unless active?
|
10
|
-
Rails.logger.warn ''
|
11
|
-
Rails.logger.warn notice.full_notice
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Bullet
|
2
|
-
module Presenter
|
3
|
-
class Xmpp < Base
|
4
|
-
@receiver = nil
|
5
|
-
@xmpp = nil
|
6
|
-
@password = nil
|
7
|
-
|
8
|
-
def self.active?
|
9
|
-
@xmpp
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.out_of_channel_notify( notice )
|
13
|
-
return unless active?
|
14
|
-
notify( notice.standard_notice )
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.setup_connection( xmpp_information )
|
18
|
-
require 'xmpp4r'
|
19
|
-
|
20
|
-
@receiver = xmpp_information[:receiver]
|
21
|
-
@password = xmpp_information[:password]
|
22
|
-
@account = xmpp_information[:account]
|
23
|
-
@show_online_status = xmpp_information[:show_online_status]
|
24
|
-
|
25
|
-
connect
|
26
|
-
rescue MissingSourceFile
|
27
|
-
@xmpp = nil
|
28
|
-
raise NotificationError.new( 'You must install the xmpp4r gem to use XMPP notifications: `sudo gem install xmpp4r`' )
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def self.connect
|
33
|
-
jid = Jabber::JID.new( @account )
|
34
|
-
@xmpp = Jabber::Client.new( jid )
|
35
|
-
@xmpp.connect
|
36
|
-
@xmpp.auth( @password )
|
37
|
-
@xmpp.send( presence_status ) if @show_online_status
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.notify( message )
|
41
|
-
message = Jabber::Message.new( @receiver, message ).
|
42
|
-
set_type( :normal ).
|
43
|
-
set_id( '1' ).
|
44
|
-
set_subject( 'Bullet Notification' )
|
45
|
-
@xmpp.send( message )
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.presence_status
|
49
|
-
project_name = Rails.root.basename.to_s.camelcase
|
50
|
-
time = Time.now
|
51
|
-
|
52
|
-
Jabber::Presence.new.set_status( "Bullet in project '#{project_name}' started on #{time}" )
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|