Class: Hooksmith::Configuration
- Inherits:
-
Object
- Object
- Hooksmith::Configuration
- Defined in:
- lib/hooksmith/configuration.rb
Overview
Configuration holds the registry of all processors.
Instance Attribute Summary collapse
-
#event_store_config ⇒ Hooksmith::Config::EventStore
readonly
Configuration for event persistence.
-
#registry ⇒ Hash
readonly
A registry mapping provider symbols to arrays of processor entries.
Instance Method Summary collapse
-
#event_store {|Hooksmith::Config::EventStore| ... } ⇒ Object
Configure event store persistence.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#processors_for(provider, event) ⇒ Array<Hash>
Returns all processor entries for a given provider and event.
-
#provider(provider_name) {|Hooksmith::Config::Provider| ... } ⇒ Object
Groups registrations under a specific provider.
-
#register_processor(provider, event, processor_class_name) ⇒ Object
Direct registration of a processor.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 16 17 |
# File 'lib/hooksmith/configuration.rb', line 13 def initialize # Registry structure: { provider_symbol => [{ event: event_symbol, processor: ProcessorClass }, ...] } @registry = Hash.new { |hash, key| hash[key] = [] } @event_store_config = Hooksmith::Config::EventStore.new end |
Instance Attribute Details
#event_store_config ⇒ Hooksmith::Config::EventStore (readonly)
Returns configuration for event persistence.
11 12 13 |
# File 'lib/hooksmith/configuration.rb', line 11 def event_store_config @event_store_config end |
#registry ⇒ Hash (readonly)
Returns a registry mapping provider symbols to arrays of processor entries.
9 10 11 |
# File 'lib/hooksmith/configuration.rb', line 9 def registry @registry end |
Instance Method Details
#event_store {|Hooksmith::Config::EventStore| ... } ⇒ Object
Configure event store persistence.
61 62 63 |
# File 'lib/hooksmith/configuration.rb', line 61 def event_store yield(@event_store_config) end |
#processors_for(provider, event) ⇒ Array<Hash>
Returns all processor entries for a given provider and event.
43 44 45 |
# File 'lib/hooksmith/configuration.rb', line 43 def processors_for(provider, event) registry[provider.to_sym].select { |entry| entry[:event] == event.to_sym } end |
#provider(provider_name) {|Hooksmith::Config::Provider| ... } ⇒ Object
Groups registrations under a specific provider.
23 24 25 26 27 |
# File 'lib/hooksmith/configuration.rb', line 23 def provider(provider_name) provider_config = Hooksmith::Config::Provider.new(provider_name) yield(provider_config) registry[provider_name.to_sym].concat(provider_config.entries) end |
#register_processor(provider, event, processor_class_name) ⇒ Object
Direct registration of a processor.
34 35 36 |
# File 'lib/hooksmith/configuration.rb', line 34 def register_processor(provider, event, processor_class_name) registry[provider.to_sym] << { event: event.to_sym, processor: processor_class_name } end |