Sha256: 775d928d1203024a1a7c522fa5b7dd5a1967d16f3e5110baeffcdc4e3f1954cc

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

require "pathname"

# Aruba
module Aruba
  # Pathname for aruba files and directories
  #
  # @private
  class ArubaPath
    def initialize(path)
      @obj = [path.to_s].flatten
    end

    def to_str
      to_pathname.to_s
    end

    def to_s
      to_str
    end

    # Add directory/file to path
    #
    # @param [String] p
    #   The path to be added
    #
    # @example
    #   path = ArubaPath.new 'path/to/dir.d'
    #   path << 'subdir.d
    #   # or path.push 'subdir.d
    #   puts path
    #   # => path/to/dir.d/subdir.d
    def push(p)
      @obj << p
    end
    alias << push

    # Remove last pushed component of path
    #
    # @example
    #   path = ArubaPath.new 'path/to'
    #   path.push 'dir'
    #   path.pop
    #   puts path # => path/to
    def pop
      @obj.pop
    end

    # Return string at index
    #
    # @param [Integer, Range] index
    def [](index)
      to_s[index]
    end

    private

    # Get path
    def to_pathname
      current_path = @obj.inject do |path, element|
        if element.start_with?("~") ||
           Aruba.platform.absolute_path?(element)
          element
        else
          File.join(path, element)
        end
      end
      ::Pathname.new(current_path)
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/aruba_path.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/aruba_path.rb
aruba-2.2.0 lib/aruba/aruba_path.rb
aruba-2.1.0 lib/aruba/aruba_path.rb
aruba-2.0.1 lib/aruba/aruba_path.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/aruba-2.0.0/lib/aruba/aruba_path.rb
aruba-2.0.0 lib/aruba/aruba_path.rb
aruba-1.1.2 lib/aruba/aruba_path.rb
aruba-1.1.1 lib/aruba/aruba_path.rb
aruba-1.1.0 lib/aruba/aruba_path.rb