flyerhzm-bullet 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +9 -0
- data/VERSION +1 -1
- data/bullet.gemspec +2 -2
- data/lib/bullet/association.rb +29 -26
- data/lib/bulletware.rb +8 -3
- metadata +2 -2
data/README.textile
CHANGED
@@ -39,6 +39,15 @@ config.after_initialize do
|
|
39
39
|
end
|
40
40
|
</code></pre>
|
41
41
|
|
42
|
+
It is recommended to config growl notification as follows if your collaborators are not using MacOS
|
43
|
+
<pre><code>
|
44
|
+
begin
|
45
|
+
require 'ruby-growl'
|
46
|
+
Bullet::Association.growl = true
|
47
|
+
rescue MissingSourceFile
|
48
|
+
end
|
49
|
+
</code></pre>
|
50
|
+
|
42
51
|
The code above will enable all five of the Bullet notification systems:
|
43
52
|
* <code>Bullet.enable</code>: enable Bullet plugin, otherwise do nothing
|
44
53
|
* <code>Bullet::Association.alert</code>: pop up a JavaScript alert in the browser
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/bullet.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bullet}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Richard Huang"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-09-03}
|
13
13
|
s.description = %q{The Bullet plugin is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries) or when you're using eager loading that isn't necessary.}
|
14
14
|
s.email = %q{flyerhzm@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/bullet/association.rb
CHANGED
@@ -85,18 +85,10 @@ module Bullet
|
|
85
85
|
!unpreload_associations.empty?
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
88
|
+
def javascript_notification
|
89
89
|
str = ''
|
90
|
-
if @@alert || @@console
|
91
|
-
response =
|
92
|
-
if has_unused_preload_associations?
|
93
|
-
response.push("Unused eager loadings detected:\n")
|
94
|
-
response.push(*@@unused_preload_associations.to_a.collect{|klazz, associations| klazz_associations_str(klazz, associations)}.join("\n"))
|
95
|
-
end
|
96
|
-
if has_unpreload_associations?
|
97
|
-
response.push("#{"\n" unless response.empty?}N+1 queries detected:\n")
|
98
|
-
response.push(*@@unpreload_associations.to_a.collect{|klazz, associations| " #{klazz} => [#{associations.map(&:inspect).join(', ')}]"}.join("\n"))
|
99
|
-
end
|
90
|
+
if @@alert || @@console
|
91
|
+
response = notification_response
|
100
92
|
end
|
101
93
|
if @@alert
|
102
94
|
str << wrap_js_association("alert(#{response.join("\n").inspect});")
|
@@ -104,25 +96,21 @@ module Bullet
|
|
104
96
|
if @@console
|
105
97
|
str << wrap_js_association("if (typeof(console) != 'undefined' && console.log) console.log(#{response.join("\n").inspect});")
|
106
98
|
end
|
99
|
+
str
|
100
|
+
end
|
101
|
+
|
102
|
+
def growl_notification
|
107
103
|
if @@growl
|
104
|
+
response = notification_response
|
108
105
|
begin
|
109
106
|
growl = Growl.new('localhost', 'ruby-growl', ['Bullet Notification'], nil, @@growl_password)
|
110
107
|
growl.notify('Bullet Notification', 'Bullet Notification', response.join("\n"))
|
111
108
|
rescue
|
112
109
|
end
|
113
|
-
str << '<!-- Sent Growl notification -->'
|
114
110
|
end
|
115
|
-
str
|
116
|
-
end
|
117
|
-
|
118
|
-
def wrap_js_association(message)
|
119
|
-
str = ''
|
120
|
-
str << "<script type=\"text/javascript\">/*<![CDATA[*/"
|
121
|
-
str << message
|
122
|
-
str << "/*]]>*/</script>\n"
|
123
111
|
end
|
124
112
|
|
125
|
-
def
|
113
|
+
def log_notificatioin(path)
|
126
114
|
if (@@bullet_logger || @@rails_logger) && (!unpreload_associations.empty? || !unused_preload_associations.empty?)
|
127
115
|
Rails.logger.warn '' if @@rails_logger
|
128
116
|
unused_preload_associations.each do |klazz, associations|
|
@@ -144,11 +132,6 @@ module Bullet
|
|
144
132
|
end
|
145
133
|
end
|
146
134
|
|
147
|
-
def bad_associations_str(bad_associations)
|
148
|
-
# puts bad_associations.inspect
|
149
|
-
bad_associations.to_a.collect{|klazz, associations| klazz_associations_str(klazz, associations)}.join("\n")
|
150
|
-
end
|
151
|
-
|
152
135
|
def klazz_associations_str(klazz, associations)
|
153
136
|
" #{klazz} => [#{associations.map(&:inspect).join(', ')}]"
|
154
137
|
end
|
@@ -157,6 +140,26 @@ module Bullet
|
|
157
140
|
":include => #{associations.map{|a| a.to_sym unless a.is_a? Hash}.inspect}"
|
158
141
|
end
|
159
142
|
|
143
|
+
def notification_response
|
144
|
+
response = []
|
145
|
+
if has_unused_preload_associations?
|
146
|
+
response.push("Unused eager loadings detected:\n")
|
147
|
+
response.push(*@@unused_preload_associations.to_a.collect{|klazz, associations| klazz_associations_str(klazz, associations)}.join("\n"))
|
148
|
+
end
|
149
|
+
if has_unpreload_associations?
|
150
|
+
response.push("#{"\n" unless response.empty?}N+1 queries detected:\n")
|
151
|
+
response.push(*@@unpreload_associations.to_a.collect{|klazz, associations| " #{klazz} => [#{associations.map(&:inspect).join(', ')}]"}.join("\n"))
|
152
|
+
end
|
153
|
+
response
|
154
|
+
end
|
155
|
+
|
156
|
+
def wrap_js_association(message)
|
157
|
+
str = ''
|
158
|
+
str << "<script type=\"text/javascript\">/*<![CDATA[*/"
|
159
|
+
str << message
|
160
|
+
str << "/*]]>*/</script>\n"
|
161
|
+
end
|
162
|
+
|
160
163
|
def has_klazz_association(klazz)
|
161
164
|
!klazz_associations[klazz].nil? and klazz_associations.keys.include?(klazz)
|
162
165
|
end
|
data/lib/bulletware.rb
CHANGED
@@ -11,15 +11,20 @@ class Bulletware
|
|
11
11
|
return [status, headers, response] if response.empty?
|
12
12
|
|
13
13
|
if Bullet::Association.has_bad_assocations?
|
14
|
-
if
|
15
|
-
response_body = response.body << Bullet::Association.
|
14
|
+
if check_html?(headers, response)
|
15
|
+
response_body = response.body << Bullet::Association.javascript_notification
|
16
16
|
headers['Content-Length'] = response_body.length.to_s
|
17
17
|
end
|
18
18
|
|
19
|
-
Bullet::Association.
|
19
|
+
Bullet::Association.growl_notification
|
20
|
+
Bullet::Association.log_notificatioin(env['PATH_INFO'])
|
20
21
|
end
|
21
22
|
response_body ||= response.body
|
22
23
|
Bullet::Association.end_request
|
23
24
|
[status, headers, response_body]
|
24
25
|
end
|
26
|
+
|
27
|
+
def check_html?(headers, response)
|
28
|
+
!headers['Content-Type'].nil? and headers['Content-Type'].include? 'text/html' and response.body =~ %r{<html.*</html>}m
|
29
|
+
end
|
25
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flyerhzm-bullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|