Module: Space::Core::Paths
- Defined in:
- lib/space_core/paths.rb
Constant Summary collapse
- TOUCH_FNM =
Flags for matching a changed path against a lane's touch_set globs. PATHNAME keeps a single
*from crossing/; EXTGLOB enables{a,b}; DOTMATCH lets a glob reach dotfile segments, so adir/**touch set coversdir/.github/workflows/ci.yml— the standard deliverable for a lane preparing a directory to become a repo root. File::FNM_PATHNAME | File::FNM_EXTGLOB | File::FNM_DOTMATCH
Class Method Summary collapse
-
.content_tree(root) ⇒ Object
Every path beneath root, at every depth: files, directories, dotfiles, and dot-directory contents all included.
- .contract(path, env: ENV) ⇒ Object
-
.layout_children(dir) ⇒ Object
The direct children of a fixed-depth structured directory layout (one entry per iteration/skill/lane/space) where a leading dot never names a real layout member — only tooling junk (.git, .DS_Store).
- .realpath_or_nil(path) ⇒ Object
-
.touch_match?(glob, path) ⇒ Boolean
Does a single touch_set glob match path? A trailing
dir/**is matched twice: bare (PATHNAME stops it at direct children) and asdir/**/*, whose whole-component**/does cross/.
Class Method Details
.content_tree(root) ⇒ Object
Every path beneath root, at every depth: files, directories, dotfiles, and
dot-directory contents all included. File::FNM_DOTMATCH is what makes
dotfiles visible to Dir.glob, but it also emits a bogus root/.
self-entry — that trap is absorbed here so no callsite has to know about it.
Returns Array
22 23 24 |
# File 'lib/space_core/paths.rb', line 22 def content_tree(root) Dir.glob(File.join(root.to_s, "**", "*"), File::FNM_DOTMATCH).reject { |p| File.basename(p) == "." } end |
.contract(path, env: ENV) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/space_core/paths.rb', line 42 def contract(path, env: ENV) value = path.to_s home = XDG.home(env: env) [home, realpath_or_nil(home)].compact.uniq.each do |h| return "~" if value == h return "~#{value.delete_prefix(h)}" if value.start_with?("#{h}/") end value end |
.layout_children(dir) ⇒ Object
The direct children of a fixed-depth structured directory layout (one
entry per iteration/skill/lane/space) where a leading dot never names a
real layout member — only tooling junk (.git, .DS_Store). Excludes them.
Returns Array
30 31 32 |
# File 'lib/space_core/paths.rb', line 30 def layout_children(dir) Pathname.new(dir).children.reject { |c| c.basename.to_s.start_with?(".") } end |
.realpath_or_nil(path) ⇒ Object
52 53 54 55 56 |
# File 'lib/space_core/paths.rb', line 52 def realpath_or_nil(path) File.realpath(path) rescue SystemCallError nil end |
.touch_match?(glob, path) ⇒ Boolean
Does a single touch_set glob match path? A trailing dir/** is matched
twice: bare (PATHNAME stops it at direct children) and as dir/**/*,
whose whole-component **/ does cross /.
37 38 39 40 |
# File 'lib/space_core/paths.rb', line 37 def touch_match?(glob, path) File.fnmatch(glob, path, TOUCH_FNM) || (glob.end_with?("/**") && File.fnmatch("#{glob}/*", path, TOUCH_FNM)) end |