Sha256: 7a1fa00a52e025317d822c53374de92c74cb4c2a74c19cbeadde7407b00232cb

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.5.0
class SmartCore::Operation::StepSet
  # @since 0.5.0
  include Enumerable

  # @return [Array<SmartCore:::Operation::Step>]
  #
  # @api private
  # @since 0.5.0
  attr_reader :steps

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

  # @param step [SmartCore::Operation::Step]
  # @return [void]
  #
  # @api private
  # @since 0.5.0
  def add_step(step)
    thread_safe { steps << step }
  end
  alias_method :<<, :add_step

  # @param step_set [SmartCore::Operation::Step]
  # @return [void]
  #
  # @api private
  # @sinec 0.5.0
  def concat(step_set)
    thread_safe { steps.concat(step_set.dup.steps) }
  end

  # @retun [SmartCore::Operation::StepSet]
  #
  # @api private
  # @since 0.5.0
  def dup
    thread_safe do
      self.class.new.tap do |duplicate|
        steps.each { |step| duplicate.add_step(step.dup) }
      end
    end
  end

  # @return [Enumerable]
  #
  # @api private
  # @since 0.5.0
  def each(&block)
    thread_safe { block_given? ? steps.each(&block) : steps.each }
  end

  private

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
smart_core-0.8.1 lib/smart_core/operation/step_set.rb
smart_core-0.8.0 lib/smart_core/operation/step_set.rb
smart_core-0.7.0 lib/smart_core/operation/step_set.rb
smart_core-0.6.0 lib/smart_core/operation/step_set.rb
smart_core-0.5.2 lib/smart_core/operation/step_set.rb
smart_core-0.5.1 lib/smart_core/operation/step_set.rb
smart_core-0.5.0 lib/smart_core/operation/step_set.rb