Class: Nero::PathRootTag
Overview
Construct path relative to some root-path. Root-paths are expected to be ancestors of the yaml-file being parsed. They are found by traversing up and checking for specific files/folders, e.g. '.git' or 'Gemfile'. Any argument is appended to the root-path, constructing a path-instance that may exist.
Instance Attribute Summary
Attributes inherited from BaseTag
Instance Method Summary collapse
- #find_up(path, containing) ⇒ Object
-
#init_options(containing:) ⇒ Object
Config: config.add_tag("path/git_root", klass: PathRootTag[containing: ".git"]) config.add_tag("path/rails_root", klass: PathRootTag[containing: "Gemfile"]).
- #resolve ⇒ Object
- #root_path ⇒ Object
Methods inherited from BaseTag
[], #args, #config, #init, #init_ctx, #tag_name
Methods included from Resolvable
#deep_resolve, #resolve_nested!, #try_resolve
Instance Method Details
#find_up(path, containing) ⇒ Object
366 367 368 369 |
# File 'lib/nero.rb', line 366 def find_up(path, containing) (path = path.parent) until path.root? || (path / containing).exist? path unless path.root? end |
#init_options(containing:) ⇒ Object
Config: config.add_tag("path/git_root", klass: PathRootTag[containing: ".git"]) config.add_tag("path/rails_root", klass: PathRootTag[containing: "Gemfile"])
YAML: project_root: !path/git_root config_path: !path/git_root [ config ]
350 351 352 |
# File 'lib/nero.rb', line 350 def (containing:) super end |
#resolve ⇒ Object
354 355 356 357 358 359 360 |
# File 'lib/nero.rb', line 354 def resolve(**) # TODO validate upfront raise <<~ERR unless root_path #{tag_name}: failed to find root-path (ie an ancestor of #{ctx[:yaml_file]} containing #{[:containing].inspect}). ERR root_path.join(*args).then(&config.fetch(:block, :itself.to_proc)) end |
#root_path ⇒ Object
362 363 364 |
# File 'lib/nero.rb', line 362 def root_path find_up(ctx[:yaml_file], [:containing]) end |