Class: Omnes::Subscriber::State Private

Inherits:
Object
  • Object
show all
Defined in:
lib/omnes/subscriber/state.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(autodiscover_strategy:, subscription_definitions: [], calling_cache: []) ⇒ State

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of State.



18
19
20
21
22
# File 'lib/omnes/subscriber/state.rb', line 18

def initialize(autodiscover_strategy:, subscription_definitions: [], calling_cache: [])
  @subscription_definitions = subscription_definitions
  @calling_cache = calling_cache
  @autodiscover_strategy = autodiscover_strategy
end

Instance Attribute Details

#autodiscover_strategyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/omnes/subscriber/state.rb', line 11

def autodiscover_strategy
  @autodiscover_strategy
end

#calling_cacheObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/omnes/subscriber/state.rb', line 11

def calling_cache
  @calling_cache
end

#subscription_definitionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/omnes/subscriber/state.rb', line 11

def subscription_definitions
  @subscription_definitions
end

Class Method Details

.IdType(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/omnes/subscriber/state.rb', line 14

def self.IdType(value)
  value.respond_to?(:call) ? value : ->(_instance) { value }
end

Instance Method Details

#add_subscription_definition(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/omnes/subscriber/state.rb', line 36

def add_subscription_definition(&block)
  @subscription_definitions << block
end

#call(bus, instance) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omnes/subscriber/state.rb', line 24

def call(bus, instance)
  raise MultipleSubscriberSubscriptionAttemptError if already_called?(bus, instance)

  all_subscription_definitions = subscription_definitions + autodiscovered_subscription_definitions(bus, instance)

  definitions = all_subscription_definitions.map { |defn| defn.(bus, instance) }

  subscribe_definitions(definitions, bus, instance).tap do
    mark_as_called(bus, instance)
  end
end