Sha256: 1b2ed13341194298db2f260c45bca4fadd54780c7ae4211f7bd6789e4b7c879f

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.13.0
class Qonfig::Validator::Collection
  # @api private
  # @since 0.13.0
  include Enumerable

  # @return [Array<Qonfig::Validator::MethodBased,Qonfig::Validator::ProcBased>]
  #
  # @api private
  # @since 0.13.0
  attr_reader :validators

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

  # @param validator [Qonfig::Validator::MethodBased, Qonfig::Validator::ProcBased]
  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def add_validator(validator)
    thread_safe { validators << validator }
  end
  alias_method :<<, :add_validator

  # @param block [Proc]
  # @return [Enumerable]
  #
  # @api private
  # @since 0.13.0
  def each(&block)
    thread_safe { block_given? ? validators.each(&block) : validators.each }
  end

  # @param collection [Qonfig::Validator::Collection]
  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def concat(collection)
    thread_safe { validators.concat(collection.validators) }
  end

  # @return [Qonfig::Validator::Collection]
  #
  # @api private
  # @since 0.13.0
  def dup
    thread_safe do
      self.class.new.tap { |duplicate| duplicate.concat(self) }
    end
  end

  private

  # @param block [Proc]
  # @return [Any]
  #
  # @api private
  # @since 0.13.0
  def thread_safe(&block)
    @access_lock.synchronize(&block)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
qonfig-0.19.1 lib/qonfig/validator/collection.rb
qonfig-0.19.0 lib/qonfig/validator/collection.rb
qonfig-0.18.1 lib/qonfig/validator/collection.rb
qonfig-0.18.0 lib/qonfig/validator/collection.rb
qonfig-0.17.0 lib/qonfig/validator/collection.rb
qonfig-0.16.0 lib/qonfig/validator/collection.rb
qonfig-0.15.0 lib/qonfig/validator/collection.rb
qonfig-0.14.0 lib/qonfig/validator/collection.rb
qonfig-0.13.0 lib/qonfig/validator/collection.rb