mole 1.0.2 → 1.0.3

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/History.txt CHANGED
@@ -1,4 +1,17 @@
1
- == 1.0.0 / 2008-02-13
1
+ == 1.0.0 / 2008-02-04
2
2
 
3
- * 1 major enhancement
4
- * Birthday!
3
+ * 1 Initial drop
4
+ * Converted from rails plugin into gem
5
+ * Retrofited to work with pure ruby, merb and rails env
6
+
7
+ == 1.0.1 / 2008-02-04
8
+
9
+ * 1 Documentation enhancements
10
+
11
+ == 1.0.2 / 2008-02-04
12
+
13
+ * 1 Added Snitch support
14
+
15
+ == 1.0.3 / 2008-02-05
16
+
17
+ * 1 Bug Fixes
data/Manifest.txt CHANGED
@@ -2,7 +2,6 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- bin/mole
6
5
  bin/molify
7
6
  config/database.yml
8
7
  config/test_database.yml
data/README.txt CHANGED
@@ -97,7 +97,7 @@ The MOle allows you to easily
97
97
  any media you'll find suitable. In a rails/merb context, you'll be able to extract session/params information
98
98
  as in this case.
99
99
 
100
- Posts.mole_after( :feature => :show ) { |context, feature, ret, args, block|
100
+ Posts.mole_after( :feature => :show ) { |context, feature, ret, block, *args|
101
101
  # Records the interaction to the database
102
102
  Mole::Moler.mole_it( context, feature,
103
103
  context.session[:user_id], # Retrieves which user performed this action
@@ -115,7 +115,7 @@ The MOle allows you to easily
115
115
  the feature that causes the performance threshold to be triggered. Setting the :email option
116
116
  to true will also send out an email alert.
117
117
 
118
- Posts.mole_perf( :features => merb_actions ) do |context, feature, elapsed_time, args, block|
118
+ Posts.mole_perf( :features => merb_actions ) do |context, feature, elapsed_time, ret, block, *args|
119
119
  user = context.instance_variable_get( "@user" )
120
120
  key = context.params[:key], "N/A"
121
121
  request = context.request.nil? ? "N/A" : context.request.remote_ip,
@@ -132,7 +132,7 @@ The MOle allows you to easily
132
132
  The unchecked exception trap works very similarly to the mole_perf trap. It will pass in
133
133
  the context of the method that triggered the exception.
134
134
 
135
- Posts.mole_unchecked( :features => merb_actions ) do |context, action, boom, args, block|
135
+ Posts.mole_unchecked( :features => merb_actions ) do |context, action, boom, block, *args|
136
136
  sub = context.instance_variable_get("@sub")
137
137
  user_id = "N/A"
138
138
  user_id = sub.user.id if sub and sub.user
data/Rakefile CHANGED
@@ -27,7 +27,6 @@ PROJ.executables = ['molify']
27
27
 
28
28
  PROJ.exclude << %w[.DS_Store$ .swo$ .swp$]
29
29
  PROJ.tests = FileList['test/**/test_*.rb']
30
- PROJ.dependencies = [ ["logging"] ]
31
30
  PROJ.annotation_tags << 'BOZO'
32
31
 
33
32
  desc "Clean up artifact directories"
@@ -43,5 +42,5 @@ end
43
42
  task 'gem:package' => 'manifest:assert'
44
43
 
45
44
 
46
- depend_on "logging" , "= 0.7.0"
45
+ depend_on "logging" , "= 0.7.1"
47
46
  depend_on "activerecord", "= 2.0.2"
data/lib/mole/logger.rb CHANGED
@@ -40,10 +40,10 @@ module Mole
40
40
  # email. If that is not reached before the program
41
41
  # exists then the at_exit handler for logging will flush
42
42
  # the log to smtp.
43
- :email_alerts_to => nil ,
44
- :email_alert_level => :error ,
45
- :email_alert_server => "mail.collectiveintellect.com".freeze ,
46
- :email_alert_buffsize => 200 ,
43
+ :email_alerts_to => nil ,
44
+ :email_alert_level => :error ,
45
+ :email_alert_server => nil ,
46
+ :email_alert_buffsize => 200 ,
47
47
  }
48
48
  end
49
49
 
@@ -122,10 +122,13 @@ module Mole
122
122
  def log_it( context, feature, user_id, args )
123
123
  args ||= "no args"
124
124
  user_id ||= "N/A"
125
- ip_addr, browser_type = MoleLog.log_details( context )
125
+ ip_addr, browser_type = MoleLog.log_details( context )
126
126
  info = []
127
- args.keys.sort { |a,b| a.to_s <=> b.to_s }.each { |k| info << "#{k}=>#{args[k]}" }
128
- self.info( "[#{ip_addr}/#{browser_type}]-- #{context}(#{feature}) --- #{user_id} -> #{info.join( ', ' ) }" )
127
+ args.keys.sort { |a,b| a.to_s <=> b.to_s }.each { |k| info << "#{k}=>#{args[k]}" }
128
+ buff = ""
129
+ buff << "[#{ip_addr}/#{browser_type}]--" if ip_addr and browser_type
130
+ buff << "#{context.class.name}(#{feature}) --- #{user_id} -> #{info.join( ', ' ) }"
131
+ self.info( buff )
129
132
  end
130
133
  end
131
134
  end
data/lib/mole/module.rb CHANGED
@@ -10,7 +10,7 @@ class Module
10
10
  #
11
11
  # Example:
12
12
  #
13
- # MyClass.mole_perf do |context, action, elapsed_time, args|
13
+ # MyClass.mole_perf do |context, action, elapsed_time, ret, block, *args|
14
14
  # Mole::DbMole.perf_it( context.session[:user_id],
15
15
  # :controller => context.class.name,
16
16
  # :action => action,
@@ -27,8 +27,8 @@ class Module
27
27
  # <tt>:interceptor</tt>:: The class name of your interceptor class
28
28
  # <tt>:method</tt>:: The name of the method to callback the interceptor on
29
29
  # once a perf condition has been trapped.
30
- def mole_perf( opts={}, &filter )
31
- opts[:interceptor] ||= filter
30
+ def mole_perf( opts={}, &interceptor )
31
+ opts[:interceptor] ||= interceptor
32
32
  opts[:method] ||= :call
33
33
  opts[:features] ||= instance_methods( false )
34
34
  opts[:features].each do |feature|
@@ -43,7 +43,7 @@ class Module
43
43
  #
44
44
  # Example:
45
45
  #
46
- # MyClass.mole_unchecked do |context, action, boom, args|
46
+ # MyClass.mole_unchecked do |context, action, boom, block, *args|
47
47
  # Mole::Moler.check_it( context.session[:user_id],
48
48
  # :controller => context.class.name,
49
49
  # :action => action,
@@ -62,8 +62,8 @@ class Module
62
62
  # <tt>:interceptor</tt>:: The class name of your interceptor class
63
63
  # <tt>:method</tt>:: The name of the method to callback the interceptor on
64
64
  # once an exception condition has been trapped.
65
- def mole_unchecked( opts={}, &filter )
66
- opts[:interceptor] ||= filter
65
+ def mole_unchecked( opts={}, &interceptor )
66
+ opts[:interceptor] ||= interceptor
67
67
  opts[:method] ||= :call
68
68
  opts[:features] ||= instance_methods( false )
69
69
  opts[:features].each do |feature|
@@ -78,7 +78,7 @@ class Module
78
78
  #
79
79
  # Example:
80
80
  #
81
- # MyClass.mole_before( :feature => :blee ) do |context, feature, *args|
81
+ # MyClass.mole_before( :feature => :blee ) do |context, feature, block, *args|
82
82
  # Mole::Moler.mole_it( context, feature, context.session[:user_id],
83
83
  # :args => args )
84
84
  # end
@@ -93,9 +93,9 @@ 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 = {}, &filter)
96
+ def mole_before(opts={}, &interceptor)
97
97
  raise "Missing :feature option" if opts[:feature].nil? or opts[:feature].to_s.empty?
98
- opts[:interceptor] ||= filter
98
+ opts[:interceptor] ||= interceptor
99
99
  opts[:method] ||= :call
100
100
  feature = opts[:feature].to_s
101
101
  if before_mole_filters[feature].empty?
@@ -110,7 +110,7 @@ class Module
110
110
  #
111
111
  # Example:
112
112
  #
113
- # MyClass.mole_after( :feature => :blee ) do |context, feature, ret_val, *args|
113
+ # MyClass.mole_after( :feature => :blee ) do |context, feature, ret_val, block, *args|
114
114
  # Mole::Moler.mole_it( context, feature, context.session[:user_id],
115
115
  # :args => args )
116
116
  # end
@@ -194,7 +194,7 @@ class Module
194
194
  between = instance_method( method )
195
195
  rescue
196
196
  # between = find_public_class_method( method )
197
- raise NameError unless(between)
197
+ raise "Unable to find moled feature `#{method}" unless(between)
198
198
  end
199
199
  code = <<-code
200
200
  def #{method}_with_mole (*a, &b)
@@ -205,14 +205,14 @@ class Module
205
205
  klass.apply_before_filters( klass.before_mole_filters[key], self, key, *a, &b )
206
206
  begin
207
207
  elapsed = Benchmark::realtime do
208
- ret_val = between.bind(self).call(*a)
208
+ ret_val = between.bind(self).call( *a, &b )
209
209
  end
210
- klass.apply_perf_filters( elapsed, klass.perf_mole_filters[key], self, key, *a, &b )
210
+ klass.apply_perf_filters( elapsed, klass.perf_mole_filters[key], self, key, ret_val, *a, &b )
211
211
  rescue => boom
212
212
  klass.apply_unchecked_filters( boom, klass.unchecked_mole_filters[key], self, key, *a, &b )
213
213
  raise boom
214
214
  end
215
- klass.apply_after_filters( klass.after_mole_filters[key], self, key, *a, &b )
215
+ klass.apply_after_filters( klass.after_mole_filters[key], self, key, ret_val, *a, &b )
216
216
  ret_val
217
217
  end
218
218
  code
@@ -224,26 +224,26 @@ class Module
224
224
 
225
225
  def apply_before_filters( filters, clazz, key, *a, &b ) #:nodoc:
226
226
  begin
227
- filters.each { |r,m| r.send(m, clazz, key, *a, &b) }
227
+ filters.each { |r,m| r.send( m, clazz, key, b, *a ) }
228
228
  rescue => ca_boom
229
229
  ::Mole.logger.error ">>> Mole Error: Before-Filter -- " + ca_boom
230
230
  # ca_boom.backtrace.each { |l| ::Mole.logger.error l }
231
231
  end
232
232
  end
233
233
 
234
- def apply_after_filters( filters, clazz, key, *a, &b ) #:nodoc:
234
+ def apply_after_filters( filters, clazz, key, ret_val, *a, &b ) #:nodoc:
235
235
  begin
236
- filters.each { |r,m| r.send(m, clazz, key, *a, &b) }
236
+ filters.each { |r,m| r.send( m, clazz, key, ret_val, b, *a ) }
237
237
  rescue => ca_boom
238
238
  ::Mole.logger.error ">>> Mole Error: After-Filter -- " + ca_boom
239
239
  # ca_boom.backtrace.each { |l| ::Mole.logger.error l }
240
240
  end
241
241
  end
242
242
 
243
- def apply_perf_filters( elapsed, filters, clazz, key, *a ) #:nodoc:
243
+ def apply_perf_filters( elapsed, filters, clazz, key, ret_val, *a, &b ) #:nodoc:
244
244
  begin
245
245
  if ( elapsed >= Mole.perf_threshold )
246
- filters.each { |r,m| r.send(m, clazz, key, elapsed, *a) }
246
+ filters.each { |r,m| r.send( m, clazz, key, elapsed, ret_val, b, *a ) }
247
247
  end
248
248
  rescue => ca_boom
249
249
  ::Mole.logger.error ">>> Mole Error: Perf-Filter -- " + ca_boom
@@ -253,7 +253,7 @@ class Module
253
253
 
254
254
  def apply_unchecked_filters( boom, filters, clazz, key, *a, &b ) #:nodoc:
255
255
  begin
256
- filters.each { |r,m| r.send(m, clazz, key, boom, *a, &b ) }
256
+ filters.each { |r,m| r.send( m, clazz, key, boom, b, *a ) }
257
257
  rescue => ca_boom
258
258
  ::Mole.logger.error ">>> Mole Error: Unchecked-Filter -- " + ca_boom
259
259
  # ca_boom.backtrace.each { |l| ::Mole.logger.error l }
data/lib/mole/version.rb CHANGED
@@ -2,7 +2,7 @@ module Mole
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  # Returns the version string for the library.
8
8
  #
data/spec/data/blee.rb CHANGED
@@ -14,12 +14,18 @@ class Blee
14
14
  # puts ">>> Blee_No_Args"
15
15
  end
16
16
 
17
- def blee_args( i, p )
18
- # puts ">>> Blee_Args #{i} -- #{p}"
17
+ def blee_args( a, b, c, d )
18
+ # puts ">>> Blee Many Args #{[a,b,c,d].join( "--" )}"
19
+ 20
19
20
  end
20
21
 
21
- def blee_args_ret( p )
22
- "Hello #{p}"
22
+ def blee_block( a, b, c, d, &block )
23
+ # puts ">>> Blee Many Block #{[a,b,c,d,block].join( "--" )}"
24
+ 10
25
+ end
26
+
27
+ def blee_args_ret( a )
28
+ "Hello #{a}"
23
29
  end
24
30
 
25
31
  def blee_raise
@@ -45,6 +45,7 @@ describe MoleLog do
45
45
  log.browser_type.should == "GodZilla"
46
46
  end
47
47
 
48
+ # Test Controller...
48
49
  module Moled
49
50
  class Controller
50
51
  class Request
data/spec/module_spec.rb CHANGED
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), "spec_helper" )
3
3
 
4
4
  describe Module do
5
5
  before( :all ) do
6
- ::Mole.initialize( :perf_threshold => 1 )
6
+ ::Mole.initialize( :perf_threshold => 1, :log_level => :info )
7
7
  require File.join( File.dirname(__FILE__), %w[data blee] )
8
8
  end
9
9
 
@@ -48,19 +48,20 @@ describe Module do
48
48
  CallStackChecker.should_not be_called
49
49
  end
50
50
 
51
- it "should trap mole handler exceptions" do
52
- Blee.mole_before( :feature => :crap_out ) { |context, feature, *args|
53
- raise "Something did crap out"
54
- CallStackChecker.called
55
- }
56
- @blee.crap_out
57
- CallStackChecker.should_not be_called
58
- end
51
+ # it "should trap mole handler exceptions" do
52
+ # Blee.mole_before( :feature => :crap_out ) { |context, feature, *args|
53
+ # raise "Something did crap out"
54
+ # CallStackChecker.called
55
+ # }
56
+ # @blee.crap_out
57
+ # CallStackChecker.should_not be_called
58
+ # end
59
59
 
60
60
  it "should correctly setup a before call" do
61
- Blee.mole_before( :feature => :blee_no_args ) { |context, feature, *args|
61
+ Blee.mole_before( :feature => :blee_no_args ) { |context, feature, block, *args|
62
62
  context.class.should == Blee
63
63
  feature.should == "blee_no_args"
64
+ block.should be_nil
64
65
  args.should have(0).items
65
66
  CallStackChecker.called
66
67
  }
@@ -69,7 +70,7 @@ describe Module do
69
70
  end
70
71
 
71
72
  it "should correctly setup an after call" do
72
- Blee.mole_after( :feature => :blee_no_args ) { |context, feature, *args|
73
+ Blee.mole_after( :feature => :blee_no_args ) { |context, feature, ret_val, block, *args|
73
74
  context.class.should == Blee
74
75
  feature.should == "blee_no_args"
75
76
  args.should have(0).items
@@ -91,40 +92,83 @@ describe Module do
91
92
  end
92
93
 
93
94
  it "should not trap a before call" do
94
- @blee.blee_args( "Hello", "World" )
95
+ @blee.blee_args( "Hello", "World", "Good", "Day" )
95
96
  CallStackChecker.should_not be_called
96
97
  end
97
98
 
98
99
  it "should correctly trap the before call arguments" do
99
- Blee.mole_before( :feature => :blee_args ) { |context, feature, *args|
100
+ Blee.mole_before( :feature => :blee_args ) { |context, feature, block, *args|
100
101
  context.class.should == Blee
101
102
  feature.should == "blee_args"
102
- args.should have(2).items
103
+ args.should have(4).items
103
104
  args[0].should == "Hello"
104
105
  args[1].should == "World"
106
+ args[2].should == "Good"
107
+ args[3].should == "Day"
105
108
  CallStackChecker.called
106
109
  }
107
- @blee.blee_args( "Hello", "World" )
110
+ @blee.blee_args( "Hello", "World", "Good", "Day" )
108
111
  CallStackChecker.should be_called
109
112
  end
113
+
114
+ it "should correctly trap a before call with a block" do
115
+ Blee.mole_before( :feature => :blee_block ) do |context, feature, block, *args|
116
+ context.class.should == Blee
117
+ feature.should == "blee_block"
118
+ block.should_not be_nil
119
+ block.call.should == "Do it already!!"
120
+ args.size.should == 4
121
+ args[0].should == "Hello"
122
+ args[1].should == "World"
123
+ args[2].should == "Good"
124
+ args[3].should == "Day"
125
+ CallStackChecker.called
126
+ end
127
+ @blee.blee_block( "Hello", "World", "Good", "Day" ) { "Do it already!!" } rescue nil
128
+ CallStackChecker.should be_called
129
+ end
110
130
 
111
- it "should correctly trap the after call arguments" do
112
- Blee.mole_after( :feature => :blee_args ) { |context, feature, *args|
131
+ it "should correctly trap the after call with many arguments" do
132
+ Blee.mole_after( :feature => :blee_args ) { |context, feature, ret_val, block, *args|
113
133
  context.class.should == Blee
114
134
  feature.should == "blee_args"
115
- args.size.should == 2
135
+ ret_val.should == 20
136
+ args.size.should == 4
116
137
  args[0].should == "Hello"
117
138
  args[1].should == "World"
139
+ args[2].should == "Good"
140
+ args[3].should == "Day"
118
141
  CallStackChecker.called
119
142
  }
120
- @blee.blee_args( "Hello", "World" )
143
+ @blee.blee_args( "Hello", "World", "Good", "Day" )
121
144
  CallStackChecker.should be_called
122
145
  end
146
+
147
+ it "should correctly trap the after call with a block" do
148
+ Blee.mole_after( :feature => :blee_block ) do |context, feature, ret_val, block, *args|
149
+ context.class.should == Blee
150
+ feature.should == "blee_block"
151
+ block.should_not be_nil
152
+ block.call.should == "Do it already!!"
153
+ ret_val.should == 10
154
+ args.size.should == 4
155
+ args[0].should == "Hello"
156
+ args[1].should == "World"
157
+ args[2].should == "Good"
158
+ args[3].should == "Day"
159
+ CallStackChecker.called
160
+ end
161
+ @blee.blee_block( "Hello", "World", "Good", "Day" ) { "Do it already!!" } rescue nil
162
+ CallStackChecker.should be_called
163
+ end
123
164
 
124
165
  it "should correctly trap a slow call" do
125
- Blee.mole_perf( :features => [:blee_slow] ) do |context, feature, elapsed_time, args, block|
166
+ Blee.mole_perf( :features => [:blee_slow] ) do |context, feature, elapsed_time, ret_val, block, *args|
126
167
  context.class.should == Blee
127
168
  feature.should == "blee_slow"
169
+ ret_val.should == 1
170
+ block.should be_nil
171
+ args.size.should == 0
128
172
  elapsed_time.should > 1
129
173
  CallStackChecker.called
130
174
  end
@@ -133,9 +177,11 @@ describe Module do
133
177
  end
134
178
 
135
179
  it "should trap a private method correctly" do
136
- Blee.mole_after( :feature => :blee_private ) { |context, feature, *args|
180
+ Blee.mole_after( :feature => :blee_private ) { |context, feature, ret_val, block, *args|
137
181
  context.class.should == Blee
138
182
  feature.should == "blee_private"
183
+ ret_val.should == "Hello"
184
+ block.should be_nil
139
185
  args.size.should == 1
140
186
  args[0].should == "Hello"
141
187
  CallStackChecker.called
@@ -145,9 +191,11 @@ describe Module do
145
191
  end
146
192
 
147
193
  it "should trap a protected method correctly" do
148
- Blee.mole_after( :feature => :blee_protected ) { |context, feature, *args|
194
+ Blee.mole_after( :feature => :blee_protected ) { |context, feature, ret_val, block, *args|
149
195
  context.class.should == Blee
150
196
  feature.should == "blee_protected"
197
+ ret_val.should == "Hello"
198
+ block.should be_nil
151
199
  args.size.should == 1
152
200
  args[0].should == "Hello"
153
201
  CallStackChecker.called
@@ -158,9 +206,11 @@ describe Module do
158
206
 
159
207
  it "should mole a static method correctly" do
160
208
  pending do
161
- Blee.mole_after( :feature => :blee_static ) { |context, feature, *args|
209
+ Blee.mole_after( :feature => :blee_static ) { |context, feature, ret_val, block, *args|
162
210
  context.class.should == Blee
163
211
  feature.should == "blee_static"
212
+ ret_val.should be_nil
213
+ block.should be_nil
164
214
  args.size.should == 0
165
215
  CallStackChecker.called
166
216
  }
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: mole
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.2
7
- date: 2008-03-02 00:00:00 -07:00
6
+ version: 1.0.3
7
+ date: 2008-03-06 00:00:00 -07:00
8
8
  summary: A flexible way to track user's interactions within your ruby web applications
9
9
  require_paths:
10
10
  - lib
@@ -33,7 +33,6 @@ files:
33
33
  - Manifest.txt
34
34
  - README.txt
35
35
  - Rakefile
36
- - bin/mole
37
36
  - bin/molify
38
37
  - config/database.yml
39
38
  - config/test_database.yml
@@ -82,7 +81,6 @@ rdoc_options:
82
81
  extra_rdoc_files:
83
82
  - History.txt
84
83
  - README.txt
85
- - bin/mole
86
84
  - bin/molify
87
85
  executables:
88
86
  - molify
@@ -91,15 +89,6 @@ extensions: []
91
89
  requirements: []
92
90
 
93
91
  dependencies:
94
- - !ruby/object:Gem::Dependency
95
- name: logging
96
- version_requirement:
97
- version_requirements: !ruby/object:Gem::Version::Requirement
98
- requirements:
99
- - - ">"
100
- - !ruby/object:Gem::Version
101
- version: 0.0.0
102
- version:
103
92
  - !ruby/object:Gem::Dependency
104
93
  name: logging
105
94
  version_requirement:
@@ -107,7 +96,7 @@ dependencies:
107
96
  requirements:
108
97
  - - "="
109
98
  - !ruby/object:Gem::Version
110
- version: 0.7.0
99
+ version: 0.7.1
111
100
  version:
112
101
  - !ruby/object:Gem::Dependency
113
102
  name: activerecord
data/bin/mole DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(
4
- File.join(File.dirname(__FILE__), '..', 'lib', 'mole'))
5
-
6
- # Put your code here
7
-
8
- # EOF