Class: Qwandry::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/qwandry/repository.rb

Overview

A Repository’s primary responsibility is to return a set of Packages that match the search criteria used in Repository#scan.

Subclasses are expected

Direct Known Subclasses

FlatRepository, LibraryRepository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, options = {}) ⇒ Repository

Creates a Repository with a give name, search path, and options.



12
13
14
15
16
# File 'lib/qwandry/repository.rb', line 12

def initialize(name, path, options={})
  @name = name
  @path = path.chomp('/')
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/qwandry/repository.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/qwandry/repository.rb', line 9

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/qwandry/repository.rb', line 8

def path
  @path
end

Instance Method Details

#all_pathsObject

Returns all paths that should be tested by Qwandry#scan.



25
26
27
28
29
30
# File 'lib/qwandry/repository.rb', line 25

def all_paths
  paths = Dir["#{@path}/*"]
  paths = paths.select(&matcher(options[:accept])) if options[:accept]
  paths = paths.reject(&matcher(options[:reject])) if options[:reject]
  paths
end

#scan(name) ⇒ Object

Given a name, scan should an array with 0 or more Packages matching the name.

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/qwandry/repository.rb', line 20

def scan(name)
  raise NotImplementedError, "Repositories must return an Array of matching packages."
end