class Aggro::Channel

Private: Provides an interface to communicate with an aggregate or saga.

Only loads the target object when needed.

Public Instance Methods

forward_command(command) click to toggle source
# File lib/aggro/channel.rb, line 5
def forward_command(command)
  target << command if handles_command?(command)
end
handles_command?(command) click to toggle source
# File lib/aggro/channel.rb, line 9
def handles_command?(command)
  target_class.allows? command
end
handles_query?(query) click to toggle source
# File lib/aggro/channel.rb, line 13
def handles_query?(query)
  target_class.responds_to? query
end
run_query(query) click to toggle source
# File lib/aggro/channel.rb, line 17
def run_query(query)
  target.ask query if handles_query? query
end

Private Instance Methods

target() click to toggle source
# File lib/aggro/channel.rb, line 23
def target
  @target ||= begin
    ConcurrentActor.spawn!(
      name: id,
      args: [target_class.new(id)],
      executor: Concurrent.configuration.global_task_pool
    )
  end
end
target_class() click to toggle source
# File lib/aggro/channel.rb, line 33
def target_class
  @target_class ||= ActiveSupport::Inflector.constantize type
end