Class: Sevgi::Function::Locate
- Inherits:
-
Object
- Object
- Sevgi::Function::Locate
- Defined in:
- lib/sevgi/function/locate.rb
Overview
Locates one of several candidate files by walking upward from an immutable configuration snapshot. Each call observes the filesystem again and returns an owned immutable Location snapshot.
Instance Attribute Summary collapse
-
#exclude ⇒ Array<String>?
readonly
Returns the frozen owned paths ignored during lookup.
-
#paths ⇒ Array<String>
readonly
Returns the frozen owned candidate paths.
-
#start ⇒ String
readonly
Returns the frozen absolute start directory.
Class Method Summary collapse
-
.call(paths, start = Dir.pwd, exclude: nil) {|path| ... } ⇒ Sevgi::Function::Location?
Builds a locator and runs it.
Instance Method Summary collapse
-
#call {|path| ... } ⇒ Sevgi::Function::Location?
Runs the upward lookup.
-
#initialize(paths, start = ::Dir.pwd, exclude: nil) ⇒ void
constructor
Builds an upward file locator.
Constructor Details
#initialize(paths, start = ::Dir.pwd, exclude: nil) ⇒ void
Builds an upward file locator.
59 60 61 62 63 64 |
# File 'lib/sevgi/function/locate.rb', line 59 def initialize(paths, start = ::Dir.pwd, exclude: nil) @paths = Array(paths).map { it.dup.freeze }.freeze @start = ::File.(start).freeze @exclude = [*exclude].map { ::File.(it).freeze }.freeze unless exclude.nil? freeze end |
Instance Attribute Details
#exclude ⇒ Array<String>? (readonly)
Returns the frozen owned paths ignored during lookup.
52 53 54 |
# File 'lib/sevgi/function/locate.rb', line 52 def exclude @exclude end |
#paths ⇒ Array<String> (readonly)
Returns the frozen owned candidate paths.
44 45 46 |
# File 'lib/sevgi/function/locate.rb', line 44 def paths @paths end |
#start ⇒ String (readonly)
Returns the frozen absolute start directory.
48 49 50 |
# File 'lib/sevgi/function/locate.rb', line 48 def start @start end |
Class Method Details
.call(paths, start = Dir.pwd, exclude: nil) {|path| ... } ⇒ Sevgi::Function::Location?
40 |
# File 'lib/sevgi/function/locate.rb', line 40 def self.call(*, **, &block) = new(*, **).call(&block) |
Instance Method Details
#call {|path| ... } ⇒ Sevgi::Function::Location?
Note:
Absolute exclusions are applied before the default or custom matcher.
Runs the upward lookup.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sevgi/function/locate.rb', line 74 def call(&block) validate_start! each_parent(start) do |here| next unless (found = match(here, &block)) slug, file = found return Location.new(file:, slug:, dir: here) end end |