Class: Qwandry::LibraryRepository

Inherits:
Repository show all
Defined in:
lib/qwandry/library_repository.rb

Overview

The LibraryRepository assumes that the search path contains files in the root mixed with directories of the same name which should be opened together. Ruby’s date library is a good example of this:

date.rb
date/

Instance Attribute Summary

Attributes inherited from Repository

#name, #options, #path

Instance Method Summary collapse

Methods inherited from Repository

#all_paths, #initialize

Constructor Details

This class inherits a constructor from Qwandry::Repository

Instance Method Details

#scan(pattern) ⇒ Object

Returns Packages that may contain one or more paths if there are similar root level files that should be bundled together.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/qwandry/library_repository.rb', line 13

def scan(pattern)
  results = Hash.new{|h,k| h[k] = package(k)}
  all_paths.select do |path|
    basename = File.basename(path)
    if File.fnmatch?(pattern, basename, File::FNM_CASEFOLD)
      # strip any file extension
      basename.sub! /\.\w+$/,'' unless File.directory?(path)
      results[basename].paths << path
    end
  end
  
  results.values.sort_by{|package| package.name}
end