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

#initialize(log) ⇒ ActorRegistry

Returns a new instance of ActorRegistry.



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

def initialize(log)
  @log = log
  @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

#logObject (readonly)

Returns the value of attribute log.



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

def log
  @log
end

Instance Method Details

#actor_for(prefix) ⇒ Object



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

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

#register(actor, prefix) ⇒ Object

Raises:

  • (ArgumentError)


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

def register(actor, prefix)
  raise ArgumentError, "#{actor.inspect} is not a Nanite::Actor subclass instance" unless Nanite::Actor === actor
  log.info("Registering #{actor.inspect} with prefix #{prefix.inspect}")
  prefix ||= actor.class.default_prefix
  actors[prefix.to_s] = actor
end

#servicesObject



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

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