Skip to content
Browse files

List all registered actors with Celluloid::Actor.registered

  • Loading branch information...
1 parent aea3512 commit 4b4adbbf8a76530c38b27247fadc780eec63027b @tarcieri tarcieri committed Nov 29, 2011
Showing with 20 additions and 9 deletions.
  1. +1 −0 CHANGES.md
  2. +9 −4 lib/celluloid/registry.rb
  3. +10 −5 spec/celluloid/registry_spec.rb
View
1 CHANGES.md
@@ -1,5 +1,6 @@
0.6.2
-----
+* List all registered actors with Celluloid::Actor.registered
* All logging now handled through Celluloid::Logger
* Rescue DeadActorError in Celluloid::ActorProxy#inspect
View
13 lib/celluloid/registry.rb
@@ -5,24 +5,29 @@ module Celluloid
module Registry
@@registry = {}
@@registry_lock = Mutex.new
-
+
# Register an Actor
def []=(name, actor)
actor_singleton = class << actor; self; end
unless actor_singleton.ancestors.include?(Celluloid::ActorProxy)
raise ArgumentError, "not an actor"
end
-
+
@@registry_lock.synchronize do
@@registry[name.to_sym] = actor
end
end
-
+
# Retrieve an actor by name
def [](name)
@@registry_lock.synchronize do
@@registry[name.to_sym]
end
end
+
+ # List all registered actors by name
+ def registered
+ @@registry_lock.synchronize { @@registry.keys }
+ end
end
-end
+end
View
15 spec/celluloid/registry_spec.rb
@@ -3,20 +3,25 @@
describe Celluloid::Registry do
class Marilyn
include Celluloid
-
+
def sing_for(person)
"o/~ Happy birthday, #{person}"
end
end
-
+
it "registers Actors" do
- Celluloid::Actor[:marilyn] = Marilyn.spawn
+ Celluloid::Actor[:marilyn] = Marilyn.new
Celluloid::Actor[:marilyn].sing_for("Mr. President").should == "o/~ Happy birthday, Mr. President"
end
-
+
it "refuses to register non-Actors" do
expect do
Celluloid::Actor[:impostor] = Object.new
end.to raise_error(ArgumentError)
end
-end
+
+ it "lists all registered actors" do
+ Celluloid::Actor[:marilyn] = Marilyn.spawn
+ Celluloid::Actor.registered.should include :marilyn
+ end
+end

0 comments on commit 4b4adbb

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