Permalink
Browse files

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

  • Loading branch information...
1 parent 9a6268f commit b497b8faee6f0de0c5849c6190fb09850f3c8229 @alloy alloy committed Sep 17, 2011
Showing with 68 additions and 13 deletions.
  1. +17 −1 lib/cocoapods/command/search.rb
  2. +22 −11 lib/cocoapods/source.rb
  3. +28 −1 spec/functional/command_spec.rb
  4. +1 −0 spec/unit/specification/set_spec.rb
@@ -1,14 +1,30 @@
module Pod
class 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)
+ @full_text_search = argv.option('--full')
unless @query = argv.arguments.first
super
end
end
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(", ")})"
end
end
@@ -12,12 +12,12 @@ def self.all
end
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}'")
end
- def self.search_by_name(query)
- result = all.map { |source| source.search_by_name(query) }.flatten
+ def self.search_by_name(query, full_text_search)
+ result = all.map { |s| s.search_by_name(query, full_text_search) }.flatten
if result.empty?
raise(Informative, "Unable to find a pod who's name matches `#{query}'")
end
@@ -30,17 +30,28 @@ def initialize(repo)
@repo = repo
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)
- if dir = @repo.children.find { |c| c.basename.to_s == dependency.name }
- Specification::Set.by_pod_dir(dir)
- end
+ pod_sets.find { |set| set.name == dependency.name }
end
- def search_by_name(query)
- dirs = @repo.children.select do |child|
- child.basename.to_s.downcase.include?(query.downcase)
- end
- dirs.map { |dir| Specification::Set.by_pod_dir(dir) }
+ def search_by_name(query, full_text_search)
+ pod_sets.map do |set|
+ text = if full_text_search
+ s = set.specification
+ "#{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
@@ -64,7 +64,34 @@ def command.master_repo_url; SpecHelper.fixture('spec-repos/master'); end
]
]
].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)
(@printed ||= []) << msg
end
@@ -8,6 +8,7 @@ def reset!
describe "Pod::Specification::Set" 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
end

0 comments on commit b497b8f

Please sign in to comment.