Class: Sequent::Core::Helpers::MessageHandlerOptionRegistry
- Inherits:
-
Object
- Object
- Sequent::Core::Helpers::MessageHandlerOptionRegistry
- Defined in:
- lib/sequent/core/helpers/message_handler_option_registry.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
-
#call_option(context, name, *args) ⇒ Object
Calls the options with the given arguments with ‘self` bound to the given context.
-
#clear_options ⇒ Object
Removes all options from the registry.
-
#initialize ⇒ MessageHandlerOptionRegistry
constructor
A new instance of MessageHandlerOptionRegistry.
-
#register_option(name, handler) ⇒ Object
Registers a handler for the given option.
Constructor Details
#initialize ⇒ MessageHandlerOptionRegistry
Returns a new instance of MessageHandlerOptionRegistry.
9 10 11 |
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 9 def initialize end |
Instance Attribute Details
#entries ⇒ Object (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_options ⇒ Object
Removes all options from the registry.
33 34 35 |
# File 'lib/sequent/core/helpers/message_handler_option_registry.rb', line 33 def @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 |