Method: LibGems::SourceIndex#search
- Defined in:
- lib/libgems/source_index.rb
#search(gem_pattern, platform_only = false) ⇒ Object
Search for a gem by LibGems::Dependency gem_pattern. If only_platform is true, only gems matching LibGems::Platform.local will be returned. An Array of matching LibGems::Specification objects is returned.
For backwards compatibility, a String or Regexp pattern may be passed as gem_pattern, and a LibGems::Requirement for platform_only. This behavior is deprecated and will be removed.
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/libgems/source_index.rb', line 292 def search(gem_pattern, platform_only = false) version_requirement = nil only_platform = false # TODO - Remove support and warning for legacy arguments after 2008/11 unless LibGems::Dependency === gem_pattern warn "#{LibGems.location_of_caller.join ':'}:Warning: LibGems::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name" end case gem_pattern when Regexp then version_requirement = platform_only || LibGems::Requirement.default when LibGems::Dependency then only_platform = platform_only version_requirement = gem_pattern.requirement gem_pattern = if Regexp === gem_pattern.name then gem_pattern.name elsif gem_pattern.name.empty? then // else /^#{Regexp.escape gem_pattern.name}$/ end else version_requirement = platform_only || LibGems::Requirement.default gem_pattern = /#{gem_pattern}/i end unless LibGems::Requirement === version_requirement then version_requirement = LibGems::Requirement.create version_requirement end specs = all_gems.values.select do |spec| spec.name =~ gem_pattern and version_requirement.satisfied_by? spec.version end if only_platform then specs = specs.select do |spec| LibGems::Platform.match spec.platform end end specs.sort_by { |s| s.sort_obj } end |