Class: Nero::PathRootTag

Inherits:
BaseTag show all
Defined in:
lib/nero.rb

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

#coder, #ctx, #options

Instance Method Summary collapse

Methods inherited from BaseTag

[], #args, #config, #init, #init_ctx, #init_with, #tag_name

Methods included from Resolvable

#deep_resolve, #gen_resolve_tryer, #resolve_nested!, #try_resolve

Instance Method Details

#find_up(path, containing) ⇒ Object


242
243
244
245
# File 'lib/nero.rb', line 242

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 ]


226
227
228
# File 'lib/nero.rb', line 226

def init_options(containing:)
  super
end

#resolveObject


230
231
232
233
234
235
236
# File 'lib/nero.rb', line 230

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 #{options[:containing].inspect}).
  ERR
  root_path.join(*super)
end

#root_pathObject


238
239
240
# File 'lib/nero.rb', line 238

def root_path
  find_up(ctx[:yaml_file], options[:containing])
end