Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move notifier registering logic into one place

  • Loading branch information...
commit 6e60639c9841f41562e17b690d185d204396b474 1 parent 728b832
@sr sr authored
View
25 lib/integrity.rb
@@ -40,17 +40,6 @@ def self.new(config=nil)
DataMapper.setup(:default, self.config[:database_uri])
end
- def self.register_notifier(klass)
- raise ArgumentError unless valid_notifier?(klass)
-
- self.notifiers[klass.to_s.split(":").last] = klass
- end
-
- def self.notifiers
- @notifiers ||= {}
- @notifiers
- end
-
def self.default_configuration
@defaults ||= { :database_uri => "sqlite3::memory:",
:export_directory => "/tmp/exports",
@@ -80,15 +69,9 @@ def self.logger
end
private_class_method :logger
- def self.valid_notifier?(notifier)
- notifier.respond_to?(:to_haml) && notifier.respond_to?(:notify_of_build) &&
- notifier != Notifier::Base
- end
- private_class_method :valid_notifier?
-
- class LogFormatter < Logger::Formatter
- def call(severity, time, progname, msg)
- time.strftime("[%H:%M:%S] ") + msg2str(msg) + "\n"
- end
+ class LogFormatter < Logger::Formatter
+ def call(severity, time, progname, msg)
+ time.strftime("[%H:%M:%S] ") + msg2str(msg) + "\n"
end
+ end
end
View
15 lib/integrity/notifier.rb
@@ -15,13 +15,22 @@ class Notifier
validates_is_unique :name, :scope => :project_id
validates_present :project_id
+ def self.available
+ @@_notifiers ||= {}
+ @@_notifiers
+ end
+
def self.register(klass)
- Integrity.register_notifier(klass)
+ raise ArgumentError unless valid?(klass)
+
+ available[klass.to_s.split(":").last] = klass
end
- def self.available
- Integrity.notifiers
+ def self.valid?(notifier)
+ notifier.respond_to?(:to_haml) && notifier.respond_to?(:notify_of_build) &&
+ notifier != Notifier::Base
end
+ private_class_method :valid?
def notify_of_build(build)
to_const.notify_of_build(build, config)
View
3  test/helpers.rb
@@ -77,8 +77,9 @@ class << self
Notifier.available.each { |n|
Notifier.send(:remove_const, n.to_s.split(":").last.to_sym)
}
+
+ Notifier.available.clear
Integrity.instance_variable_set(:@config, nil)
- Integrity.instance_variable_set(:@notifiers, nil)
end
after(:each) do
View
17 test/unit/integrity_test.rb
@@ -32,21 +32,4 @@ class IntegrityTest < Test::Unit::TestCase
Integrity.config[:foo] = "bar"
Integrity.config[:foo].should == "bar"
end
-
- describe "Registering a notifier" do
- it "registers given notifier class" do
- load "helpers/acceptance/textfile_notifier.rb"
-
- Integrity.register_notifier(Integrity::Notifier::Textfile)
- assert_equal Integrity::Notifier::Textfile, Integrity.notifiers["Textfile"]
- end
-
- it "raises ArgumentError if given class is not a valid notifier" do
- assert_raise(ArgumentError) {
- Integrity.register_notifier(Class.new)
- }
-
- assert Integrity.notifiers.empty?
- end
- end
end
View
20 test/unit/notifier_test.rb
@@ -66,11 +66,23 @@ class NotifierTest < Test::Unit::TestCase
end
end
- test "managing available notifiers" do
- Notifier.gen(:irc)
- Notifier.register(Integrity::Notifier::IRC)
+ describe "Registering a notifier" do
+ it "registers given notifier class" do
+ load "helpers/acceptance/textfile_notifier.rb"
+
+ Notifier.register(Integrity::Notifier::Textfile)
+
+ assert_equal Integrity::Notifier::Textfile,
+ Notifier.available["Textfile"]
+ end
+
+ it "raises ArgumentError if given class is not a valid notifier" do
+ assert_raise(ArgumentError) {
+ Notifier.register(Class.new)
+ }
- assert_equal 1, Notifier.available.size
+ assert Notifier.available.empty?
+ end
end
it "knows how to notify the world of a build" do
Please sign in to comment.
Something went wrong with that request. Please try again.