Sha256: 2b54d9da51e0ded4f9edc897e64d87524398d6784d2ad8ffc4b5fb85370691af

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.1.0
# @version 0.4.0
class SmartCore::Container::DependencyResolver::Route
  require_relative 'route/cursor'

  # @since 0.1.0
  include Enumerable

  class << self
    # @param path [String, Symbol]
    # @return [SmartCore::Container::DependencyResolver::Route]
    #
    # @api private
    # @since 0.1.0
    def build(path)
      new(SmartCore::Container::KeyGuard.indifferently_accessable_key(path))
    end

    # @return [Array<String>]
    #
    # @api private
    # @since 0.1.0
    # @version 0.4.0
    def build_path(*path_parts)
      path_parts.join(SmartCore::Container::DependencyResolver::PATH_PART_SEPARATOR)
    end
  end

  # @return [Integer]
  #
  # @api private
  # @since 0.1.0
  attr_reader :size

  # @return [String]
  #
  # @api private
  # @since 0.1.0
  attr_reader :path

  # @param path [String]
  # @return [void]
  #
  # @api private
  # @since 0.1.0
  # @version 0.4.0
  def initialize(path)
    @path = path
    @path_parts = path.split(SmartCore::Container::DependencyResolver::PATH_PART_SEPARATOR).freeze
    @size = @path_parts.size
  end

  # @param block [Block]
  # @yield cursor [SmartCore::Container::DependencyResolver::Route::Cursor]
  # @return [Enumerable]
  #
  # @api private
  # @since 0.1.0
  def each(&block)
    enumerator = Enumerator.new do |yielder|
      path_parts.each_with_index do |path_part, path_part_index|
        cursor = Cursor.new(path_part, path_part_index, self)
        yielder.yield(cursor)
      end
    end

    block_given? ? enumerator.each(&block) : enumerator
  end

  private

  # @return [Array<String>]
  #
  # @api private
  # @since 0.1.0
  attr_reader :path_parts
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
smart_container-0.11.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.10.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.9.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.8.1 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.8.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.7.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.6.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.5.0 lib/smart_core/container/dependency_resolver/route.rb
smart_container-0.4.0 lib/smart_core/container/dependency_resolver/route.rb