Class: Ace::Support::Nav::Molecules::HandbookScanner
- Inherits:
-
Object
- Object
- Ace::Support::Nav::Molecules::HandbookScanner
- Defined in:
- lib/ace/support/nav/molecules/handbook_scanner.rb
Overview
Scans and indexes available handbooks
Instance Method Summary collapse
- #find_resources_in_source(source, protocol, pattern = "*") ⇒ Object
-
#initialize(gem_resolver: nil, path_normalizer: nil, config_loader: nil) ⇒ HandbookScanner
constructor
A new instance of HandbookScanner.
- #scan_all_sources ⇒ Object
- #scan_source_by_alias(alias_name) ⇒ Object
Constructor Details
#initialize(gem_resolver: nil, path_normalizer: nil, config_loader: nil) ⇒ HandbookScanner
Returns a new instance of HandbookScanner.
14 15 16 17 18 19 |
# File 'lib/ace/support/nav/molecules/handbook_scanner.rb', line 14 def initialize(gem_resolver: nil, path_normalizer: nil, config_loader: nil) @gem_resolver = gem_resolver || Atoms::GemResolver.new @path_normalizer = path_normalizer || Atoms::PathNormalizer.new @config_loader = config_loader || ConfigLoader.new @settings = @config_loader.load_settings end |
Instance Method Details
#find_resources_in_source(source, protocol, pattern = "*") ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ace/support/nav/molecules/handbook_scanner.rb', line 54 def find_resources_in_source(source, protocol, pattern = "*") return [] unless source&.exists? handbook_path = source.handbook_path protocol_dir = protocol_to_directory(protocol) search_path = File.join(handbook_path, protocol_dir) return [] unless Dir.exist?(search_path) # Find matching files extension = protocol_to_extension(protocol) glob_pattern = File.join(search_path, "**", "#{pattern}#{extension}") Dir.glob(glob_pattern).map do |file_path| relative_path = file_path.sub("#{search_path}/", "").sub(extension, "") { path: file_path, relative_path: relative_path, source: source, protocol: protocol } end end |
#scan_all_sources ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ace/support/nav/molecules/handbook_scanner.rb', line 21 def scan_all_sources sources = [] # Priority 1: Project overrides sources << scan_project_source # Priority 2: User overrides sources << scan_user_source # Priority 3: Gem handbooks sources.concat(scan_gem_sources) # Priority 4: Custom configured paths sources.concat(scan_custom_sources) # Filter out non-existent sources unless specifically configured sources.compact.select { |s| s.exists? || s.custom? } end |
#scan_source_by_alias(alias_name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ace/support/nav/molecules/handbook_scanner.rb', line 40 def scan_source_by_alias(alias_name) return scan_project_source if alias_name == "@project" return scan_user_source if alias_name == "@user" # Check if it's a gem source if alias_name.start_with?("@ace-") gem_name = alias_name[1..] # Remove @ return scan_gem_source(gem_name) end # Check custom sources scan_custom_source(alias_name) end |