class Sequent::Core::Helpers::MessageHandlerOptionRegistry
Attributes
Public Class Methods
Source
# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 9 def initialize clear_options end
Public Instance Methods
Source
# 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
Calls the options with the given arguments with ‘self` bound to the given context.
Source
# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 33 def clear_options @entries = {} end
Removes all options from the registry.
Source
# 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
Registers a handler for the given option.
Private Instance Methods
Source
# 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
Returns the handler for given option.
Source
# File lib/sequent/core/helpers/message_handler_option_registry.rb, line 53 def option_registered?(name) @entries.key?(name) end
Returns true when an option for the given name is registered, or false otherwise.