Commit b497b8fa authored by Eloy Duran's avatar Eloy Duran

Search through summary and description with `--full'.

parent 9a6268ff
module Pod module Pod
class Command class Command
class Search < Command class Search < Command
def self.banner
%{Search pods:
$ pod search [QUERY]
Searches for pods, ignoring case, whose name matches `QUERY'. If the
`--full' option is specified, this will also search in the summary and
description of the pods.}
end
def self.options
" --full Search by name, summary, and description\n" +
super
end
def initialize(argv) def initialize(argv)
@full_text_search = argv.option('--full')
unless @query = argv.arguments.first unless @query = argv.arguments.first
super super
end end
end end
def run def run
Source.search_by_name(@query.strip).each do |set| Source.search_by_name(@query.strip, @full_text_search).each do |set|
puts "#{set.name} (#{set.versions.reverse.join(", ")})" puts "#{set.name} (#{set.versions.reverse.join(", ")})"
end end
end end
......
...@@ -12,12 +12,12 @@ module Pod ...@@ -12,12 +12,12 @@ module Pod
end end
def self.search(dependency) def self.search(dependency)
all.map { |source| source.search(dependency) }.compact.first || all.map { |s| s.search(dependency) }.compact.first ||
raise(Informative, "Unable to find a pod named `#{dependency.name}'") raise(Informative, "Unable to find a pod named `#{dependency.name}'")
end end
def self.search_by_name(query) def self.search_by_name(query, full_text_search)
result = all.map { |source| source.search_by_name(query) }.flatten result = all.map { |s| s.search_by_name(query, full_text_search) }.flatten
if result.empty? if result.empty?
raise(Informative, "Unable to find a pod who's name matches `#{query}'") raise(Informative, "Unable to find a pod who's name matches `#{query}'")
end end
...@@ -30,17 +30,28 @@ module Pod ...@@ -30,17 +30,28 @@ module Pod
@repo = repo @repo = repo
end end
def pod_sets
@repo.children.map do |child|
if child.directory? && child.basename.to_s != '.git'
Specification::Set.by_pod_dir(child)
end
end.compact
end
def search(dependency) def search(dependency)
if dir = @repo.children.find { |c| c.basename.to_s == dependency.name } pod_sets.find { |set| set.name == dependency.name }
Specification::Set.by_pod_dir(dir)
end
end end
def search_by_name(query) def search_by_name(query, full_text_search)
dirs = @repo.children.select do |child| pod_sets.map do |set|
child.basename.to_s.downcase.include?(query.downcase) text = if full_text_search
end s = set.specification
dirs.map { |dir| Specification::Set.by_pod_dir(dir) } "#{s.read(:name)} #{s.read(:summary)} #{s.read(:description)}"
else
set.name
end
set if text.downcase.include?(query.downcase)
end.compact
end end
end end
end end
...@@ -64,7 +64,34 @@ describe "Pod::Command" do ...@@ -64,7 +64,34 @@ describe "Pod::Command" do
] ]
] ]
].each do |query, result| ].each do |query, result|
command = Pod::Command.parse('search', query) command = Pod::Command.parse('search', '--silent', query)
def command.puts(msg)
(@printed ||= []) << msg
end
command.run
printed = command.instance_variable_get(:@printed)
printed.should == result.sort
end
end
it "searches for a pod who's name, summary, or description matches the given query ignoring case" do
[
[
'systemCONfiguration',
[
"Reachability (2.0.4)"
]
],
[
'is',
[
"ASIHTTPRequest (1.8, 1.8.1)",
"Reachability (2.0.4)",
"SSZipArchive (1.0)"
]
]
].each do |query, result|
command = Pod::Command.parse('search', '--silent', '--full', query)
def command.puts(msg) def command.puts(msg)
(@printed ||= []) << msg (@printed ||= []) << msg
end end
......
...@@ -8,6 +8,7 @@ end ...@@ -8,6 +8,7 @@ end
describe "Pod::Specification::Set" do describe "Pod::Specification::Set" do
it "returns nil in case a set hasn't been resolved yet" do it "returns nil in case a set hasn't been resolved yet" do
Pod::Spec::Set.reset!
Pod::Spec::Set.by_specification_name('ASIHTTPRequest').should == nil Pod::Spec::Set.by_specification_name('ASIHTTPRequest').should == nil
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment