Class: Sequent::Core::Helpers::MessageHandlerOptionRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/core/helpers/message_handler_option_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessageHandlerOptionRegistry

Returns a new instance of MessageHandlerOptionRegistry.



9
10
11
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 9

def initialize
  clear_options
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



7
8
9
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 7

def entries
  @entries
end

Instance Method Details

#call_option(context, name, *args) ⇒ Object

Calls the options with the given arguments with ‘self` bound to the given context.



25
26
27
28
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 25

def call_option(context, name, *args)
  handler = find_option(name)
  context.instance_exec(*args, &handler)
end

#clear_optionsObject

Removes all options from the registry.



33
34
35
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 33

def clear_options
  @entries = {}
end

#register_option(name, handler) ⇒ Object

Registers a handler for the given option.



16
17
18
19
20
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 16

def register_option(name, handler)
  fail ArgumentError, "Option with name '#{name}' already registered" if option_registered?(name)

  @entries[name] = handler
end