Class: Nanite::ActorRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/nanite/actor_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActorRegistry

Returns a new instance of ActorRegistry.



5
6
7
# File 'lib/nanite/actor_registry.rb', line 5

def initialize
  @actors = {}
end

Instance Attribute Details

#actorsObject (readonly)

Returns the value of attribute actors.



3
4
5
# File 'lib/nanite/actor_registry.rb', line 3

def actors
  @actors
end

Instance Method Details

#actor_for(prefix) ⇒ Object



22
23
24
# File 'lib/nanite/actor_registry.rb', line 22

def actor_for(prefix)
  actor = actors[prefix]
end

#register(actor, prefix) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
# File 'lib/nanite/actor_registry.rb', line 9

def register(actor, prefix)
  raise ArgumentError, "#{actor.inspect} is not a Nanite::Actor subclass instance" unless Nanite::Actor === actor
  log_msg = "[actor] #{actor.class.to_s}"
  log_msg += ", prefix #{prefix}" if prefix && !prefix.empty?
  Nanite::Log.info(log_msg)
  prefix ||= actor.class.default_prefix
  actors[prefix.to_s] = actor
end

#servicesObject



18
19
20
# File 'lib/nanite/actor_registry.rb', line 18

def services
  actors.map {|prefix, actor| actor.class.provides_for(prefix) }.flatten.uniq
end