Class: Pod::Command::Search::Sorted

Inherits:
Pod::Command::Search show all
Defined in:
lib/pod/command/search/sorted.rb

Overview

The pod search sort subcommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Sorted

Returns a new instance of Sorted.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pod/command/search/sorted.rb', line 25

def initialize(argv)
  super
  @sorting_criteria = argv.flag?('stars')      ? :stars    : nil
  @sorting_criteria ||= argv.flag?('forks')    ? :forks    : nil
  @sorting_criteria ||= argv.flag?('activity') ? :activity : nil

  unless @sorting_criteria
    @sorting_criteria = :stars
  end

  @provider_klass = SortedSearch::GithubProvider
  @printer_klass = SortedSearch::GitHubPrinter

end

Instance Attribute Details

#sorting_criteriaObject (readonly)

Returns the value of attribute sorting_criteria.



15
16
17
# File 'lib/pod/command/search/sorted.rb', line 15

def sorting_criteria
  @sorting_criteria
end

Class Method Details

.optionsObject



40
41
42
43
44
45
46
# File 'lib/pod/command/search/sorted.rb', line 40

def self.options
  [
    ["--stars",   "Sort by stars"],
    ["--activity", "Sort by most recently changed repo"],
    ["--forks",   "Sort by amount of forks"],
  ].concat(super)
end

Instance Method Details

#find_specs(query) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pod/command/search/sorted.rb', line 58

def find_specs(query)
  sets = SourcesManager.search_by_name(query.join(' ').strip, @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
end

#runObject



48
49
50
51
52
53
54
55
56
# File 'lib/pod/command/search/sorted.rb', line 48

def run
  specs = find_specs(@query)

  provider = @provider_klass.new(specs, @sorting_criteria)
  sorted_pods = provider.provide_sorted_specs

  printer = @printer_klass.new
  printer.print(sorted_pods)
end