rackamole 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -19,4 +19,7 @@
19
19
  0.2.3
20
20
  * Bug fixes
21
21
  * Fixed issue where session or param key falls under the format a.b.c which causes
22
- validation problems in mongoDB. Thanks Rafael!
22
+ validation problems in mongoDB. Thanks Rafael!
23
+
24
+ 0.2.4
25
+ * Breaking off action_mailer dependencies. Now leveraging Pony for sending out email alerts.
data/README.rdoc CHANGED
@@ -40,7 +40,8 @@ interactions and leverage these findings for the next iteration of your applicat
40
40
  * MongoDb + mongo ruby adapter
41
41
  * Twitter4r
42
42
  * Chronic
43
- * Actionmailer
43
+ * Erubis
44
+ * Pony
44
45
 
45
46
  == INSTALL:
46
47
 
data/Rakefile CHANGED
@@ -31,4 +31,5 @@ depend_on "mongo" , ">= 0.17.1"
31
31
  depend_on "mongo_ext" , ">= 0.17.1"
32
32
  depend_on "chronic" , ">= 0.2.3"
33
33
  depend_on "twitter4r" , ">= 0.3.0"
34
- depend_on "actionmailer" , ">= 2.1.0"
34
+ depend_on "erubis" , ">= 2.6.0"
35
+ depend_on "pony" , ">= 0.6"
data/a.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'pony'
3
+
4
+ # :to => ['fernand.galiana@gmail.com', 'fernand@collectiveintellect.com'],
5
+
6
+ result = Pony.mail(
7
+ :from => 'fernand@collectiveintellect.com',
8
+ :to => 'fernand.galiana@gmail.com, fernand@collectiveintellect.com',
9
+ :subject => 'test4',
10
+ :body => "Hello World",
11
+ :via => :smtp,
12
+ :smtp => { :host => "exchange@collectiveintellect.com", :port => 25, : }
13
+ # :user => 'fernand@collectiveintellect.com',
14
+ # :password => '$mistral1',
15
+ # :auth => :plain
16
+ )
17
+
18
+ puts result.inspect
data/lib/rackamole.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Rackamole
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.4'
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -1,45 +1,56 @@
1
- require 'action_mailer'
1
+ require 'pony'
2
+ require 'erubis'
2
3
 
3
4
  module Rackamole::Alert
4
- class Emole < ActionMailer::Base
5
- self.template_root = File.join( File.dirname(__FILE__), %w[templates] )
5
+ class Emole
6
+
7
+ # retrieves erb template dir
8
+ def self.template_root() @template_root ||= File.join( File.dirname(__FILE__), %w[templates] ); end
6
9
 
7
10
  # Send an email notification for particular moled feature. An email will
8
11
  # be sent based on the two configuration :emails and :mail_on defined on the
9
12
  # Rack::Mole component. These specify the to and from addresses and the conditions
10
13
  # that will trigger the email, currently :enabled and :features for the type of
11
- # moled features to track via email. The notification will be sent via actionmailer,
14
+ # moled features to track via email. The notification will be sent via Pony,
12
15
  # so you will need to make sure it is properly configured for your domain.
13
16
  # NOTE: This is just a notification mechanism. All moled event will be either logged
14
17
  # or persisted in the db regardless.
15
18
  #
16
19
  # === Parameters:
17
- # from :: The from address address. Must be a valid domain.
18
- # recipients :: An array of email addresses for recipients to be notified.
20
+ # options :: Hash minimaly containing :from for the from address. Must be a valid domain.
21
+ # :: And a :to, n array of email addresses for recipients to be notified.
19
22
  # args :: The gathered information from the mole.
20
23
  #
21
- def alert( from, recipients, args )
22
- buff = []
24
+ def self.deliver_alert( options, args )
25
+ params = options.clone
26
+ params[:to] = options[:to].join( ", " )
27
+ params[:subject] = "[M()le] (#{alert_type( args )}#{request_time?( args )}) -#{args[:app_name]}@#{args[:host]}- for user #{args[:user_name]}"
23
28
 
24
- dump( buff, args, 0 )
29
+ content = []
30
+ dump( content, args, 0 )
31
+ content = content.join( "\n" )
25
32
 
26
- from from
27
- recipients recipients
28
- subject "[M()le] (#{alert_type( args )}#{request_time?( args )}) -#{args[:app_name]}@#{args[:host]}- for user #{args[:user_name]}"
29
- body :args => args,
30
- :dump => buff.join( "\n" )
33
+ tmpl = File.join( template_root, %w[alert.erb] )
34
+ template = Erubis::Eruby.new( IO.read( tmpl ), :trim => true )
35
+
36
+ output = template.result( binding )
37
+ params[:body] = output
38
+
39
+ Pony.mail( params )
40
+
41
+ output
31
42
  end
32
-
43
+
33
44
  # =========================================================================
34
45
  private
35
46
 
36
47
  # Dump request time if any...
37
- def request_time?( args )
48
+ def self.request_time?( args )
38
49
  args[:type] == Rackamole.perf ? ":#{args[:request_time]}" : ''
39
50
  end
40
51
 
41
52
  # Identify the type of alert...
42
- def alert_type( args )
53
+ def self.alert_type( args )
43
54
  case args[:type]
44
55
  when Rackamole.feature : "Feature"
45
56
  when Rackamole.perf : "Performance"
@@ -48,7 +59,7 @@ module Rackamole::Alert
48
59
  end
49
60
 
50
61
  # Dump args...
51
- def dump( buff, env, level=0 )
62
+ def self.dump( buff, env, level=0 )
52
63
  env.each_pair do |k,value|
53
64
  if value.respond_to?(:each_pair)
54
65
  buff << "%s %-#{40-level}s" % [' '*level,k]
@@ -0,0 +1,9 @@
1
+ A watched feature was triggered in application `<%= args[:app_name] %> on host `<%=args[:host]%>
2
+
3
+ Details...
4
+
5
+ <%= content %>
6
+
7
+ - Your Rackamole
8
+
9
+ This message was generated automatically. Please do not respond directly.
@@ -83,11 +83,12 @@ module Rackamole::Alert
83
83
  ("%4.2f" % time).to_f
84
84
  end
85
85
 
86
- # Truncate for twitt max size
86
+ # Truncate for twitt max size
87
+ # BOZO !! This will be hosed if not 1.9 for multibyte chars
87
88
  def truncate(text, length = 140, truncate_string = "...")
88
89
  return "" if text.nil?
89
- l = length - truncate_string.mb_chars.length
90
- text.mb_chars.length > length ? (text.mb_chars[0...l] + truncate_string).to_s : text
90
+ l = length - truncate_string.size
91
+ text.size > length ? (text[0...l] + truncate_string).to_s : text
91
92
  end
92
93
  end
93
94
  end
@@ -53,8 +53,9 @@ module Rack
53
53
  # ==== BOZO! currently there is not support for throttling or monitoring these alerts.
54
54
  # ==
55
55
  # :email :: The mole can be configured to send out emails bases on interesting mole features.
56
- # This feature uses actionmailer. You must specify a hash with the following keys :from, :to
57
- # and :alert_on options to indicate which mole type your wish to be alerted on.
56
+ # This feature uses Pony to send out the email. You must specify a hash with the following keys :from, :to
57
+ # and :alert_on options to indicate which mole type your wish to be alerted on.
58
+ # See Pony docs for custom options for your emails
58
59
  # ==
59
60
  # :email => { :from => 'fred@acme.com', :to => ['blee@acme.com', 'doh@acme.com'], :alert_on => [Rackamole.perf, Rackamole.fault] }
60
61
  # ==
@@ -153,7 +154,7 @@ module Rack
153
154
  # send email alert ?
154
155
  if alertable?( :email, attrs[:type] )
155
156
  logger.debug ">>> Sending out email on mole type #{attrs[:type]} to #{options[:email][:to].join( ", ")}"
156
- Rackamole::Alert::Emole.deliver_alert( options[:email][:from], options[:email][:to], attrs )
157
+ Rackamole::Alert::Emole.deliver_alert( options[:email], attrs )
157
158
  end
158
159
 
159
160
  # send twitter alert ?
@@ -22,17 +22,17 @@ describe Rackamole::Alert::Emole do
22
22
  describe "#alert" do
23
23
 
24
24
  it "should send a feature email correctly" do
25
- @expected.subject = "[M()le] (Feature) -Test@Fred- for user Fernand"
25
+ # @expected.subject = "[M()le] (Feature) -Test@Fred- for user Fernand"
26
26
  @expected.body = feature_body
27
- Rackamole::Alert::Emole.create_alert( @from, @to, @args ).body_port.to_s.should == @expected.body_port.to_s
27
+ Rackamole::Alert::Emole.deliver_alert( {:from => @from, :to => @to}, @args ).should == @expected.body_port.to_s
28
28
  end
29
29
 
30
30
  it "should send a perf email correctly" do
31
31
  @args[:type] = Rackamole.perf
32
32
  @args[:request_time] = 10.0
33
- @expected.subject = "[M()le] (Performance:10.0) -Test@Fred- for user Fernand"
33
+ # @expected.subject = "[M()le] (Performance:10.0) -Test@Fred- for user Fernand"
34
34
  @expected.body = perf_body
35
- Rackamole::Alert::Emole.create_alert( @from, @to, @args ).body_port.to_s.should == @expected.body_port.to_s
35
+ Rackamole::Alert::Emole.deliver_alert( {:from => @from, :to => @to }, @args ).should == @expected.body_port.to_s
36
36
  end
37
37
 
38
38
  it "should send a fault email correctly" do
@@ -40,9 +40,9 @@ describe Rackamole::Alert::Emole do
40
40
  @args[:fault] = 'Oh Snap!'
41
41
  @args[:stack] = ['fred', 'blee']
42
42
  @args[:params] = { :id => 10 }
43
- @expected.subject = "[M()le] (Fault) -Test@Fred- for user Fernand"
43
+ # @expected.subject = "[M()le] (Fault) -Test@Fred- for user Fernand"
44
44
  @expected.body = fault_body
45
- Rackamole::Alert::Emole.create_alert( @from, @to, @args ).body_port.to_s.should == @expected.body_port.to_s
45
+ Rackamole::Alert::Emole.deliver_alert( { :from => @from, :to => @to }, @args ).should == @expected.body_port.to_s
46
46
  end
47
47
 
48
48
  end
@@ -1,4 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), %w[.. spec_helper])
2
+ require 'action_controller'
2
3
 
3
4
  describe Rack::Mole do
4
5
  include Rack::Test::Methods
@@ -65,7 +66,7 @@ describe Rack::Mole do
65
66
  get "/", nil, @test_env
66
67
  rescue
67
68
  last_request.env['mole.stash'].should_not be_nil
68
- fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
69
+ fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
69
70
  fault.should_not be_nil
70
71
  fault.count.should == 1
71
72
  end
@@ -78,7 +79,7 @@ describe Rack::Mole do
78
79
  get "/", nil, env
79
80
  rescue
80
81
  last_request.env['mole.stash'].should_not be_nil
81
- fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
82
+ fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
82
83
  fault.should_not be_nil
83
84
  fault.count.should == i+1
84
85
  env = last_request.env
@@ -92,9 +93,9 @@ describe Rack::Mole do
92
93
  begin
93
94
  env['PATH_INFO'] = "/#{i}"
94
95
  get "/#{i}", nil, env
95
- rescue
96
+ rescue => boom
96
97
  last_request.env['mole.stash'].should_not be_nil
97
- fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
98
+ fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
98
99
  fault.should_not be_nil
99
100
  fault.count.should == i+1
100
101
  env = last_request.env
@@ -155,7 +156,7 @@ describe Rack::Mole do
155
156
  rescue
156
157
  @test_store.mole_result[:stack].should have(4).items
157
158
  last_request.env['mole.stash'].should_not be_nil
158
- fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
159
+ fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
159
160
  fault.should_not be_nil
160
161
  fault.count.should == 1
161
162
  end
@@ -194,7 +195,7 @@ describe Rack::Mole do
194
195
  @test_store.mole_result[:stack].should have(4).items
195
196
  @test_store.mole_result[:fault].should == 'Oh snap!'
196
197
  last_request.env['mole.stash'].should_not be_nil
197
- fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:189" )
198
+ fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:190" )
198
199
  fault.should_not be_nil
199
200
  fault.count.should == 1
200
201
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,9 @@ require 'rubygems'
2
2
  require 'rack'
3
3
  require 'rack/test'
4
4
 
5
+ require 'active_support'
6
+ require 'action_pack'
7
+
5
8
  require File.join(File.dirname(__FILE__), %w[.. lib rackamole])
6
9
 
7
10
  Spec::Runner.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackamole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernand Galiana
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-08 00:00:00 -07:00
12
+ date: 2010-01-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -73,14 +73,24 @@ dependencies:
73
73
  version: 0.3.0
74
74
  version:
75
75
  - !ruby/object:Gem::Dependency
76
- name: actionmailer
76
+ name: erubis
77
77
  type: :runtime
78
78
  version_requirement:
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 2.1.0
83
+ version: 2.6.0
84
+ version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: pony
87
+ type: :runtime
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0.6"
84
94
  version:
85
95
  - !ruby/object:Gem::Dependency
86
96
  name: bones
@@ -111,13 +121,14 @@ extensions: []
111
121
  extra_rdoc_files:
112
122
  - README.rdoc
113
123
  - aaa.txt
114
- - lib/rackamole/alert/templates/rackamole/alert/emole/alert.erb
124
+ - lib/rackamole/alert/templates/alert.erb
115
125
  - samples/rails/moled/public/robots.txt
116
126
  files:
117
127
  - ...
118
128
  - HISTORY
119
129
  - README.rdoc
120
130
  - Rakefile
131
+ - a.rb
121
132
  - aaa.txt
122
133
  - images/mole_logo.png
123
134
  - images/mole_logo.psd
@@ -125,7 +136,7 @@ files:
125
136
  - images/mole_logo_small.psd
126
137
  - lib/rackamole.rb
127
138
  - lib/rackamole/alert/emole.rb
128
- - lib/rackamole/alert/templates/rackamole/alert/emole/alert.erb
139
+ - lib/rackamole/alert/templates/alert.erb
129
140
  - lib/rackamole/alert/twitt.rb
130
141
  - lib/rackamole/interceptor.rb
131
142
  - lib/rackamole/logger.rb
@@ -1,9 +0,0 @@
1
- A watched feature was triggered in application `<%= @args[:app_name] %> on host `<%=@args[:host]%>
2
-
3
- Details...
4
-
5
- <%= @dump %>
6
-
7
- - Your Rackamole
8
-
9
- This message was generated automatically. Please do not respond directly.