Class: Sevgi::Function::Locate
- Inherits:
-
Object
- Object
- Sevgi::Function::Locate
- Defined in:
- lib/sevgi/function/locate.rb
Instance Attribute Summary collapse
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Class Method Summary collapse
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(paths, start = ::Dir.pwd, exclude: nil) ⇒ Locate
constructor
A new instance of Locate.
Constructor Details
#initialize(paths, start = ::Dir.pwd, exclude: nil) ⇒ Locate
Returns a new instance of Locate.
14 15 16 17 18 |
# File 'lib/sevgi/function/locate.rb', line 14 def initialize(paths, start = ::Dir.pwd, exclude: nil) @paths = Array(paths) @start = start @exclude = [*exclude].map { ::File.(it) } unless exclude.nil? end |
Instance Attribute Details
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
12 13 14 |
# File 'lib/sevgi/function/locate.rb', line 12 def exclude @exclude end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
12 13 14 |
# File 'lib/sevgi/function/locate.rb', line 12 def paths @paths end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
12 13 14 |
# File 'lib/sevgi/function/locate.rb', line 12 def start @start end |
Class Method Details
.call(&block) ⇒ Object
6 |
# File 'lib/sevgi/function/locate.rb', line 6 def self.call(*, **, &block) = new(*, **).call(&block) |
Instance Method Details
#call(&block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sevgi/function/locate.rb', line 20 def call(&block) origin = ::Dir.pwd ::Dir.chdir(start) here = ::Dir.pwd until (found = match(&block)) ::Dir.chdir("..") ::Dir.pwd == here ? return : here = ::Dir.pwd end Location[::File.(found, here), found, here] ensure ::Dir.chdir(origin) end |