Sha256: 2ef2e817b8b4fdf172818627b133293d2dd8a84c66f88d606f1e605febab4eae
Contents?: true
Size: 1.1 KB
Versions: 8
Compression:
Stored size: 1.1 KB
Contents
module Sprinkle::Package class PackageRepository #:nodoc: # sets up an empty repository def initialize clear end def clear @packages = [] end # adds a single package to the repository def add(package) @packages << package end def <<(package); add(package); end # returns the first package matching the name and options given def first(name, opts={}) find_all(name, opts).try(:first) end # returns all packages matching the name and options given (including via provides) def find_all(name, opts={}) # opts ||= {} all = [@packages.select {|x| x.name.to_s == name.to_s }, find_all_by_provides(name, opts)].flatten.compact filter(all, opts) end def count @packages.size end private def find_all_by_provides(name, opts={}) @packages.select {|x| x.provides and x.provides.to_s == name.to_s } end def filter(all, opts) all = all.select {|x| "#{x.version}" == opts[:version].to_s} if opts[:version] all end end end
Version data entries
8 entries across 8 versions & 1 rubygems