Class: Yoda::Model::ScopedPath
- Inherits:
-
Object
- Object
- Yoda::Model::ScopedPath
- 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
- #path ⇒ Path readonly
-
#scopes ⇒ LexicalContext
(also: #lexical_context)
readonly
Represents namespaces in order of nearness.
Class Method Summary collapse
Instance Method Summary collapse
- #==(another) ⇒ Object
- #absolute_paths ⇒ Array<Path>
- #change_scope(paths) ⇒ ScopedPath
- #eql?(another) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(scopes, path) ⇒ ScopedPath
constructor
A new instance of ScopedPath.
- #paths ⇒ Array<Path>
Constructor Details
#initialize(scopes, path) ⇒ ScopedPath
Returns a new instance of ScopedPath.
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
#scopes ⇒ LexicalContext (readonly) Also known as: lexical_context
Returns 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
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_paths ⇒ Array<Path>
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
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
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 |
#hash ⇒ Object
32 33 34 |
# File 'lib/yoda/model/scoped_path.rb', line 32 def hash [self.class.name, scopes, path].hash end |
#paths ⇒ Array<Path>
50 51 52 |
# File 'lib/yoda/model/scoped_path.rb', line 50 def paths scopes.map { |scope| Path.from_names([scope, path]) } end |