Class: Pod::Command::Search
- Inherits:
-
Pod::Command
- Object
- CLAide::Command
- Pod::Command
- Pod::Command::Search
- Extended by:
- Executable
- Defined in:
- lib/cocoapods/command/search.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Search
constructor
A new instance of Search.
- #local_search ⇒ Object
- #run ⇒ Object
- #validate! ⇒ Object
- #web_search ⇒ Object
Methods included from Executable
executable, execute_command, which
Methods inherited from Pod::Command
#ensure_master_spec_repo_exists!, report_error, run
Methods included from Pod::Config::Mixin
Constructor Details
#initialize(argv) ⇒ Search
Returns a new instance of Search.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cocoapods/command/search.rb', line 27 def initialize(argv) @use_regex = argv.flag?('regex') @full_text_search = argv.flag?('full') @stats = argv.flag?('stats') @supported_on_ios = argv.flag?('ios') @supported_on_osx = argv.flag?('osx') @web = argv.flag?('web') @query = argv.arguments! unless argv.arguments.empty? config.silent = false super end |
Class Method Details
.options ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cocoapods/command/search.rb', line 16 def self. [ ['--regex', 'Interpret the `QUERY` as a regular expression'], ['--full', 'Search by name, summary, and description'], ['--stats', 'Show additional stats (like GitHub watchers and forks)'], ['--ios', 'Restricts the search to Pods supported on iOS'], ['--osx', 'Restricts the search to Pods supported on OS X'], ['--web', 'Searches on cocoapods.org'], ].concat(super.reject { |option, _| option == '--silent' }) end |
Instance Method Details
#local_search ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cocoapods/command/search.rb', line 75 def local_search query_regex = @query.join(' ').strip query_regex = Regexp.escape(query_regex) unless @use_regex sets = SourcesManager.search_by_name(query_regex, @full_text_search) if @supported_on_ios sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) } end if @supported_on_osx sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:osx) } end sets.each do |set| begin if @stats UI.pod(set, :stats) else UI.pod(set, :normal) end rescue DSLError UI.warn "Skipping `#{set.name}` because the podspec contains errors." end end end |
#run ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/cocoapods/command/search.rb', line 52 def run ensure_master_spec_repo_exists! if @web web_search else local_search end end |
#validate! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cocoapods/command/search.rb', line 39 def validate! super help! 'A search query is required.' unless @query unless @web || !@use_regex begin /#{@query.join(' ').strip}/ rescue RegexpError help! 'A valid regular expression is required.' end end end |
#web_search ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cocoapods/command/search.rb', line 64 def web_search query_parameter = [ ('on:osx' if @supported_on_osx), ('on:ios' if @supported_on_ios), @query, ].compact.flatten.join(' ') url = "http://cocoapods.org/?q=#{CGI.escape(query_parameter).gsub('+', '%20')}" UI.puts("Opening #{url}") open!(url) end |