mole 1.0.5 → 1.0.6
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/Manifest.txt +92 -0
- data/README.txt +10 -7
- data/lib/mole.rb +63 -1
- data/lib/mole/module.rb +136 -124
- data/lib/mole/utils/frameworks.rb +32 -7
- data/lib/mole/version.rb +1 -1
- data/notes/notes.txt +1 -0
- data/samples/merbapp/README +14 -0
- data/samples/merbapp/Rakefile +124 -0
- data/samples/merbapp/app/controllers/application.rb +3 -0
- data/samples/merbapp/app/controllers/exceptions.rb +13 -0
- data/samples/merbapp/app/controllers/moled.rb +25 -0
- data/samples/merbapp/app/helpers/global_helper.rb +5 -0
- data/samples/merbapp/app/mailers/views/layout/application.html.erb +1 -0
- data/samples/merbapp/app/mailers/views/layout/application.text.erb +1 -0
- data/samples/merbapp/app/parts/views/layout/application.html.erb +1 -0
- data/samples/merbapp/app/views/exceptions/internal_server_error.html.erb +216 -0
- data/samples/merbapp/app/views/exceptions/not_acceptable.html.erb +38 -0
- data/samples/merbapp/app/views/exceptions/not_found.html.erb +40 -0
- data/samples/merbapp/app/views/layout/application.html.erb +11 -0
- data/samples/merbapp/app/views/moled/index.html.erb +5 -0
- data/samples/merbapp/app/views/moled/result.html.erb +5 -0
- data/samples/merbapp/config/boot.rb +11 -0
- data/samples/merbapp/config/dependencies.rb +41 -0
- data/samples/merbapp/config/environments/development.rb +1 -0
- data/samples/merbapp/config/environments/production.rb +1 -0
- data/samples/merbapp/config/environments/test.rb +1 -0
- data/samples/merbapp/config/merb.yml +82 -0
- data/samples/merbapp/config/merb_init.rb +26 -0
- data/samples/merbapp/config/mole_config.rb +33 -0
- data/samples/merbapp/config/router.rb +38 -0
- data/samples/merbapp/config/upload.conf +0 -0
- data/samples/merbapp/log/merb.4000.pid +1 -0
- data/samples/merbapp/public/images/merb.jpg +0 -0
- data/samples/merbapp/public/merb.fcgi +6 -0
- data/samples/merbapp/public/stylesheets/master.css +119 -0
- data/samples/merbapp/script/destroy +32 -0
- data/samples/merbapp/script/generate +32 -0
- data/samples/merbapp/script/stop_merb +13 -0
- data/samples/merbapp/spec/spec_helper.rb +15 -0
- data/samples/merbapp/test/test_helper.rb +14 -0
- data/samples/railsapp/README +14 -0
- data/samples/railsapp/Rakefile +10 -0
- data/samples/railsapp/app/controllers/application.rb +13 -0
- data/samples/railsapp/app/controllers/moled_controller.rb +23 -0
- data/samples/railsapp/app/helpers/application_helper.rb +3 -0
- data/samples/railsapp/app/views/moled/index.html.erb +5 -0
- data/samples/railsapp/app/views/moled/result.html.erb +5 -0
- data/samples/railsapp/config/boot.rb +109 -0
- data/samples/railsapp/config/database.yml +13 -0
- data/samples/railsapp/config/environment.rb +59 -0
- data/samples/railsapp/config/environments/development.rb +18 -0
- data/samples/railsapp/config/environments/production.rb +20 -0
- data/samples/railsapp/config/environments/test.rb +22 -0
- data/samples/railsapp/config/initializers/inflections.rb +10 -0
- data/samples/railsapp/config/initializers/mime_types.rb +5 -0
- data/samples/railsapp/config/initializers/mole.rb +10 -0
- data/samples/railsapp/config/moles/mole_config.rb +44 -0
- data/samples/railsapp/config/routes.rb +35 -0
- data/samples/railsapp/doc/README_FOR_APP +2 -0
- data/samples/railsapp/log/development.log +3554 -0
- data/samples/railsapp/log/production.log +643 -0
- data/samples/railsapp/log/server.log +0 -0
- data/samples/railsapp/log/test.log +0 -0
- data/samples/railsapp/public/.htaccess +40 -0
- data/samples/railsapp/public/404.html +30 -0
- data/samples/railsapp/public/422.html +30 -0
- data/samples/railsapp/public/500.html +30 -0
- data/samples/railsapp/public/dispatch.cgi +10 -0
- data/samples/railsapp/public/dispatch.fcgi +24 -0
- data/samples/railsapp/public/dispatch.rb +10 -0
- data/samples/railsapp/public/favicon.ico +0 -0
- data/samples/railsapp/public/images/rails.png +0 -0
- data/samples/railsapp/public/javascripts/application.js +2 -0
- data/samples/railsapp/public/javascripts/controls.js +963 -0
- data/samples/railsapp/public/javascripts/dragdrop.js +972 -0
- data/samples/railsapp/public/javascripts/effects.js +1120 -0
- data/samples/railsapp/public/javascripts/prototype.js +4225 -0
- data/samples/railsapp/public/robots.txt +5 -0
- data/samples/railsapp/script/about +3 -0
- data/samples/railsapp/script/console +3 -0
- data/samples/railsapp/script/destroy +3 -0
- data/samples/railsapp/script/generate +3 -0
- data/samples/railsapp/script/performance/benchmarker +3 -0
- data/samples/railsapp/script/performance/profiler +3 -0
- data/samples/railsapp/script/performance/request +3 -0
- data/samples/railsapp/script/plugin +3 -0
- data/samples/railsapp/script/process/inspector +3 -0
- data/samples/railsapp/script/process/reaper +3 -0
- data/samples/railsapp/script/process/spawner +3 -0
- data/samples/railsapp/script/runner +3 -0
- data/samples/railsapp/script/server +3 -0
- data/samples/railsapp/test/test_helper.rb +38 -0
- data/samples/rubyapp/README +22 -0
- data/samples/rubyapp/bin/ruby_app +35 -0
- data/samples/rubyapp/config/mole_conf.rb +31 -0
- data/samples/rubyapp/lib/fred.rb +22 -0
- data/spec/config/auto_mole_config.rb +26 -0
- data/spec/data/blee.rb +1 -1
- data/spec/module_spec.rb +8 -8
- data/spec/mole_spec.rb +70 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/utils/framework_spec.rb +52 -12
- metadata +154 -53
data/Manifest.txt
CHANGED
|
@@ -15,6 +15,98 @@ lib/mole/module.rb
|
|
|
15
15
|
lib/mole/moler.rb
|
|
16
16
|
lib/mole/utils/frameworks.rb
|
|
17
17
|
lib/mole/version.rb
|
|
18
|
+
notes/notes.txt
|
|
19
|
+
samples/merbapp/README
|
|
20
|
+
samples/merbapp/Rakefile
|
|
21
|
+
samples/merbapp/app/controllers/application.rb
|
|
22
|
+
samples/merbapp/app/controllers/exceptions.rb
|
|
23
|
+
samples/merbapp/app/controllers/moled.rb
|
|
24
|
+
samples/merbapp/app/helpers/global_helper.rb
|
|
25
|
+
samples/merbapp/app/mailers/views/layout/application.html.erb
|
|
26
|
+
samples/merbapp/app/mailers/views/layout/application.text.erb
|
|
27
|
+
samples/merbapp/app/parts/views/layout/application.html.erb
|
|
28
|
+
samples/merbapp/app/views/exceptions/internal_server_error.html.erb
|
|
29
|
+
samples/merbapp/app/views/exceptions/not_acceptable.html.erb
|
|
30
|
+
samples/merbapp/app/views/exceptions/not_found.html.erb
|
|
31
|
+
samples/merbapp/app/views/layout/application.html.erb
|
|
32
|
+
samples/merbapp/app/views/moled/index.html.erb
|
|
33
|
+
samples/merbapp/app/views/moled/result.html.erb
|
|
34
|
+
samples/merbapp/config/boot.rb
|
|
35
|
+
samples/merbapp/config/dependencies.rb
|
|
36
|
+
samples/merbapp/config/environments/development.rb
|
|
37
|
+
samples/merbapp/config/environments/production.rb
|
|
38
|
+
samples/merbapp/config/environments/test.rb
|
|
39
|
+
samples/merbapp/config/merb.yml
|
|
40
|
+
samples/merbapp/config/merb_init.rb
|
|
41
|
+
samples/merbapp/config/mole_config.rb
|
|
42
|
+
samples/merbapp/config/router.rb
|
|
43
|
+
samples/merbapp/config/upload.conf
|
|
44
|
+
samples/merbapp/log/merb.4000.pid
|
|
45
|
+
samples/merbapp/public/images/merb.jpg
|
|
46
|
+
samples/merbapp/public/merb.fcgi
|
|
47
|
+
samples/merbapp/public/stylesheets/master.css
|
|
48
|
+
samples/merbapp/script/destroy
|
|
49
|
+
samples/merbapp/script/generate
|
|
50
|
+
samples/merbapp/script/stop_merb
|
|
51
|
+
samples/merbapp/spec/spec_helper.rb
|
|
52
|
+
samples/merbapp/test/test_helper.rb
|
|
53
|
+
samples/railsapp/README
|
|
54
|
+
samples/railsapp/Rakefile
|
|
55
|
+
samples/railsapp/app/controllers/application.rb
|
|
56
|
+
samples/railsapp/app/controllers/moled_controller.rb
|
|
57
|
+
samples/railsapp/app/helpers/application_helper.rb
|
|
58
|
+
samples/railsapp/app/views/moled/index.html.erb
|
|
59
|
+
samples/railsapp/app/views/moled/result.html.erb
|
|
60
|
+
samples/railsapp/config/boot.rb
|
|
61
|
+
samples/railsapp/config/database.yml
|
|
62
|
+
samples/railsapp/config/environment.rb
|
|
63
|
+
samples/railsapp/config/environments/development.rb
|
|
64
|
+
samples/railsapp/config/environments/production.rb
|
|
65
|
+
samples/railsapp/config/environments/test.rb
|
|
66
|
+
samples/railsapp/config/initializers/inflections.rb
|
|
67
|
+
samples/railsapp/config/initializers/mime_types.rb
|
|
68
|
+
samples/railsapp/config/initializers/mole.rb
|
|
69
|
+
samples/railsapp/config/moles/mole_config.rb
|
|
70
|
+
samples/railsapp/config/routes.rb
|
|
71
|
+
samples/railsapp/doc/README_FOR_APP
|
|
72
|
+
samples/railsapp/log/development.log
|
|
73
|
+
samples/railsapp/log/production.log
|
|
74
|
+
samples/railsapp/log/server.log
|
|
75
|
+
samples/railsapp/log/test.log
|
|
76
|
+
samples/railsapp/public/.htaccess
|
|
77
|
+
samples/railsapp/public/404.html
|
|
78
|
+
samples/railsapp/public/422.html
|
|
79
|
+
samples/railsapp/public/500.html
|
|
80
|
+
samples/railsapp/public/dispatch.cgi
|
|
81
|
+
samples/railsapp/public/dispatch.fcgi
|
|
82
|
+
samples/railsapp/public/dispatch.rb
|
|
83
|
+
samples/railsapp/public/favicon.ico
|
|
84
|
+
samples/railsapp/public/images/rails.png
|
|
85
|
+
samples/railsapp/public/javascripts/application.js
|
|
86
|
+
samples/railsapp/public/javascripts/controls.js
|
|
87
|
+
samples/railsapp/public/javascripts/dragdrop.js
|
|
88
|
+
samples/railsapp/public/javascripts/effects.js
|
|
89
|
+
samples/railsapp/public/javascripts/prototype.js
|
|
90
|
+
samples/railsapp/public/robots.txt
|
|
91
|
+
samples/railsapp/script/about
|
|
92
|
+
samples/railsapp/script/console
|
|
93
|
+
samples/railsapp/script/destroy
|
|
94
|
+
samples/railsapp/script/generate
|
|
95
|
+
samples/railsapp/script/performance/benchmarker
|
|
96
|
+
samples/railsapp/script/performance/profiler
|
|
97
|
+
samples/railsapp/script/performance/request
|
|
98
|
+
samples/railsapp/script/plugin
|
|
99
|
+
samples/railsapp/script/process/inspector
|
|
100
|
+
samples/railsapp/script/process/reaper
|
|
101
|
+
samples/railsapp/script/process/spawner
|
|
102
|
+
samples/railsapp/script/runner
|
|
103
|
+
samples/railsapp/script/server
|
|
104
|
+
samples/railsapp/test/test_helper.rb
|
|
105
|
+
samples/rubyapp/README
|
|
106
|
+
samples/rubyapp/bin/ruby_app
|
|
107
|
+
samples/rubyapp/config/mole_conf.rb
|
|
108
|
+
samples/rubyapp/lib/fred.rb
|
|
109
|
+
spec/config/auto_mole_config.rb
|
|
18
110
|
spec/config/mole_config.rb
|
|
19
111
|
spec/config/moles/fred_config.rb
|
|
20
112
|
spec/data/blee.rb
|
data/README.txt
CHANGED
|
@@ -26,6 +26,7 @@ instead.
|
|
|
26
26
|
* Forum: http://groups.google.com/group/mole-plugin
|
|
27
27
|
* Home: mole.rubyforge.org
|
|
28
28
|
* Svn: svn://rubyforge.org/var/svn/mole/mole/trunk
|
|
29
|
+
* Git: git://github.com/derailed/mole.git
|
|
29
30
|
* Snitch Svn: svn://rubyforge.org/var/svn/mole/snitch/trunk
|
|
30
31
|
* Examples: svn://rubyforge.org/var/svn/mole/samples
|
|
31
32
|
|
|
@@ -87,19 +88,21 @@ The MOle allows you to easily
|
|
|
87
88
|
:log_level => :debug,
|
|
88
89
|
:perf_threshold => 2,
|
|
89
90
|
:mole_config => File.join( File.dirname(__FILE__), %w[mole.rb] ) )
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
# Load the MOle configuration file(s)
|
|
92
|
+
::Mole.load_configuration
|
|
92
93
|
|
|
93
94
|
NOTE: The mole_config can either be a single ruby file or a directory containing multiple MOle
|
|
94
95
|
configuration files. Thanks to Ian Schreuder for the suggestion !
|
|
95
96
|
|
|
96
|
-
NOTE: For rails
|
|
97
|
-
or in your environment file
|
|
98
|
-
load_configuration call in your application controller as follows:
|
|
97
|
+
NOTE: For rails applications you can either put the MOle initialization code in a custom initializer
|
|
98
|
+
ie config/initializers/mole.rb or in your environment file (config/environments/production.rb).
|
|
99
|
+
You will need to make the load_configuration call in your application controller(application.rb) as follows:
|
|
99
100
|
|
|
100
101
|
::Mole.load_mole_configuration rescue nil
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
|
|
103
|
+
In dev env, the MOle will reload the configuration so you can tweak your app on the fly. In production
|
|
104
|
+
env the MOle configuration will be loaded once.
|
|
105
|
+
|
|
103
106
|
* Now you'll need to create a mole.rb specification file to specify the various aspects you'll want
|
|
104
107
|
to inject. This file is specified in the initialize call via the :mole_config tag.
|
|
105
108
|
|
data/lib/mole.rb
CHANGED
|
@@ -191,7 +191,69 @@ unless defined? Mole
|
|
|
191
191
|
#
|
|
192
192
|
def self.load_all_moles_relative_to( mole_dir ) #:nodoc:
|
|
193
193
|
search_me = ::File.join( mole_dir, '**', '*.rb')
|
|
194
|
-
Dir.glob(search_me).sort.each {|rb|
|
|
194
|
+
Dir.glob(search_me).sort.each {|rb| load rb}
|
|
195
195
|
end
|
|
196
|
+
|
|
197
|
+
# Stolen from inflector
|
|
198
|
+
def self.camelize(lower_case_and_underscored_word)
|
|
199
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Fetch all ruby files in the given directory and return a cltn of class names
|
|
203
|
+
def self.find_controller_classes( dir )
|
|
204
|
+
classes = []
|
|
205
|
+
search_me = ::File.expand_path( ::File.join(dir, '*.rb'))
|
|
206
|
+
Dir.glob(search_me).sort.each {|rb| classes << camelize( File.basename( rb, ".rb") ) }
|
|
207
|
+
classes
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# Automatically setup on perf MOle on any classes within a given directory
|
|
211
|
+
# NOTE: this call assumes the controller classes are in all in the path
|
|
212
|
+
def self.auto_perf( dir, &block )
|
|
213
|
+
controller_classes = find_controller_classes( dir )
|
|
214
|
+
controller_classes.each do |class_name|
|
|
215
|
+
clazz = Kernel.const_get( class_name )
|
|
216
|
+
features = ::Mole::Utils::Frameworks.features_for( clazz )
|
|
217
|
+
clazz.mole_perf( :features => features, &block )
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Automatically setup MOle untrapped exception on any classes within a given directory
|
|
222
|
+
# NOTE: this call assumes the controller classes are in all in the path
|
|
223
|
+
def self.auto_unchecked( dir, &block )
|
|
224
|
+
controller_classes = find_controller_classes( dir )
|
|
225
|
+
controller_classes.each do |class_name|
|
|
226
|
+
clazz = Kernel.const_get( class_name )
|
|
227
|
+
features = ::Mole::Utils::Frameworks.features_for( clazz )
|
|
228
|
+
clazz.mole_unchecked( :features => features, &block )
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Automatically setup MOle after filter on any classes within a given directory
|
|
233
|
+
# NOTE: this call assumes the controller classes are in all in the path
|
|
234
|
+
def self.auto_after( dir, &block )
|
|
235
|
+
controller_classes = find_controller_classes( dir )
|
|
236
|
+
controller_classes.each do |class_name|
|
|
237
|
+
clazz = Kernel.const_get( class_name )
|
|
238
|
+
features = ::Mole::Utils::Frameworks.features_for( clazz )
|
|
239
|
+
features.each do |feature|
|
|
240
|
+
clazz.mole_after( :feature => feature, &block )
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# Automatically setup MOle after filter on any classes within a given directory
|
|
246
|
+
# NOTE: this call assumes the controller classes are in all in the path
|
|
247
|
+
def self.auto_before( dir, &block )
|
|
248
|
+
controller_classes = find_controller_classes( dir )
|
|
249
|
+
controller_classes.each do |class_name|
|
|
250
|
+
clazz = Kernel.const_get( class_name )
|
|
251
|
+
features = ::Mole::Utils::Frameworks.features_for( clazz )
|
|
252
|
+
features.each do |feature|
|
|
253
|
+
clazz.mole_before( :feature => feature, &block )
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
196
258
|
end
|
|
197
259
|
end
|
data/lib/mole/module.rb
CHANGED
|
@@ -93,7 +93,7 @@ class Module
|
|
|
93
93
|
# <tt>:interceptor</tt>:: The class name of your interceptor class. If no interceptor block is specified
|
|
94
94
|
# <tt>:method</tt>:: The name of the method to callback the interceptor on
|
|
95
95
|
# once an exception condition has been trapped.
|
|
96
|
-
def mole_before(opts={}, &interceptor)
|
|
96
|
+
def mole_before(opts={}, &interceptor)
|
|
97
97
|
raise "Missing :feature option" if opts[:feature].nil? or opts[:feature].to_s.empty?
|
|
98
98
|
opts[:interceptor] ||= interceptor
|
|
99
99
|
opts[:method] ||= :call
|
|
@@ -133,142 +133,154 @@ class Module
|
|
|
133
133
|
after_mole_filters[feature] << [opts[:interceptor], opts[:method]]
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
|
-
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
# puts "#{k} --> #{v}"
|
|
154
|
-
# end
|
|
155
|
-
# end
|
|
136
|
+
|
|
137
|
+
# ---------------------------------------------------------------------------
|
|
138
|
+
# Dumps moled feature info
|
|
139
|
+
def mole_dump( msg=nil )
|
|
140
|
+
puts "\n------------------------------------------------------------------"
|
|
141
|
+
puts "From #{msg}" if msg
|
|
142
|
+
puts "MOle Info for class <- #{self} ->"
|
|
143
|
+
puts "\nBefore filters"
|
|
144
|
+
before_mole_filters.keys.sort.each { |k| puts "\t#{k} --> #{before_mole_filters[k]}" }
|
|
145
|
+
puts "\nAfter filters"
|
|
146
|
+
after_mole_filters.keys.sort.each { |k| puts "\t#{k} --> #{after_mole_filters[k]}" }
|
|
147
|
+
puts "\nUnchecked filters"
|
|
148
|
+
unchecked_mole_filters.keys.sort.each { |k| puts "\t#{k} --> #{unchecked_mole_filters[k]}" }
|
|
149
|
+
puts "\nPerf filters"
|
|
150
|
+
perf_mole_filters.keys.sort.each { |k| puts "\t#{k} --> #{perf_mole_filters[k]}" }
|
|
151
|
+
puts "---------------------------------------------------------------------\n"
|
|
152
|
+
end
|
|
156
153
|
|
|
157
154
|
# ===========================================================================
|
|
158
|
-
|
|
155
|
+
private
|
|
156
|
+
|
|
157
|
+
# Clear MOle state for this class # Used for testing only
|
|
158
|
+
def mole_clear!
|
|
159
|
+
@before_mole_filters = nil
|
|
160
|
+
@after_mole_filters = nil
|
|
161
|
+
@perf_mole_filters = nil
|
|
162
|
+
@unchecked_mole_filters = nil
|
|
163
|
+
end
|
|
159
164
|
|
|
160
|
-
#
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
# ===========================================================================
|
|
166
|
+
public
|
|
167
|
+
|
|
168
|
+
# -------------------------------------------------------------------------
|
|
169
|
+
# Holds before filters
|
|
170
|
+
def before_mole_filters #:nodoc:
|
|
171
|
+
@before_mole_filters ||= Hash.new{ |h,k| h[k] = [] }
|
|
172
|
+
end
|
|
165
173
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
# -------------------------------------------------------------------------
|
|
175
|
+
# Holds after filters
|
|
176
|
+
def after_mole_filters #:nodoc:
|
|
177
|
+
@after_mole_filters ||= Hash.new{ |h,k| h[k] = [] }
|
|
178
|
+
end
|
|
171
179
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
# Holds unchecked exception filters
|
|
178
|
-
def unchecked_mole_filters #:nodoc:
|
|
179
|
-
@unchecked_mole_filters ||= Hash.new{ |h,k| h[k] = []}
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# Attempt to find singleton class method with given name
|
|
183
|
-
# TODO Figure out how to get method for static signature...
|
|
184
|
-
# def find_public_class_method(method)
|
|
185
|
-
# singleton_methods.each { |name| puts "Looking for #{method}--#{method.class} -- #{name}#{name.class}";return name if name == method }
|
|
186
|
-
# nil
|
|
187
|
-
# end
|
|
180
|
+
# -------------------------------------------------------------------------
|
|
181
|
+
# Holds perf around filters
|
|
182
|
+
def perf_mole_filters #:nodoc:
|
|
183
|
+
@perf_mole_filters ||= Hash.new{ |h,k| h[k] = []}
|
|
184
|
+
end
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
begin
|
|
194
|
-
between = instance_method( method )
|
|
195
|
-
rescue
|
|
196
|
-
# between = find_public_class_method( method )
|
|
197
|
-
raise "Unable to find moled feature `#{method}" unless(between)
|
|
186
|
+
# -------------------------------------------------------------------------
|
|
187
|
+
# Holds unchecked exception filters
|
|
188
|
+
def unchecked_mole_filters #:nodoc:
|
|
189
|
+
@unchecked_mole_filters ||= Hash.new{ |h,k| h[k] = []}
|
|
198
190
|
end
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
191
|
+
|
|
192
|
+
# -------------------------------------------------------------------------
|
|
193
|
+
# Attempt to find singleton class method with given name
|
|
194
|
+
# TODO Figure out how to get method for static signature...
|
|
195
|
+
# def find_public_class_method(method)
|
|
196
|
+
# singleton_methods.each { |name| puts "Looking for #{method}--#{method.class} -- #{name}#{name.class}";return name if name == method }
|
|
197
|
+
# nil
|
|
198
|
+
# end
|
|
199
|
+
|
|
200
|
+
# -------------------------------------------------------------------------
|
|
201
|
+
# Wrap method call
|
|
202
|
+
# TODO Add support for wrapping class methods ??
|
|
203
|
+
def wrap( method ) #:nodoc:
|
|
204
|
+
return if wrapped?( method )
|
|
205
|
+
begin
|
|
206
|
+
between = instance_method( method )
|
|
207
|
+
rescue
|
|
208
|
+
# between = find_public_class_method( method )
|
|
209
|
+
raise "Unable to find moled feature `#{method}" unless(between)
|
|
217
210
|
end
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
211
|
+
code = <<-code
|
|
212
|
+
def #{method}_with_mole (*a, &b)
|
|
213
|
+
key = '#{method}'
|
|
214
|
+
klass = self.class
|
|
215
|
+
between = klass.wrapped[key]
|
|
216
|
+
ret_val = nil
|
|
217
|
+
klass.apply_before_filters( klass.before_mole_filters[key], self, key, *a, &b ) if klass.before_mole_filters[key]
|
|
218
|
+
begin
|
|
219
|
+
elapsed = Benchmark::realtime do
|
|
220
|
+
ret_val = between.bind(self).call( *a, &b )
|
|
221
|
+
end
|
|
222
|
+
klass.apply_perf_filters( elapsed, klass.perf_mole_filters[key], self, key, ret_val, *a, &b ) if klass.perf_mole_filters[key]
|
|
223
|
+
rescue => boom
|
|
224
|
+
klass.apply_unchecked_filters( boom, klass.unchecked_mole_filters[key], self, key, *a, &b ) if klass.unchecked_mole_filters[key]
|
|
225
|
+
raise boom
|
|
226
|
+
end
|
|
227
|
+
klass.apply_after_filters( klass.after_mole_filters[key], self, key, ret_val, *a, &b ) if klass.after_mole_filters[key]
|
|
228
|
+
ret_val
|
|
229
|
+
end
|
|
230
|
+
code
|
|
224
231
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
rescue => ca_boom
|
|
229
|
-
::Mole.logger.error ">>> Mole Error: Before-Filter -- " + ca_boom
|
|
230
|
-
# ca_boom.backtrace.each { |l| ::Mole.logger.error l }
|
|
232
|
+
module_eval code
|
|
233
|
+
alias_method_chain method, "mole"
|
|
234
|
+
wrapped[method.to_s] = between
|
|
231
235
|
end
|
|
232
|
-
|
|
236
|
+
|
|
237
|
+
def apply_before_filters( filters, clazz, key, *a, &b ) #:nodoc:
|
|
238
|
+
begin
|
|
239
|
+
filters.each { |r,m| r.send( m, clazz, key, b, *a ) }
|
|
240
|
+
rescue => ca_boom
|
|
241
|
+
::Mole.logger.error ">>> MOle Failure: Before-Filter -- " + ca_boom
|
|
242
|
+
ca_boom.backtrace.each { |l| ::Mole.logger.error l }
|
|
243
|
+
end
|
|
244
|
+
end
|
|
233
245
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
246
|
+
def apply_after_filters( filters, clazz, key, ret_val, *a, &b ) #:nodoc:
|
|
247
|
+
begin
|
|
248
|
+
filters.each { |r,m| r.send( m, clazz, key, ret_val, b, *a ) }
|
|
249
|
+
rescue => ca_boom
|
|
250
|
+
::Mole.logger.error ">>> MOle Failure: After-Filter -- " + ca_boom
|
|
251
|
+
ca_boom.backtrace.each { |l| ::Mole.logger.error l }
|
|
252
|
+
end
|
|
253
|
+
end
|
|
242
254
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
255
|
+
def apply_perf_filters( elapsed, filters, clazz, key, ret_val, *a, &b ) #:nodoc:
|
|
256
|
+
begin
|
|
257
|
+
if ( elapsed >= Mole.perf_threshold )
|
|
258
|
+
filters.each { |r,m| r.send( m, clazz, key, elapsed, ret_val, b, *a ) }
|
|
259
|
+
end
|
|
260
|
+
rescue => ca_boom
|
|
261
|
+
::Mole.logger.error ">>> MOle Failure: Perf-Filter -- " + ca_boom
|
|
262
|
+
ca_boom.backtrace.each { |l| ::Mole.logger.error l }
|
|
263
|
+
end
|
|
264
|
+
end
|
|
253
265
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
266
|
+
def apply_unchecked_filters( boom, filters, clazz, key, *a, &b ) #:nodoc:
|
|
267
|
+
begin
|
|
268
|
+
filters.each { |r,m| r.send( m, clazz, key, boom, b, *a ) }
|
|
269
|
+
rescue => ca_boom
|
|
270
|
+
::Mole.logger.error ">>> MOle Failure: Unchecked-Filter -- " + ca_boom
|
|
271
|
+
ca_boom.backtrace.each { |l| ::Mole.logger.error l }
|
|
272
|
+
end
|
|
273
|
+
end
|
|
262
274
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
275
|
+
# ---------------------------------------------------------------------------
|
|
276
|
+
# Log wrapped class
|
|
277
|
+
def wrapped #:nodoc:
|
|
278
|
+
@wrapped ||= {}
|
|
279
|
+
end
|
|
268
280
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
# ---------------------------------------------------------------------------
|
|
282
|
+
# Check if method has been wrapped
|
|
283
|
+
def wrapped?(which) #:nodoc:
|
|
284
|
+
wrapped.has_key?(which.to_s)
|
|
285
|
+
end
|
|
274
286
|
end
|