Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Configure Orchestra on initialization.

  • Loading branch information...
commit aeaabc6d2d6f9faaa98057f33c0635d8add54461 1 parent 8f59d7a
@josevalim josevalim authored
View
11 railties/lib/rails/application.rb
@@ -487,5 +487,16 @@ def new
Rails::Generators.options.deep_merge! config.generators.options
end
end
+
+ # For each framework, search for instrument file with Orchestra hooks.
+ #
+ initializer :load_orchestra_instrumentation do
+ config.frameworks.each do |framework|
+ begin
+ require "#{framework}/instrument"
+ rescue LoadError => e
+ end
+ end
+ end
end
end
View
8 railties/lib/rails/configuration.rb
@@ -290,6 +290,14 @@ def generators
end
end
+ # Allows Orchestra queue to be modified.
+ #
+ # config.orchestra.queue = MyNewQueue.new
+ #
+ def orchestra
+ ActiveSupport::Orchestra
+ end
+
class Generators #:nodoc:
attr_accessor :aliases, :options, :colorize_logging
View
49 railties/test/application/orchestra_test.rb
@@ -0,0 +1,49 @@
+require "isolation/abstract_unit"
+require "active_support/orchestra"
+
+module ApplicationTests
+ class OrchestraTest < Test::Unit::TestCase
+
+ class MyQueue
+ attr_reader :events, :subscribers
+
+ def initialize
+ @events = []
+ @subscribers = []
+ end
+
+ def publish(name, payload=nil)
+ @events << name
+ end
+
+ def subscribe(pattern=nil, &block)
+ @subscribers << pattern
+ end
+ end
+
+ def setup
+ build_app
+ boot_rails
+
+ Rails::Initializer.run do |c|
+ c.orchestra.queue = MyQueue.new
+ c.orchestra.subscribe(/listening/) do
+ puts "Cool"
+ end
+ end
+ end
+
+ test "new queue is set" do
+ ActiveSupport::Orchestra.instrument(:foo)
+ assert_equal :foo, ActiveSupport::Orchestra.queue.events.first
+ end
+
+ test "frameworks subscribers are loaded" do
+ assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == "sql" }
+ end
+
+ test "configuration subscribers are loaded" do
+ assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == /listening/ }
+ end
+ end
+end

2 comments on commit aeaabc6

@apacala

Wasn't Orchestra renamed to Notifications recently?

@josevalim
Owner

I reverted to merge with my fork and then changed to Notifications once again.

Please sign in to comment.
Something went wrong with that request. Please try again.