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 a start directory.
Instance Attribute Summary collapse
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#paths ⇒ Array<String>
readonly
Candidate paths.
-
#start ⇒ String
readonly
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.
41 42 43 44 45 |
# File 'lib/sevgi/function/locate.rb', line 41 def initialize(paths, start = ::Dir.pwd, exclude: nil) @paths = Array(paths) @start = ::File.(start) @exclude = [*exclude].map { ::File.(it) } unless exclude.nil? end |
Instance Attribute Details
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
34 |
# File 'lib/sevgi/function/locate.rb', line 34 attr_reader :paths, :start, :exclude |
#paths ⇒ Array<String> (readonly)
Returns candidate paths.
34 35 36 |
# File 'lib/sevgi/function/locate.rb', line 34 def paths @paths end |
#start ⇒ String (readonly)
Returns absolute start directory.
34 |
# File 'lib/sevgi/function/locate.rb', line 34 attr_reader :paths, :start, :exclude |
Class Method Details
.call(paths, start = Dir.pwd, exclude: nil) {|path| ... } ⇒ Sevgi::Function::Location?
26 |
# File 'lib/sevgi/function/locate.rb', line 26 def self.call(*, **, &block) = new(*, **).call(&block) |
Instance Method Details
#call {|path| ... } ⇒ Sevgi::Function::Location?
Runs the upward lookup.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sevgi/function/locate.rb', line 54 def call(&block) validate_start! each_parent(start) do |here| next unless (found = match(here, &block)) slug, file = found return Location[file, slug, here] end end |