Class: Gitlab::EventStore::Store
- Inherits:
-
Object
- Object
- Gitlab::EventStore::Store
- Defined in:
- lib/gitlab/event_store/store.rb
Instance Attribute Summary collapse
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Store
constructor
A new instance of Store.
- #publish(event) ⇒ Object
- #subscribe(worker, to:, if: nil, delay: nil) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Store
Returns a new instance of Store.
8 9 10 11 12 13 14 15 16 |
# File 'lib/gitlab/event_store/store.rb', line 8 def initialize @subscriptions = Hash.new { |h, k| h[k] = [] } yield(self) if block_given? # freeze the subscriptions as safety measure to avoid further # subcriptions after initialization. lock! end |
Instance Attribute Details
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
6 7 8 |
# File 'lib/gitlab/event_store/store.rb', line 6 def subscriptions @subscriptions end |
Instance Method Details
#publish(event) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/gitlab/event_store/store.rb', line 27 def publish(event) unless event.is_a?(Event) raise InvalidEvent, "Event being published is not an instance of Gitlab::EventStore::Event: got #{event.inspect}" end subscriptions.fetch(event.class, []).each do |subscription| subscription.consume_event(event) end end |
#subscribe(worker, to:, if: nil, delay: nil) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/gitlab/event_store/store.rb', line 18 def subscribe(worker, to:, if: nil, delay: nil) condition = binding.local_variable_get('if') Array(to).each do |event| validate_subscription!(worker, event) subscriptions[event] << Gitlab::EventStore::Subscription.new(worker, condition, delay) end end |