Sha256: 211a14140a08521d70830ffd4fc39cb74a222937152461a573878147338fd2a4

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

module Protoboard
  module Adapters
    ##
    # This class is responsible to encapsulate every action that are commom between all adapters
    class BaseAdapter
      class << self
        ##
        # Manages the execution of the code intended to run before circuit execution
        def execute_before_circuit_callbacks(circuit_execution)
          before_global_callback(circuit_execution)
          before_circuit_callback(circuit_execution)
        end

        ##
        # Manages the execution of the code intended to run after circuit execution
        def execute_after_circuit_callbacks(circuit_execution)
          after_global_callback(circuit_execution)
          after_circuit_callback(circuit_execution)
        end

        private
        ##
        # Calls the code intended to run before all circuit execution
        def before_global_callback(circuit_execution)
          Protoboard.config.callbacks.before.each do |callback|
            callback.call(circuit_execution)
          end
        end

        ##
        # Calls the code intended to run before a circuit execution
        def before_circuit_callback(circuit_execution)
          circuit_execution.circuit.on_before.each do |callback|
            callback.call(circuit_execution)
          end
        end

        ##
        # Calls the code intended to run after all circuit execution
        def after_global_callback(circuit_execution)
          Protoboard.config.callbacks.after.each do |callback|
            callback.call(circuit_execution)
          end
        end

        ##
        # Calls the code intended to run after a circuit execution
        def after_circuit_callback(circuit_execution)
          circuit_execution.circuit.on_after.each do |callback|
            callback.call(circuit_execution)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
protoboard-0.2.3 lib/protoboard/adapters/base_adapter.rb
protoboard-0.2.2 lib/protoboard/adapters/base_adapter.rb
protoboard-0.2.1 lib/protoboard/adapters/base_adapter.rb
protoboard-0.2.0 lib/protoboard/adapters/base_adapter.rb
protoboard-0.1.5 lib/protoboard/adapters/base_adapter.rb
protoboard-0.1.4 lib/protoboard/adapters/base_adapter.rb
protoboard-0.1.3 lib/protoboard/adapters/base_adapter.rb
protoboard-0.1.2 lib/protoboard/adapters/base_adapter.rb
protoboard-0.1.1 lib/protoboard/adapters/base_adapter.rb