class Sequent::Core::Helpers::MessageHandlerOptionRegistry

Attributes

entries[R]

Public Class Methods

new() click to toggle source
# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 9
def initialize
  clear_options
end

Public Instance Methods

call_option(context, name, *args) click to toggle source

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

# 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_options() click to toggle source

Removes all options from the registry.

# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 33
def clear_options
  @entries = {}
end
register_option(name, handler) click to toggle source

Registers a handler for the given option.

# 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

Private Instance Methods

find_option(name) click to toggle source

Returns the handler for given option.

# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 42
def find_option(name)
  @entries[name] || fail(
    ArgumentError,
    "Unsupported option: '#{name}'; " \
    "#{@entries.keys.any? ? "registered options: #{@entries.keys.join(', ')}" : 'no registered options'}",
  )
end
option_registered?(name) click to toggle source

Returns true when an option for the given name is registered, or false otherwise.

# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 53
def option_registered?(name)
  @entries.key?(name)
end