lib/composer/repository/hash_repository.rb in php-composer-0.2.0 vs lib/composer/repository/hash_repository.rb in php-composer-0.3.0

- old
+ new

@@ -9,11 +9,11 @@ # file that was distributed with this source code. # module Composer module Repository - class HashRepository + class HashRepository < Composer::Repository::BaseRepository def initialize(packages = []) packages.each do |package| add_package(package) end end @@ -21,21 +21,25 @@ def find_package(name, version = nil) # normalize name name = name.downcase # normalize version - if version != nil + if !version.nil? version_parser = Composer::Package::Version::VersionParser.new version = version_parser.normalize(version) end + match = nil packages.each do |package| - if package.name === name && (nil === version || version === package.version) - return package + if package.name === name + if version.nil? || package.version === version + match = package + break + end end end - + match end def find_packages(name, version = nil) # normalize name name = name.downcase @@ -47,43 +51,40 @@ end matches = [] packages.each do |package| if package.name === name && (nil === version || version === package.version) - matches << package + matches.push(package) end end matches end - def search(query, full_search = false) + def search(query, mode = 0) regex = /(?:#{query.split(/\s+/).join('|')})/i matches = {} packages.each do |package| name = package.name # already matched - next if matches['name'] + next if matches[name] # search - if full_search - next unless ( - package.instance_of?(Composer::Package::CompletePackage) && - regex.match("#{package.keywords.join(' ')} #{package.description}") - ) - else - next unless ( - full_search == false && - regex.match(name) - ) + unless regex.match(name) + unless mode === Composer::Repository::BaseRepository::SEARCH_FULLTEXT && + package.instance_of?(Composer::Package::CompletePackage) && + regex.match("#{package.keywords ? package.keywords.join(' ') : ''} #{package.description ? package.description : ''}") + next + end end matches[name] = { 'name' => package.pretty_name, 'description' => package.description, } + end - matches + matches.values end def package?(package) unless package raise ArgumentError,