Sha256: ffdf202cd2acdd0c3059aaf7b116fd404541d74687b3d1f023eb8c1f8a617a8f

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

module Yoda
  module Model
    # ScopedPath represents a path name written in namespaces.
    # ScopedPath owns lexical scopes where the path is written.
    class ScopedPath
      # @return [Array<Path>] represents namespaces in order of nearness.
      attr_reader :scopes

      # @return [Path]
      attr_reader :path

      # @param path [Path]
      # @return [ScopedPath]
      def self.build(path)
        path.is_a?(ScopedPath) ? path : ScopedPath.new(['Object'], Path.build(path))
      end

      # @param scopes [Array<Path>] represents namespaces in order of nearness.
      # @param path [Path]
      def initialize(scopes, path)
        @scopes = scopes.map { |pa| Path.build(pa) }
        @path = Path.build(path)
      end

      # @param paths [Array<String, Path>]
      # @return [ScopedPath]
      def change_scope(paths)
        self.class.new(paths, path)
      end

      def hash
        [self.class.name, scopes, path].hash
      end

      def ==(another)
        eql?(another)
      end

      def eql?(another)
        another.is_a?(ScopedPath) && path == another.path && scopes == another.scopes
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yoda-language-server-0.7.2 lib/yoda/model/scoped_path.rb
yoda-language-server-0.7.1 lib/yoda/model/scoped_path.rb
yoda-language-server-0.7.0 lib/yoda/model/scoped_path.rb
yoda-language-server-0.6.2 lib/yoda/model/scoped_path.rb
yoda-language-server-0.6.1 lib/yoda/model/scoped_path.rb
yoda-language-server-0.6.0 lib/yoda/model/scoped_path.rb
yoda-language-server-0.5.0 lib/yoda/model/scoped_path.rb
yoda-language-server-0.4.0 lib/yoda/model/scoped_path.rb