Class: Nero::RootPathTag
Overview
A Pathname below the nearest ancestor directory (of the YAML file) that contains
containing, e.g. .git for !path/git_root.
root: !path/git_root # the root itself
app: !path/git_root config/app.yml # one relative path
up: !path/git_root [storage, !env TENANT] # segments, joined
Segments are strings or numbers. A nil segment (e.g. a missing !env?), an absolute
segment, a segment leading outside the root (..) or a mapping is an error. The
result is cleaned (config/../lib → lib). The root must exist, the resulting path
needn't.
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.
16 17 18 |
# File 'lib/nero/root_path_tag.rb', line 16 def initialize(containing:) @containing = containing end |
Instance Method Details
#resolve(args, context:) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/nero/root_path_tag.rb', line 20 def resolve(args, context:) error = invalid_args(args) return context.add_error("#{label}: #{error}") && nil if error segments = Array(args).map(&:to_s).reject(&:empty?) root = find_root(context) or return segments.empty? ? root : root.join(*segments).cleanpath end |