Class: Appydave::Tools::AppContext::GlobsLoader
- Inherits:
-
Object
- Object
- Appydave::Tools::AppContext::GlobsLoader
- Defined in:
- lib/appydave/tools/app_context/globs_loader.rb
Overview
Loads and resolves named glob patterns from a context.globs.json file.
Resolution is 3-tier:
1. Direct glob name — "services" → globs["services"]
2. Alias match — "backend" → aliases["backend"] → ["services", "routes"]
3. Composite match — "understand" → composites["understand"] → ["context", "docs", ...]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Instance Method Summary collapse
- #aliases ⇒ Object
- #available? ⇒ Boolean
-
#available_names ⇒ Object
List all available glob names (direct + aliases + composites).
- #composites ⇒ Object
-
#expand(names) ⇒ Object
Resolve multiple names, expand globs against the filesystem, return absolute paths.
- #globs ⇒ Object
-
#initialize(project_path) ⇒ GlobsLoader
constructor
A new instance of GlobsLoader.
- #pattern ⇒ Object
- #project_name ⇒ Object
-
#resolve(name) ⇒ Object
Resolve a single name through the 3-tier hierarchy.
Constructor Details
#initialize(project_path) ⇒ GlobsLoader
Returns a new instance of GlobsLoader.
17 18 19 20 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 17 def initialize(project_path) @project_path = project_path @data = load_globs_file end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 15 def data @data end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
15 16 17 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 15 def project_path @project_path end |
Instance Method Details
#aliases ⇒ Object
30 31 32 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 30 def aliases data&.fetch('aliases', {}) || {} end |
#available? ⇒ Boolean
22 23 24 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 22 def available? !data.nil? end |
#available_names ⇒ Object
List all available glob names (direct + aliases + composites)
47 48 49 50 51 52 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 47 def available_names names = globs.keys.map { |k| { name: k, type: 'glob' } } names += aliases.keys.map { |k| { name: k, type: 'alias' } } names += composites.keys.map { |k| { name: k, type: 'composite' } } names end |
#composites ⇒ Object
34 35 36 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 34 def composites data&.fetch('composites', {}) || {} end |
#expand(names) ⇒ Object
Resolve multiple names, expand globs against the filesystem, return absolute paths.
81 82 83 84 85 86 87 88 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 81 def (names) patterns = names.flat_map { |name| resolve(name) }.uniq patterns.flat_map { |pat| Dir.glob(File.join(project_path, pat)) } .select { |f| File.file?(f) } .uniq .sort end |
#globs ⇒ Object
26 27 28 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 26 def globs data&.fetch('globs', {}) || {} end |
#pattern ⇒ Object
38 39 40 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 38 def pattern data&.fetch('pattern', nil) end |
#project_name ⇒ Object
42 43 44 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 42 def project_name data&.fetch('project', nil) end |
#resolve(name) ⇒ Object
Resolve a single name through the 3-tier hierarchy. Returns an array of raw glob patterns (strings).
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/appydave/tools/app_context/globs_loader.rb', line 56 def resolve(name) name = name.strip.downcase # Tier 1: direct glob name return globs[name] if globs.key?(name) # Tier 2: alias → list of glob names return aliases[name].flat_map { |glob_name| globs[glob_name] || [] } if aliases.key?(name) # Tier 3: composite → list of glob names (or "*" for all) if composites.key?(name) members = composites[name] return globs.values.flatten if members == ['*'] return members.flat_map { |glob_name| resolve_single_glob(glob_name) } end # Tier 4: substring fallback match = find_substring_match(name) return resolve(match) if match [] end |