lib/emittance/brokerage.rb in emittance-0.0.4 vs lib/emittance/brokerage.rb in emittance-0.0.5
- old
+ new
@@ -14,37 +14,43 @@
# @param broker_id [Symbol] a symbol that can be used to identify a broker by
def send_event(event)
broker.process_event event
end
+ # @return [Class] the currently selected broker
def broker
@current_broker
end
+ # @param identifier [Symbol] the symbol you have registered the broker to
def use_broker(identifier)
@current_broker = registry.fetch identifier
end
# @param broker [Emittance::Broker] the broker you would like to register
- def register_broker(broker)
- registry.register broker
+ def register_broker(broker, symbol)
+ registry.register broker, symbol
end
+ # @return [Module] the registry containing all broker registrations
def registry
Emittance::Brokerage::Registry
end
+ # Enables event propagation.
def enable!
- @enabled = true
+ self.enabled = true
end
+ # Disables event propagation.
def disable!
- @enabled = false
+ self.enabled = false
end
+ # @return [Boolean] true if event propagation is enabled, false otherwise
def enabled?
- @enabled
+ enabled
end
private
attr_accessor :enabled
@@ -53,27 +59,17 @@
# @private
module Registry
@brokers = {}
class << self
- include Emittance::Helpers::StringHelpers
-
attr_reader :brokers
- def register(broker)
- broker_sym = generate_broker_sym(broker)
- brokers[broker_sym] = broker
+ def register(broker, symbol)
+ brokers[symbol.to_sym] = broker
end
def fetch(broker_id)
brokers[broker_id.to_sym]
- end
-
- private
-
- def generate_broker_sym(broker)
- camel_case = broker.name.split('::').last
- snake_case(camel_case).to_sym
end
end
end
end
end