simple-notifier 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +43 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/example/error.rb +69 -0
- data/example/notifier/error/emailer/error_notification.erb +2 -0
- data/lib/notifier/base.rb +76 -0
- data/lib/notifier.rb +39 -0
- data/simple-notifier.gemspec +69 -0
- data/test/helper.rb +18 -0
- data/test/test_error_notifier.rb +25 -0
- metadata +156 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem "shoulda", ">= 0"
|
17
|
+
gem "shoulda-matchers"
|
18
|
+
gem "bundler", "~> 1.0.0"
|
19
|
+
gem "jeweler", "~> 1.5.2"
|
20
|
+
gem "rcov", ">= 0"
|
21
|
+
gem "actionmailer", "~> 2.0"
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (2.3.11)
|
5
|
+
actionpack (= 2.3.11)
|
6
|
+
actionpack (2.3.11)
|
7
|
+
activesupport (= 2.3.11)
|
8
|
+
rack (~> 1.1.0)
|
9
|
+
activesupport (2.3.11)
|
10
|
+
git (1.2.5)
|
11
|
+
jeweler (1.5.2)
|
12
|
+
bundler (~> 1.0.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rack (1.1.0)
|
16
|
+
rake (0.8.7)
|
17
|
+
rcov (0.9.9)
|
18
|
+
shoulda (2.11.3)
|
19
|
+
shoulda-matchers (1.0.0.beta1)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
actionmailer (~> 2.0)
|
26
|
+
bundler (~> 1.0.0)
|
27
|
+
jeweler (~> 1.5.2)
|
28
|
+
rcov
|
29
|
+
shoulda
|
30
|
+
shoulda-matchers
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Alex Agranov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
==simple-notifier - simple type-based notification
|
2
|
+
|
3
|
+
gem install simple-notifier
|
4
|
+
|
5
|
+
simple-notifier offers a simple type-based notification facility modeled much after ActionMailer. You can create Notifier implementations that offer a method for each type of object/class that you would like to notify on via the 'notify!' method.
|
6
|
+
|
7
|
+
For instance:
|
8
|
+
|
9
|
+
class FooNotifier < Notifier::Base
|
10
|
+
|
11
|
+
def bar(somebar, opts={})
|
12
|
+
puts "I just got Foo'd"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class Bar
|
18
|
+
end
|
19
|
+
|
20
|
+
FooNotifier.notify!(Bar.new)
|
21
|
+
|
22
|
+
I just got Foo'd
|
23
|
+
=> nil
|
24
|
+
|
25
|
+
==Examples
|
26
|
+
|
27
|
+
You can find more examples in the /example directory along with corresponding unit tests in /test.
|
28
|
+
|
29
|
+
==Contributing to simple-notifier
|
30
|
+
|
31
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
32
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
33
|
+
* Fork the project
|
34
|
+
* Start a feature/bugfix branch
|
35
|
+
* Commit and push until you are happy with your contribution
|
36
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
37
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2011 Alex Agranov. See LICENSE.txt for
|
42
|
+
further details.
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "simple-notifier"
|
16
|
+
gem.homepage = "http://github.com/alexagranov/simple-notifier"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Allows one to create notification handlers for any type of object.}
|
19
|
+
gem.description = %Q{Inspired by ActionMailer, Notifier offers Notifier::Base, a base class for creating notification handlers on any class or instance of a class. Simply define a method in your handler named after the type of object you would like to create notification events for, substituting any namespace "::" delineation with "_", along with a signature that allows for the object as the first parameter and an optional params hash. Then notify on that object or class by simply calling MyHandler.notify!(myclass, params).}
|
20
|
+
gem.email = "alex@morphogenic.net"
|
21
|
+
gem.authors = ["Alex Agranov"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.add_dependency 'actionmailer', '~> 2.0'
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |test|
|
39
|
+
test.libs << 'test'
|
40
|
+
test.pattern = 'test/**/test_*.rb'
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "notifier #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/example/error.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
This is an Error notifier.
|
3
|
+
|
4
|
+
Create a <object_type> method for each object type you would like to handle notification via the 'notify!(<object>, <params>...)' method.
|
5
|
+
=end
|
6
|
+
module Notifier
|
7
|
+
class Error < Notifier::Base
|
8
|
+
|
9
|
+
=begin rdoc
|
10
|
+
A method to configure the Error Notifier.
|
11
|
+
|
12
|
+
:recipients => <array of email addresses to receive email notifications>
|
13
|
+
:from => <email address to be used for the From: field of email notification>
|
14
|
+
=end
|
15
|
+
def self.configure(opts={})
|
16
|
+
@@recipients = opts[:recipients]
|
17
|
+
@@from = opts[:from]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.recipients
|
21
|
+
@@recipients
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from
|
25
|
+
@@from
|
26
|
+
end
|
27
|
+
|
28
|
+
=begin rdoc
|
29
|
+
Notification handler for Exception. Called via Notifier::Error.notify!(exception).
|
30
|
+
|
31
|
+
Currently, use an internal ActionMailer class to send out an email to the error recipients list about potential problems.
|
32
|
+
=end
|
33
|
+
def exception(exception, opts={})
|
34
|
+
opts[:body] = exception.message + "\n"
|
35
|
+
opts[:body] += exception.backtrace.join("\n") unless exception.backtrace.nil?
|
36
|
+
Emailer.deliver_error_notification(exception.message, opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
=begin rdoc
|
40
|
+
Notification handler for String. Called via Notifier::Error.notify!("some error msg").
|
41
|
+
|
42
|
+
Currently, use an internal ActionMailer class to send out an email to the error recipients list about potential problems.
|
43
|
+
=end
|
44
|
+
def string(msg, opts={})
|
45
|
+
opts[:body] = msg
|
46
|
+
Emailer.deliver_error_notification(msg, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
class ConfigurationError < StandardError
|
52
|
+
end
|
53
|
+
|
54
|
+
class Emailer < ActionMailer::Base
|
55
|
+
self.template_root = File.dirname(__FILE__)
|
56
|
+
self.delivery_method = :test
|
57
|
+
|
58
|
+
def error_notification(error_msg, opts={})
|
59
|
+
raise ConfigurationError.new("Failed to call Notifier::Error.configure with :recipients and/or :from") if Notifier::Error.recipients.nil? or Notifier::Error.from.nil?
|
60
|
+
recipients Notifier::Error.recipients.join(",")
|
61
|
+
from Notifier::Error.from
|
62
|
+
subject error_msg
|
63
|
+
body :body => opts[:body]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
The notifier gem offers a simple framework for type-based notification events.
|
3
|
+
|
4
|
+
Working much like ActionMailer, this base class simply adds a method_missing implementation to child classes that allows delegation of calls to
|
5
|
+
'notify!(object_or_class, params...)' to a method in the child class named after the class type of the first parameter.
|
6
|
+
|
7
|
+
Concrete sub-classes should implement a method named after the class type of the document being notified on - with the convention that the method
|
8
|
+
name is all downcase with '::' replaced with '_'.
|
9
|
+
|
10
|
+
For an example, see Notifier::Error in the /example directory and the corresponding unit test /test/test_error_notifier.rb.
|
11
|
+
=end
|
12
|
+
module Notifier
|
13
|
+
class Base
|
14
|
+
|
15
|
+
private_class_method :new
|
16
|
+
|
17
|
+
class << self
|
18
|
+
|
19
|
+
# allow child class to only respond_to the dynamic method names that we will add/support below...
|
20
|
+
def respond_to?(method_symbol, include_private = false) #:nodoc:
|
21
|
+
matches_dynamic_method?(method_symbol) || super
|
22
|
+
end
|
23
|
+
|
24
|
+
# override method_missing for child classes so that our list of dynamically added method names are recognized. if a particular
|
25
|
+
# dynamically added method name is called, do the appropriate action. For instance, if calling 'notify!', delegate to a method named
|
26
|
+
# after the type of the first passed parameter...
|
27
|
+
def method_missing(method_symbol, *parameters) #:nodoc:
|
28
|
+
if match = matches_dynamic_method?(method_symbol)
|
29
|
+
case match[1]
|
30
|
+
when 'notify!':
|
31
|
+
# support for notifying on Class types rather than just instances...
|
32
|
+
if parameters[0].class == Class
|
33
|
+
method_to_call = parameters[0].to_s.downcase.gsub(/::/,"_")
|
34
|
+
else
|
35
|
+
method_to_call = parameters[0].class.to_s.downcase.gsub(/::/,"_")
|
36
|
+
end
|
37
|
+
new(method_to_call).send!(*parameters)
|
38
|
+
when 'new' then nil
|
39
|
+
else super
|
40
|
+
end
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# our list of supported dynamic method names on child classes...(note these are to be called at class-level)
|
49
|
+
def matches_dynamic_method?(method_name) #:nodoc:
|
50
|
+
method_name = method_name.to_s
|
51
|
+
/^(notify!)$/.match(method_name) || /^(new)$/.match(method_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize(method_name=nil, *parameters)
|
57
|
+
create!(method_name) if method_name
|
58
|
+
end
|
59
|
+
|
60
|
+
def create!(method_name)
|
61
|
+
initialize_defaults(method_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def send!(*parameters)
|
65
|
+
__send__(@type_method, *parameters)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
# Set up any default values
|
70
|
+
def initialize_defaults(method_name)
|
71
|
+
@type_method ||= method_name
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/lib/notifier.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2010-2011 MorphoGenic Corp.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'action_mailer'
|
26
|
+
|
27
|
+
$:.unshift(File.dirname(__FILE__))
|
28
|
+
require 'notifier/base'
|
29
|
+
|
30
|
+
module Notifier #:nodoc:
|
31
|
+
module VERSION #:nodoc:
|
32
|
+
MAJOR = 0 unless defined?(MAJOR)
|
33
|
+
MINOR = 1 unless defined?(MINOR)
|
34
|
+
PATCH = 0 unless defined?(PATCH)
|
35
|
+
|
36
|
+
STRING = [MAJOR, MINOR, PATCH].join('.') unless defined?(STRING)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{simple-notifier}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex Agranov"]
|
12
|
+
s.date = %q{2011-02-11}
|
13
|
+
s.description = %q{Inspired by ActionMailer, Notifier offers Notifier::Base, a base class for creating notification handlers on any class or instance of a class. Simply define a method in your handler named after the type of object you would like to create notification events for, substituting any namespace "::" delineation with "_", along with a signature that allows for the object as the first parameter and an optional params hash. Then notify on that object or class by simply calling MyHandler.notify!(myclass, params).}
|
14
|
+
s.email = %q{alex@morphogenic.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"example/error.rb",
|
28
|
+
"example/notifier/error/emailer/error_notification.erb",
|
29
|
+
"lib/notifier.rb",
|
30
|
+
"lib/notifier/base.rb",
|
31
|
+
"simple-notifier.gemspec",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_error_notifier.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/alexagranov/simple-notifier}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.5.0}
|
39
|
+
s.summary = %q{Allows one to create notification handlers for any type of object.}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_error_notifier.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
52
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<actionmailer>, ["~> 2.0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
+
s.add_dependency(%q<actionmailer>, ["~> 2.0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
s.add_dependency(%q<actionmailer>, ["~> 2.0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'notifier'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'example/error'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'shoulda-matchers'
|
5
|
+
|
6
|
+
class TestErrorNotifier < Test::Unit::TestCase
|
7
|
+
context "the test error notifier" do
|
8
|
+
subject { "TestErrorNotifier" }
|
9
|
+
|
10
|
+
setup do
|
11
|
+
Notifier::Error.configure(:recipients=>["alex@morphogenic.net"], :from=>"notifier@morphogenic.net")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "1 send an email when ErrorNotifier notifies on a String message" do
|
15
|
+
Notifier::Error.notify!("Please read this important message!")
|
16
|
+
end
|
17
|
+
|
18
|
+
should "2 send an email when ErrorNotifier notifies on an Exception" do
|
19
|
+
Notifier::Error.notify!(Exception.new("Notifying on Exception!"))
|
20
|
+
end
|
21
|
+
|
22
|
+
should have_sent_email.with_body(/Please read/)
|
23
|
+
should have_sent_email.with_subject(/Notifying on Exception!/)
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alex Agranov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-11 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
name: shoulda
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 23
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 1.0.0
|
48
|
+
name: bundler
|
49
|
+
version_requirements: *id002
|
50
|
+
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 7
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 5
|
62
|
+
- 2
|
63
|
+
version: 1.5.2
|
64
|
+
name: jeweler
|
65
|
+
version_requirements: *id003
|
66
|
+
prerelease: false
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
name: rcov
|
79
|
+
version_requirements: *id004
|
80
|
+
prerelease: false
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
type: :runtime
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 2
|
91
|
+
- 0
|
92
|
+
version: "2.0"
|
93
|
+
name: actionmailer
|
94
|
+
version_requirements: *id005
|
95
|
+
prerelease: false
|
96
|
+
description: Inspired by ActionMailer, Notifier offers Notifier::Base, a base class for creating notification handlers on any class or instance of a class. Simply define a method in your handler named after the type of object you would like to create notification events for, substituting any namespace "::" delineation with "_", along with a signature that allows for the object as the first parameter and an optional params hash. Then notify on that object or class by simply calling MyHandler.notify!(myclass, params).
|
97
|
+
email: alex@morphogenic.net
|
98
|
+
executables: []
|
99
|
+
|
100
|
+
extensions: []
|
101
|
+
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.rdoc
|
105
|
+
files:
|
106
|
+
- .document
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- example/error.rb
|
114
|
+
- example/notifier/error/emailer/error_notification.erb
|
115
|
+
- lib/notifier.rb
|
116
|
+
- lib/notifier/base.rb
|
117
|
+
- simple-notifier.gemspec
|
118
|
+
- test/helper.rb
|
119
|
+
- test/test_error_notifier.rb
|
120
|
+
has_rdoc: true
|
121
|
+
homepage: http://github.com/alexagranov/simple-notifier
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.5.0
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: Allows one to create notification handlers for any type of object.
|
154
|
+
test_files:
|
155
|
+
- test/helper.rb
|
156
|
+
- test/test_error_notifier.rb
|