Class: Rox::Core::ConfigurationFetchedInvoker

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/core/configuration/configuration_fetched_invoker.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_unhandled_error_invoker) ⇒ ConfigurationFetchedInvoker

Returns a new instance of ConfigurationFetchedInvoker.



7
8
9
10
11
12
# File 'lib/rox/core/configuration/configuration_fetched_invoker.rb', line 7

def initialize(user_unhandled_error_invoker)
  @fetched_handlers = []
  @mutex = Mutex.new
  @internal_handler = nil
  @user_unhandled_error_invoker = user_unhandled_error_invoker
end

Instance Method Details

#invoke(fetcher_status, creation_date, has_changes) ⇒ Object



14
15
16
# File 'lib/rox/core/configuration/configuration_fetched_invoker.rb', line 14

def invoke(fetcher_status, creation_date, has_changes)
  raise_fetched_event(Rox::Core::ConfigurationFetchedArgs.new(fetcher_status, creation_date, has_changes))
end

#invoke_error(error_details) ⇒ Object



18
19
20
# File 'lib/rox/core/configuration/configuration_fetched_invoker.rb', line 18

def invoke_error(error_details)
  raise_fetched_event(Rox::Core::ConfigurationFetchedArgs.error(error_details))
end

#raise_fetched_event(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rox/core/configuration/configuration_fetched_invoker.rb', line 32

def raise_fetched_event(args)
  unless @internal_handler.nil?
    @internal_handler.call(args)
  end
  handlers = []
  @mutex.synchronize do
    handlers = @fetched_handlers.clone
  end

  handlers.each do |handler|
    begin
      handler.call(args)
    rescue StandardError => e
      @user_unhandled_error_invoker.invoke(handler, ExceptionTrigger::CONFIGURATION_FETCHED_HANDLER, e)
    end
  end
end

#register_fetched_handler(&block) ⇒ Object



26
27
28
29
30
# File 'lib/rox/core/configuration/configuration_fetched_invoker.rb', line 26

def register_fetched_handler(&block)
  @mutex.synchronize do
    @fetched_handlers << block
  end
end

#register_start_stop_push(block) ⇒ Object



22
23
24
# File 'lib/rox/core/configuration/configuration_fetched_invoker.rb', line 22

def register_start_stop_push(block)
  @internal_handler = block
end