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)


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

def initialize(scopes, path)
  @scopes = scopes.map { |pa| Path.build(pa) }
  @path = Path.build(path)
end

Instance Attribute Details

#pathPath (readonly)

Returns:



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

def path
  @path
end

#scopesArray<Path> (readonly)

Returns represents namespaces in order of nearness.

Returns:

  • (Array<Path>)

    represents namespaces in order of nearness.



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

def scopes
  @scopes
end

Class Method Details

.build(path) ⇒ ScopedPath

Parameters:

Returns:



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

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

Instance Method Details

#==(another) ⇒ Object



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

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

#change_scope(paths) ⇒ ScopedPath

Parameters:

  • paths (Array<String, Path>)

Returns:



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

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

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

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