Class: Ace::Demo::Molecules::TapeScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/demo/molecules/tape_scanner.rb

Instance Method Summary collapse

Constructor Details

#initialize(gem_root: Demo.gem_root, home_dir: Dir.home, cwd: Dir.pwd, parser: Atoms::TapeMetadataParser) ⇒ TapeScanner

Returns a new instance of TapeScanner.



7
8
9
10
11
12
# File 'lib/ace/demo/molecules/tape_scanner.rb', line 7

def initialize(gem_root: Demo.gem_root, home_dir: Dir.home, cwd: Dir.pwd, parser: Atoms::TapeMetadataParser)
  @gem_root = gem_root
  @home_dir = home_dir
  @cwd = cwd
  @parser = parser
end

Instance Method Details

#find(tape_ref) ⇒ Object

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ace/demo/molecules/tape_scanner.rb', line 31

def find(tape_ref)
  direct_path = File.expand_path(tape_ref, @cwd)
  if File.exist?(direct_path) && File.file?(direct_path)
    name = logical_name(direct_path)
    return build_record(name, direct_path)
  end

  lookup_name = logical_name(tape_ref)
  match = find_in_search_dirs(lookup_name, tape_ref)
  return match if match

  raise TapeNotFoundError, missing_message(tape_ref)
end

#listObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ace/demo/molecules/tape_scanner.rb', line 14

def list
  discovered = {}

  search_dirs.each do |dir|
    next unless Dir.exist?(dir)

    discover_paths(dir).each do |path|
      name = logical_name(path)
      next if discovered.key?(name)

      discovered[name] = build_record(name, path)
    end
  end

  discovered.keys.sort.map { |name| discovered[name] }
end