Sha256: f4ea2f83997b1bb4f6cf5d62b27e338c10de17c1739631788ecdbb6fb1a8bbec

Contents?: true

Size: 877 Bytes

Versions: 10

Compression:

Stored size: 877 Bytes

Contents

# frozen_string_literal: true

# @api private
# @since 0.13.0
class Qonfig::Settings::Callbacks
  require_relative 'callbacks/validation'

  # @api private
  # @since 0.13.0
  include Enumerable

  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def initialize
    @callbacks = []
    @lock = Mutex.new
  end

  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def call
    thread_safe { callbacks.each(&:call) }
  end

  # @param callback [Proc, Qonfig::Settings::Callbacks, #call]
  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def add(callback)
    thread_safe { callbacks << callback }
  end

  private

  # @return [Array<Proc>]
  #
  # @api private
  # @since 0.13.0
  attr_reader :callbacks

  # @return [Any]
  #
  # @api private
  # @since 0.14.0
  def thread_safe(&block)
    @lock.owned? ? yield : @lock.synchronize(&block)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
qonfig-0.30.0 lib/qonfig/settings/callbacks.rb
qonfig-0.28.0 lib/qonfig/settings/callbacks.rb
qonfig-0.27.0 lib/qonfig/settings/callbacks.rb
qonfig-0.26.0 lib/qonfig/settings/callbacks.rb
qonfig-0.25.0 lib/qonfig/settings/callbacks.rb
qonfig-0.24.1 lib/qonfig/settings/callbacks.rb
qonfig-0.24.0 lib/qonfig/settings/callbacks.rb
qonfig-0.23.0 lib/qonfig/settings/callbacks.rb
qonfig-0.22.0 lib/qonfig/settings/callbacks.rb
qonfig-0.21.0 lib/qonfig/settings/callbacks.rb