Class: SolidObjects::EffectRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_objects/effect_registry.rb,
sig/generated/lib/solid_objects/effect_registry.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEffectRegistry

Returns a new instance of EffectRegistry.

RBS:

  • () -> void



9
10
11
12
# File 'lib/solid_objects/effect_registry.rb', line 9

def initialize
  @handlers = {}
  @mutex = Mutex.new
end

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.

Returns:

  • (Object)


32
33
34
# File 'lib/solid_objects/effect_registry.rb', line 32

def handlers
  @handlers
end

#mutexObject (readonly)

Returns the value of attribute mutex.

Returns:

  • (Object)


32
33
34
# File 'lib/solid_objects/effect_registry.rb', line 32

def mutex
  @mutex
end

Instance Method Details

#fetch(name) ⇒ Proc

RBS:

  • (String | Symbol) -> Proc

Parameters:

  • (String, Symbol)

Returns:

  • (Proc)


24
25
26
27
28
# File 'lib/solid_objects/effect_registry.rb', line 24

def fetch(name)
  handlers.fetch(name.to_s) do
    raise InvalidActor, "no effect handler registered for #{name.inspect}"
  end
end

#register(name, handler) ⇒ Proc

RBS:

  • (String | Symbol, Proc) -> Proc

Parameters:

  • (String, Symbol)
  • (Proc)

Returns:

  • (Proc)


15
16
17
18
19
20
21
# File 'lib/solid_objects/effect_registry.rb', line 15

def register(name, handler)
  effect_name = name.to_s
  raise ArgumentError, "effect name cannot be empty" if effect_name.empty?

  mutex.synchronize { handlers[effect_name] = handler }
  handler
end