Class: NRSER::Meta::Source::Location
- Inherits:
-
Hamster::Vector
- Object
- Hamster::Vector
- NRSER::Meta::Source::Location
- Includes:
- Props::Immutable::Vector
- Defined in:
- lib/nrser/meta/source/location.rb
Overview
document NRSER::Meta::Source::Location class.
Constant Summary
Constants included from Props::Immutable::Vector
Props::Immutable::Vector::STORAGE
Instance Attribute Summary collapse
-
#file ⇒ String?
readonly
The first entry in the source location array, denoting the file path.
-
#line ⇒ Integer?
readonly
The second entry in the source location array, denoting the line number.
Class Method Summary collapse
-
.for_methods(methods, only_valid: false) ⇒ Hash<Symbol, NRSER::Meta::Source::Location>
Given an Enumerable of Method objects, return a Hash mapping their Method#name to the method’s Location.
Instance Method Summary collapse
-
#initialize(source) ⇒ Location
constructor
Override to allow argument to be ‘nil` for when Method#source_location weirdly returns `nil`.
-
#to_s ⇒ String
A short string describing the instance.
-
#valid? ⇒ Boolean
Do we have a file and a line?.
Methods included from Props::Immutable::Vector
Methods inherited from Hamster::Vector
#as_json, #to_mutable, #to_yaml
Methods included from Ext::Tree
#each_branch, #leaves, #map_branches, #map_leaves, #map_tree
Constructor Details
#initialize(source) ⇒ Location
Override to allow argument to be ‘nil` for when Method#source_location weirdly returns `nil`.
145 146 147 148 149 |
# File 'lib/nrser/meta/source/location.rb', line 145 def initialize source source = source.source_location if source.respond_to? :source_location source = {} if source.nil? super source end |
Instance Attribute Details
#file ⇒ String? (readonly)
The first entry in the source location array, denoting the file path.
90 |
# File 'lib/nrser/meta/source/location.rb', line 90 prop :file, type: t.abs_path?, default: nil, index: 0 |
#line ⇒ Integer? (readonly)
The second entry in the source location array, denoting the line number.
102 |
# File 'lib/nrser/meta/source/location.rb', line 102 prop :line, type: t.pos_int?, default: nil, index: 1 |
Class Method Details
.for_methods(methods, only_valid: false) ⇒ Hash<Symbol, NRSER::Meta::Source::Location>
Given an Enumerable of Method objects, return a Hash mapping their Method#name to the method’s NRSER::Meta::Source::Location.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nrser/meta/source/location.rb', line 65 def self.for_methods methods, only_valid: false all = methods.map { |method| [ method.name, NRSER::Meta::Source::Location.new( method ) ] }.to_h if only_valid all.select { |method, location| location.valid? } else all end end |
Instance Method Details
#to_s ⇒ String
Returns a short string describing the instance.
173 174 175 |
# File 'lib/nrser/meta/source/location.rb', line 173 def to_s "#{ file || '???' }:#{ line || '???' }" end |
#valid? ⇒ Boolean
165 166 167 |
# File 'lib/nrser/meta/source/location.rb', line 165 def valid? !( file.nil? && line.nil? ) end |