Class: Nero::RootPathTag
Instance Method Summary collapse
-
#initialize(containing:) ⇒ RootPathTag
constructor
A new instance of RootPathTag.
- #resolve(args, context:) ⇒ Object
Constructor Details
#initialize(containing:) ⇒ RootPathTag
Returns a new instance of RootPathTag.
5 6 7 |
# File 'lib/nero/root_path_tag.rb', line 5 def initialize(containing:) @containing = containing end |
Instance Method Details
#resolve(args, context:) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nero/root_path_tag.rb', line 9 def resolve(args, context:) relative_path = args[0]&.then { |p| p.empty? ? nil : p } dir = context.dir loop do if File.exist?(File.join(dir, @containing)) return relative_path ? Pathname.new(File.join(dir, relative_path)) : Pathname.new(dir) end parent = File.dirname(dir) if parent == dir context.add_error("could not find #{@containing} in any ancestor of #{context.dir}") return nil end dir = parent end end |