Skip to content

Commit

Permalink
Only use patten matches if there is not an exact match
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsanderson committed Aug 4, 2009
1 parent d312d31 commit 6a502a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/open_gem/common_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,29 @@ def add_latest_version_option
end
end

def add_exact_match_option
add_option('-x', '--exact',
'Only list exact matches') do |value, options|
options[:exact] = true
end
end

def get_spec(name)
dep = Gem::Dependency.new /#{Regexp.escape name}/, options[:version]
dep = Gem::Dependency.new(name, options[:version])
specs = Gem.source_index.search(dep)
if block_given?
specs = specs.select{|spec| yield spec}
end

if specs.length == 0
say "'#{name}' is not available"
return nil
# If we have not tried to do a pattern match yet, fall back on it.
if(!options[:exact] && !name.is_a?(Regexp))
pattern = /#{Regexp.escape name}/
get_spec(pattern)
else
say "'#{name}' is not available"
return nil
end

elsif specs.length == 1 || options[:latest]
return specs.last
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/commands/open_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize
add_command_option
add_latest_version_option
add_version_option
add_exact_match_option
end

def arguments # :nodoc:
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/commands/read_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize
add_command_option "Application to read rdoc with"
add_latest_version_option
add_version_option
add_exact_match_option
end

def arguments # :nodoc:
Expand Down

0 comments on commit 6a502a9

Please sign in to comment.