Class: Horizon::Context
- Inherits:
-
Object
- Object
- Horizon::Context
- Defined in:
- lib/horizon/context.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/horizon/context.rb', line 5 def store @store end |
Class Method Details
.current ⇒ Object
10 11 12 |
# File 'lib/horizon/context.rb', line 10 def self.current store.current_context end |
.current=(context) ⇒ Object
14 15 16 |
# File 'lib/horizon/context.rb', line 14 def self.current=(context) store.current_context = context end |
.reset! ⇒ Object
18 19 20 |
# File 'lib/horizon/context.rb', line 18 def self.reset! store.current_context = nil end |
.store ⇒ Object
6 7 8 |
# File 'lib/horizon/context.rb', line 6 def self.store @store ||= ThreadLocalContextStore.new end |
Instance Method Details
#add_handler(handler) ⇒ Object
26 27 28 29 30 |
# File 'lib/horizon/context.rb', line 26 def add_handler(handler) handler.events_handled.each do |event| event_map[event] << handler end end |
#event_map ⇒ Object
22 23 24 |
# File 'lib/horizon/context.rb', line 22 def event_map @event_map ||= Hash.new { |h, k| h[k] = Set.new } end |
#publish(event, *args) ⇒ Object
32 33 34 35 36 |
# File 'lib/horizon/context.rb', line 32 def publish(event, *args) event_map[event].each do |handler| handler.handle event, *args end end |