class Actors::Hub::ActorsProxy
Public Class Methods
new(actors, channels)
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 6 def initialize(actors, channels) raise ArgumentError, "'actors' should be an instance of TypedMap" unless actors.instance_of? TypedMap raise ArgumentError, "'channels' should be an instance of TypedMap" unless channels.instance_of? TypedMap @actors = actors @channels = channels end
Public Instance Methods
[](key)
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 33 def [](key) @actors[key] end
add(actor_name, executable, subscribed_on: [], publishes_to: [])
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 14 def add(actor_name, executable, subscribed_on: [], publishes_to: []) actor = Actor.new(actor_name, executable) @actors.add actor.name, actor subscribed_on.each do |chname| channel = find_or_else_create_channel(chname) channel.subscribers.add actor.name, actor end publishes_to.each do |chname| find_or_else_create_channel(chname) end end
count()
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 41 def count @actors.count end
has?(key)
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 37 def has?(key) @actors.has? key end
keys()
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 29 def keys @actors.keys end
length()
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 45 def length @actors.length end
to_a()
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 49 def to_a @actors.to_a end
to_h()
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 53 def to_h @actors.to_h end
Private Instance Methods
find_or_else_create_channel(chname)
click to toggle source
# File lib/actors/hub/actors_proxy.rb, line 59 def find_or_else_create_channel(chname) return @channels[chname] if @channels.has? chname channel = Channel.new(chname) @channels.add channel.name, channel channel end