Class: Yoda::Model::ScopedPath

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/model/scoped_path.rb

Overview

ScopedPath represents a path name written in namespaces. ScopedPath owns lexical scopes where the path is written.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scopes, path) ⇒ ScopedPath

Returns a new instance of ScopedPath.

Parameters:

  • scopes (Array<Path>)

    represents namespaces in order of nearness.

  • path (Path)


21
22
23
24
# File 'lib/yoda/model/scoped_path.rb', line 21

def initialize(scopes, path)
  @scopes = LexicalContext.build(scopes)
  @path = Path.build(path)
end

Instance Attribute Details

#pathPath (readonly)

Returns:



11
12
13
# File 'lib/yoda/model/scoped_path.rb', line 11

def path
  @path
end

#scopesLexicalContext (readonly) Also known as: lexical_context

Returns represents namespaces in order of nearness.

Returns:



7
8
9
# File 'lib/yoda/model/scoped_path.rb', line 7

def scopes
  @scopes
end

Class Method Details

.build(path) ⇒ ScopedPath

Parameters:

Returns:



15
16
17
# File 'lib/yoda/model/scoped_path.rb', line 15

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

Instance Method Details

#==(another) ⇒ Object



36
37
38
# File 'lib/yoda/model/scoped_path.rb', line 36

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

#absolute_pathsArray<Path>

Returns:



45
46
47
# File 'lib/yoda/model/scoped_path.rb', line 45

def absolute_paths
  scopes.map { |scope| Path.from_names([scope, path]).absolute! }
end

#change_scope(paths) ⇒ ScopedPath

Parameters:

  • paths (Array<String, Path>)

Returns:



28
29
30
# File 'lib/yoda/model/scoped_path.rb', line 28

def change_scope(paths)
  self.class.new(paths, path)
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/yoda/model/scoped_path.rb', line 40

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

#hashObject



32
33
34
# File 'lib/yoda/model/scoped_path.rb', line 32

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

#pathsArray<Path>

Returns:



50
51
52
# File 'lib/yoda/model/scoped_path.rb', line 50

def paths
  scopes.map { |scope| Path.from_names([scope, path]) }
end