cocoapods-sorted-search 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20178c8bd0840a7eb0d6bc871e3f88b0e78109e3
4
- data.tar.gz: 18b976debbf06fba65c6456392224ff194a03547
3
+ metadata.gz: 4971bd047baa1b6a42cfa3fff5da31eb2750a845
4
+ data.tar.gz: df3e1b4a5a8f7eafa1c634686fa8bb5f667155f2
5
5
  SHA512:
6
- metadata.gz: 415686400445b8fec19c749c0418542f5e642a5b924cd2eebb5d7665de0b8c2bb16b7f60d1c1975b05275368a57ad0ebed1be0fc84034b15100567c02ab92495
7
- data.tar.gz: 86fb90c96b1036908e265049eeffc9f781f8e06ff8c672e1bfe46f9b5960c974d17d3e76cb1a174f60b591e524d7cb3b26f33f681712594e8b754d03cf7ecdf1
6
+ metadata.gz: cd780ed6c5660afa31f987f12f9da2676871dda97f7b6b18b4198b93161f854a304e317356d1b4ec7afaf217b0657e98e16669ae148de8186604aeea6a7bd526
7
+ data.tar.gz: 5936efe925a153f0a0d69b2a42a90b0a0d9949717475a67f66640876ea2bcb2f58ffce1a06fcd43f9a3af7d244e53d40e87b4fbee1b1ba5a8782495ead1f6a49
data/.rubocop.yml ADDED
@@ -0,0 +1,58 @@
1
+ HashSyntax:
2
+ EnforcedStyle: ruby19
3
+ SupportedStyles:
4
+ - ruby19
5
+ - hash_rockets
6
+
7
+ CaseIndentation:
8
+ SupportedStyles:
9
+ - case
10
+ - end
11
+ IndentOneStep: true
12
+
13
+ StringLiterals:
14
+ Enabled: false
15
+ EnforcedStyle: double_quotes
16
+
17
+ SignalException:
18
+ EnforcedStyle: only_raise
19
+
20
+ ConstantName:
21
+ Enabled: false
22
+
23
+ IfUnlessModifier:
24
+ Enabled: false
25
+
26
+ EmptyLinesAroundBody:
27
+ Enabled: false
28
+
29
+ AsciiComments:
30
+ Enabled: false
31
+
32
+ Proc:
33
+ Enabled: false
34
+
35
+ BracesAroundHashParameters:
36
+ Enabled: false
37
+
38
+ Encoding:
39
+ Enabled: false
40
+
41
+ TrailingComma:
42
+ EnforcedStyleForMultiline: comma
43
+
44
+ FileName:
45
+ Enabled: false
46
+
47
+ ClassLength:
48
+ Max: 200
49
+
50
+ MethodLength:
51
+ Max: 30
52
+
53
+ CyclomaticComplexity:
54
+ Max: 7
55
+
56
+ LineLength:
57
+ Enabled: false
58
+
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: objective-c
2
+
3
+ env:
4
+ - RVM_RUBY_VERSION=2.1.1
5
+
6
+ before_install:
7
+ - curl http://curl.haxx.se/ca/cacert.pem -o /usr/local/share/cacert.pem
8
+ - source ~/.rvm/scripts/rvm
9
+ - rvm install $RVM_RUBY_VERSION
10
+ - rvm use $RVM_RUBY_VERSION
11
+
12
+ install:
13
+ - bundle install --without=documentation --path ./travis_bundle_dir
14
+
15
+ script: rake spec
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cocoapods-sorted-search.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods'
8
+ gem 'rubocop'
9
+ end
data/Gemfile.lock CHANGED
@@ -1,16 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cocoapods-sorted-search (0.1.2)
4
+ cocoapods-sorted-search (0.2.0)
5
5
  cocoapods (~> 0.28)
6
+ hashie
7
+ osx_keychain
6
8
  ruby-progressbar
9
+ typhoeus
7
10
 
8
11
  GEM
9
12
  remote: https://rubygems.org/
10
13
  specs:
14
+ RubyInline (3.12.2)
15
+ ZenTest (~> 4.3)
16
+ ZenTest (4.9.5)
11
17
  activesupport (3.2.17)
12
18
  i18n (~> 0.6, >= 0.6.4)
13
19
  multi_json (~> 1.0)
20
+ addressable (2.3.6)
21
+ ast (1.1.0)
14
22
  claide (0.5.0)
15
23
  cocoapods (0.31.1)
16
24
  activesupport (>= 3.2.15, < 4)
@@ -32,14 +40,28 @@ GEM
32
40
  cocoapods-downloader (0.4.1)
33
41
  cocoapods-try (0.2.0)
34
42
  colored (1.2)
43
+ crack (0.4.2)
44
+ safe_yaml (~> 1.0.0)
35
45
  diff-lcs (1.2.5)
36
46
  escape (0.0.4)
47
+ ethon (0.7.0)
48
+ ffi (>= 1.3.0)
49
+ ffi (1.9.3)
37
50
  fuzzy_match (2.0.4)
51
+ hashie (2.1.1)
38
52
  i18n (0.6.9)
53
+ json (1.8.1)
39
54
  json_pure (1.8.1)
40
55
  multi_json (1.9.2)
41
56
  nap (0.7.0)
42
57
  open4 (1.3.3)
58
+ osx_keychain (1.0.0)
59
+ RubyInline (~> 3)
60
+ parser (2.1.7)
61
+ ast (~> 1.1)
62
+ slop (~> 3.4, >= 3.4.5)
63
+ powerpack (0.0.9)
64
+ rainbow (2.0.0)
43
65
  rake (10.2.2)
44
66
  rspec (2.14.1)
45
67
  rspec-core (~> 2.14.0)
@@ -49,7 +71,20 @@ GEM
49
71
  rspec-expectations (2.14.5)
50
72
  diff-lcs (>= 1.1.3, < 2.0)
51
73
  rspec-mocks (2.14.6)
74
+ rubocop (0.20.1)
75
+ json (>= 1.7.7, < 2)
76
+ parser (~> 2.1.7)
77
+ powerpack (~> 0.0.6)
78
+ rainbow (>= 1.99.1, < 3.0)
79
+ ruby-progressbar (~> 1.4)
52
80
  ruby-progressbar (1.4.2)
81
+ safe_yaml (1.0.2)
82
+ slop (3.5.0)
83
+ typhoeus (0.6.8)
84
+ ethon (>= 0.7.0)
85
+ webmock (1.17.4)
86
+ addressable (>= 2.2.7)
87
+ crack (>= 0.3.2)
53
88
  xcodeproj (0.16.0)
54
89
  activesupport (~> 3.0)
55
90
  colored (~> 1.2)
@@ -59,6 +94,9 @@ PLATFORMS
59
94
 
60
95
  DEPENDENCIES
61
96
  bundler
97
+ cocoapods
62
98
  cocoapods-sorted-search!
63
99
  rake
64
100
  rspec
101
+ rubocop
102
+ webmock
data/README.md CHANGED
@@ -1,9 +1,12 @@
1
+ [![Build Status](http://img.shields.io/travis/DenHeadless/cocoapods-sorted-search/master.svg)](https://travis-ci.org/DenHeadless/cocoapods-sorted-search)
2
+ [![Gem Version](http://img.shields.io/gem/v/cocoapods-sorted-search.svg)](http://badge.fury.io/rb/cocoapods-sorted-search)
3
+
1
4
  CocoaPods sorted search
2
5
  ==============
3
6
 
4
7
  CocoaPods plugin which adds a `sort` subcommand for `pod search` to sort search results by amount of stars, forks, or github activity.
5
8
 
6
- ##Usage
9
+ ## Usage
7
10
 
8
11
  pod search sort POD_NAME
9
12
 
@@ -17,10 +20,24 @@ CocoaPods plugin which adds a `sort` subcommand for `pod search` to sort search
17
20
 
18
21
  [sudo] gem install cocoapods-sorted-search
19
22
 
20
- ## Known issues
23
+ ## Unleash the ~~hounds~~ pods!
24
+
25
+ Plugin uses GitHub anonymous requests by default, that have rate limit of 60 requests per hour.
26
+
27
+ Feed plugin with GitHub OAuth token, and raise the limit to **5000** requests per hour! Not only that, if provided with token, plugin starts to fetch GitHub info in parallel, making sorting incredibly fast.
28
+
29
+ Steps for token configuration:
30
+ 1. Go to GitHub settings -> Applications -> Personal Access Tokens
31
+ 2. Generate new one and **uncheck** all scopes. It should look [like this](https://raw.githubusercontent.com/DenHeadless/cocoapods-sorted-search/master/token_example.png).
32
+ 3. Run ``` pod setup github --token=MyToken ```
21
33
 
22
- Currently GitHub has a rate limit set for 60 API requests per hour. CocoaPods does great job at caching results, but it is easy to exceed current limit. Use with care =)
34
+ Your token will be stored in OS X Keychain and used automatically for fetching GitHub info for repositories.
23
35
 
24
36
  ## Example
25
37
 
26
38
  ![](example.gif)
39
+
40
+ ## Requirements
41
+
42
+ - CocoaPods 0.28 and higher
43
+ - Ruby 1.9.3 and higher
data/Rakefile CHANGED
@@ -1,2 +1,37 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :default => "spec"
4
+
5
+ # Bootstrap
6
+ #-----------------------------------------------------------------------------#
7
+
8
+ task :bootstrap, :use_bundle_dir? do |t, args|
9
+ if args[:use_bundle_dir?]
10
+ sh "bundle install --path ./travis_bundle_dir"
11
+ else
12
+ sh "bundle install"
13
+ end
14
+ end
15
+
16
+ # Spec
17
+ #-----------------------------------------------------------------------------#
18
+
19
+ desc "Runs all the specs"
20
+ task :spec do
21
+ start_time = Time.now
22
+ sh "bundle exec rspec spec"
23
+ duration = Time.now - start_time
24
+ puts "Tests completed in #{duration}s"
25
+ Rake::Task["rubocop"].invoke
26
+ end
27
+
28
+ # Rubocop
29
+ #-----------------------------------------------------------------------------#
30
+
31
+ desc 'Checks code style'
32
+ task :rubocop do
33
+ require 'rubocop'
34
+ cli = Rubocop::CLI.new
35
+ result = cli.run(FileList['{spec,lib}/**/*.rb'])
36
+ abort('RuboCop failed!') unless result == 0
37
+ end
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = "cocoapods-sorted-search"
7
- spec.version = '0.1.2'
8
+ spec.version = '0.2.0'
8
9
  spec.authors = ["Denys Telezhkin"]
9
10
  spec.email = ["strangervir@gmail.com"]
10
11
  spec.summary = %q{CocoaPods plugin for sorted searching amongst CocoaPods.}
@@ -18,8 +19,12 @@ Gem::Specification.new do |spec|
18
19
 
19
20
  spec.add_runtime_dependency 'cocoapods', '~> 0.28'
20
21
  spec.add_dependency 'ruby-progressbar'
22
+ spec.add_dependency "typhoeus"
23
+ spec.add_dependency "hashie"
24
+ spec.add_dependency "osx_keychain"
21
25
 
22
26
  spec.add_development_dependency "bundler"
23
27
  spec.add_development_dependency "rake"
24
28
  spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "webmock"
25
30
  end
data/example.gif CHANGED
Binary file
@@ -1 +1,2 @@
1
- require 'pod/command/search_sort'
1
+ require 'pod/command/search/sorted'
2
+ require 'pod/command/setup/github'
@@ -0,0 +1,79 @@
1
+ require 'cocoapods'
2
+ require 'sorted_search/printers/pods_printer'
3
+ require 'sorted_search/providers/cocoapods_provider'
4
+ require 'sorted_search/credentials'
5
+ require 'sorted_search/providers/github_provider'
6
+ require 'sorted_search/printers/github_printer'
7
+
8
+ module Pod
9
+ class Command
10
+ class Search
11
+
12
+ # The pod search sort subcommand
13
+ #
14
+ class Sorted < Search
15
+
16
+ attr_reader :sorting_criteria
17
+
18
+ self.summary = 'Sort pod search results easily!'
19
+
20
+ self.description = <<-DESC
21
+ Sort CocoaPods search results by stars, forks, or repo activity.
22
+ DESC
23
+
24
+ self.command = "sort"
25
+
26
+ def initialize(argv)
27
+ super
28
+ @sorting_criteria = argv.flag?('stars') ? :stars : nil
29
+ @sorting_criteria ||= argv.flag?('forks') ? :forks : nil
30
+ @sorting_criteria ||= argv.flag?('activity') ? :activity : nil
31
+
32
+ unless @sorting_criteria
33
+ @sorting_criteria = :stars
34
+ end
35
+
36
+ if SortedSearch::Credentials.token
37
+ @provider_klass = SortedSearch::GithubProvider
38
+ @printer_klass = SortedSearch::GitHubPrinter
39
+ else
40
+ UI.warn "Using anonymous requests. GitHub rate limit 60 requests per hour."
41
+ @provider_klass = SortedSearch::CocoapodsProvider
42
+ @printer_klass = SortedSearch::CocoapodsPrinter
43
+ end
44
+
45
+ end
46
+
47
+ def self.options
48
+ [
49
+ ["--stars", "Sort by stars"],
50
+ ["--activity", "Sort by most recently changed repo"],
51
+ ["--forks", "Sort by amount of forks"],
52
+ ].concat(super)
53
+ end
54
+
55
+ def run
56
+ specs = find_specs(@query)
57
+
58
+ provider = @provider_klass.new(specs, @sorting_criteria)
59
+ sorted_pods = provider.provide_sorted_specs
60
+
61
+ printer = @printer_klass.new
62
+ printer.print(sorted_pods)
63
+ end
64
+
65
+ def find_specs(query)
66
+ sets = SourcesManager.search_by_name(query.join(' ').strip, @full_text_search)
67
+ if @supported_on_ios
68
+ sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
69
+ end
70
+ if @supported_on_osx
71
+ sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:osx) }
72
+ end
73
+
74
+ sets
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,47 @@
1
+ require 'ruby-progressbar'
2
+ require 'cocoapods'
3
+ require 'sorted_search/github'
4
+ require 'sorted_search/credentials'
5
+
6
+ module Pod
7
+ class Command
8
+ class Setup
9
+
10
+ # The pod search sort subcommand
11
+ #
12
+ class GitHub < Setup
13
+ self.summary = 'Sort pod search results easily!'
14
+
15
+ self.description = <<-DESC
16
+ Add GitHub token to use authenticated requests for pod search sort command.
17
+ Send up to 1000 requests per hour!
18
+ DESC
19
+
20
+ self.command = "github"
21
+
22
+ def initialize(argv)
23
+ super
24
+ @token = argv.option('token')
25
+ end
26
+
27
+ def self.options
28
+ [
29
+ ["--token", "GitHub OAuth token"],
30
+ ]
31
+ end
32
+
33
+ def validate!
34
+ help! "GitHub token is required" unless @token
35
+ super
36
+ end
37
+
38
+ def run
39
+ SortedSearch::Credentials.token = @token
40
+ puts
41
+ puts SortedSearch::Credentials.token.green + " token saved to OS X keychain".green
42
+ puts
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,22 @@
1
+ require 'osx_keychain'
2
+
3
+ module SortedSearch
4
+
5
+ # Module for saving github token to Mac OS X keychain
6
+ #
7
+ module Credentials
8
+
9
+ GITHUB_TOKEN_KEY = "GitHub token key"
10
+
11
+ def self.token
12
+ keychain = OSXKeychain.new
13
+ keychain["GitHub CocoaPods OAuth token", GITHUB_TOKEN_KEY]
14
+ end
15
+
16
+ def self.token=(token)
17
+ keychain = OSXKeychain.new
18
+ keychain["GitHub CocoaPods OAuth token", GITHUB_TOKEN_KEY] = token
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ require 'typhoeus'
2
+ require 'json'
3
+ require 'hashie'
4
+ require 'sorted_search/credentials'
5
+
6
+ module SortedSearch
7
+
8
+ # Github API client
9
+ #
10
+ module GitHub
11
+
12
+ HOSTNAME = "api.github.com"
13
+
14
+ # returns Typhoeus::Request object, that can be added to Hydra
15
+ # completion block will be called with parsed response, or nil if request failed
16
+ def self.get_repo(owner, repo, &completion)
17
+ token = SortedSearch::Credentials.token
18
+ request = Typhoeus::Request.new("https://#{HOSTNAME}/repos/#{owner}/#{repo}", headers: { Authorization: "token #{token}" })
19
+ request.on_complete(&self.parse_block(&completion))
20
+ request
21
+ end
22
+
23
+ private
24
+
25
+ def self.parse_block(&completion)
26
+ lambda do |response|
27
+ if response.success?
28
+ parsed_body = JSON.parse response.body
29
+ parsed_object = Hashie::Mash.new(parsed_body)
30
+ completion.call(parsed_object) if completion
31
+ else
32
+ completion.call(nil)
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,63 @@
1
+ require 'sorted_search/printers/printer'
2
+ require 'cocoapods'
3
+
4
+ module SortedSearch
5
+
6
+ # Printer for pods specification
7
+ #
8
+ class GitHubPrinter < Printer
9
+
10
+ def print(pods)
11
+
12
+ pods.each do |array|
13
+ pod = array[0]
14
+ mash = array[1]
15
+
16
+ Pod::UI.title("-> #{pod.name} (#{pod.version})".green, '', 1) do
17
+ stars = [0x2605].pack('U') + ' '
18
+ forks = [0x2442].pack('U') + ' '
19
+ commit = 'Last commit: '
20
+
21
+ if mash.name
22
+ stars += mash.stargazers_count.to_s + ' '
23
+ forks += mash.forks.to_s + ' '
24
+ commit += distance_from_now_in_words(mash.pushed_at)
25
+ else
26
+ stars += "Unknown "
27
+ forks += "Unknown "
28
+ commit += "Unknown "
29
+ end
30
+
31
+ Pod::UI.puts_indented pod.summary
32
+ Pod::UI.puts_indented "pod '#{pod.name}', '~> #{pod.version}'"
33
+ Pod::UI.puts_indented stars.yellow + forks.yellow
34
+ Pod::UI.puts_indented commit.yellow
35
+ end
36
+ end
37
+
38
+ Pod::UI.puts
39
+ end
40
+
41
+ def distance_from_now_in_words(from_time)
42
+ return nil unless from_time
43
+ from_time = Time.parse(from_time) unless from_time.is_a?(Time)
44
+ to_time = Time.now
45
+ distance_in_days = (((to_time - from_time).abs) / 60 / 60 / 24).round
46
+
47
+ case distance_in_days
48
+ when 0..7
49
+ "less than a week ago"
50
+ when 8..29
51
+ "#{distance_in_days} days ago"
52
+ when 30..45
53
+ "1 month ago"
54
+ when 46..365
55
+ "#{(distance_in_days.to_f / 30).round} months ago"
56
+ else
57
+ "more than a year ago"
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,30 @@
1
+ require 'sorted_search/printers/printer'
2
+ require 'cocoapods'
3
+
4
+ module SortedSearch
5
+
6
+ # Printer for pods specification
7
+ #
8
+ class CocoapodsPrinter < Printer
9
+
10
+ def print(pods)
11
+ pods.each do |pod|
12
+ Pod::UI.title("-> #{pod.name} (#{pod.version})".green, '', 1) do
13
+ next unless pod.github_last_activity
14
+ stars = [0x2605].pack('U') + ' ' + pod.github_watchers.to_s + ' '
15
+ forks = [0x2442].pack('U') + ' ' + pod.github_forks.to_s + ' '
16
+ commit = 'Last commit: ' + pod.github_last_activity
17
+
18
+ Pod::UI.puts_indented pod.summary
19
+ Pod::UI.puts_indented "pod '#{pod.name}', '~> #{pod.version}'"
20
+ Pod::UI.puts_indented stars.yellow + forks.yellow
21
+ Pod::UI.puts_indented commit.yellow
22
+ end
23
+
24
+ end
25
+
26
+ Pod::UI.puts
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ module SortedSearch
2
+
3
+ # base class for printers
4
+ #
5
+ class Printer
6
+ def print(pods)
7
+ raise Informative "Redefine print method in subclasses"
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'sorted_search/providers/provider'
2
+
3
+ module SortedSearch
4
+
5
+ # base class for printers
6
+ #
7
+ class CocoapodsProvider < Provider
8
+
9
+ def fetch_data
10
+ super
11
+ @specs.each do |spec|
12
+ pod = pod_from_spec(spec)
13
+ pod.github_watchers # This will force statistics provider to fetch github info unless it is already cached
14
+ @progress_bar.increment
15
+ end
16
+ end
17
+
18
+ def sort_specs
19
+ pods = @specs.map { |spec| pod_from_spec(spec) }
20
+
21
+ pods.sort do |x, y|
22
+ case @sorting_criteria
23
+
24
+ when :stars
25
+ x.github_watchers.to_i <=> y.github_watchers.to_i
26
+
27
+ when :forks
28
+ x.github_forks.to_i <=> y.github_forks.to_i
29
+
30
+ when :activity
31
+ x.statistics_provider.github_pushed_at(y.set).to_i <=> y.statistics_provider.github_pushed_at(x.set).to_i
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,63 @@
1
+ require 'sorted_search/providers/provider'
2
+ require 'sorted_search/github'
3
+
4
+ module SortedSearch
5
+
6
+ # base class for printers
7
+ #
8
+ class GithubProvider < Provider
9
+
10
+ def fetch_data
11
+ super
12
+ pods = []
13
+ @specs.each do |spec|
14
+ pods << pod_from_spec(spec)
15
+ end
16
+
17
+ hydra = Typhoeus::Hydra.hydra
18
+
19
+ @github_repos = {}
20
+ pods.each do |pod|
21
+
22
+ _, username, reponame = *(pod.source_url.match(%r{[:/]([\w\-]+)/([\w\-]+)\.git}))
23
+
24
+ request = SortedSearch::GitHub.get_repo(username, reponame) do |response_object|
25
+ @progress_bar.increment
26
+
27
+ if response_object
28
+ @github_repos[pod] = response_object
29
+ else
30
+ mash = Hashie::Mash.new
31
+ mash.stargazers_count = 0
32
+ mash.forks = 0
33
+ mash.pushed_at = 0
34
+ @github_repos[pod] = mash
35
+ end
36
+ end
37
+
38
+ hydra.queue request
39
+ end
40
+
41
+ hydra.run
42
+ end
43
+
44
+ def sort_specs
45
+ @github_repos.sort_by do |key, value|
46
+ case @sorting_criteria
47
+
48
+ when :stars
49
+ value.stargazers_count.to_i
50
+
51
+ when :forks
52
+ value.forks.to_i
53
+
54
+ when :activity
55
+ value.pushed_at
56
+
57
+ else
58
+ nil
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ require 'ruby-progressbar'
2
+
3
+ module SortedSearch
4
+
5
+ # base class for printers
6
+ #
7
+ class Provider
8
+
9
+ attr_reader :sorting_criteria
10
+
11
+ def initialize(specs, sorting_criteria)
12
+ @specs = specs
13
+ @sorting_criteria = sorting_criteria
14
+ end
15
+
16
+ def provide_sorted_specs
17
+ fetch_data
18
+ sort_specs
19
+ end
20
+
21
+ # private
22
+
23
+ def fetch_data
24
+ found = "\nFound " + @specs.count.to_s + " specs. Fetching GitHub info, wait a moment please.\n"
25
+ Pod::UI.puts found.green
26
+
27
+ @progress_bar = ProgressBar.create(total: @specs.count, length: 60)
28
+ end
29
+
30
+ def sort_specs
31
+ end
32
+
33
+ def pod_from_spec(spec)
34
+ statistics_provider = Pod::Config.instance.spec_statistics_provider
35
+ Pod::Specification::Set::Presenter.new(spec, statistics_provider)
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,89 @@
1
+ {
2
+ "id": 5998758,
3
+ "name": "DTTableViewManager",
4
+ "full_name": "DenHeadless/DTTableViewManager",
5
+ "owner": {
6
+ "login": "DenHeadless",
7
+ "id": 853604,
8
+ "avatar_url": "https://avatars.githubusercontent.com/u/853604?",
9
+ "gravatar_id": "5d7040ac544974637e38e6525b644694",
10
+ "url": "https://api.github.com/users/DenHeadless",
11
+ "html_url": "https://github.com/DenHeadless",
12
+ "followers_url": "https://api.github.com/users/DenHeadless/followers",
13
+ "following_url": "https://api.github.com/users/DenHeadless/following{/other_user}",
14
+ "gists_url": "https://api.github.com/users/DenHeadless/gists{/gist_id}",
15
+ "starred_url": "https://api.github.com/users/DenHeadless/starred{/owner}{/repo}",
16
+ "subscriptions_url": "https://api.github.com/users/DenHeadless/subscriptions",
17
+ "organizations_url": "https://api.github.com/users/DenHeadless/orgs",
18
+ "repos_url": "https://api.github.com/users/DenHeadless/repos",
19
+ "events_url": "https://api.github.com/users/DenHeadless/events{/privacy}",
20
+ "received_events_url": "https://api.github.com/users/DenHeadless/received_events",
21
+ "type": "User",
22
+ "site_admin": false
23
+ },
24
+ "private": false,
25
+ "html_url": "https://github.com/DenHeadless/DTTableViewManager",
26
+ "description": "The most simple and robust way to manage UITableView",
27
+ "fork": false,
28
+ "url": "https://api.github.com/repos/DenHeadless/DTTableViewManager",
29
+ "forks_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/forks",
30
+ "keys_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/keys{/key_id}",
31
+ "collaborators_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/collaborators{/collaborator}",
32
+ "teams_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/teams",
33
+ "hooks_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/hooks",
34
+ "issue_events_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/issues/events{/number}",
35
+ "events_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/events",
36
+ "assignees_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/assignees{/user}",
37
+ "branches_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/branches{/branch}",
38
+ "tags_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/tags",
39
+ "blobs_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/git/blobs{/sha}",
40
+ "git_tags_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/git/tags{/sha}",
41
+ "git_refs_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/git/refs{/sha}",
42
+ "trees_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/git/trees{/sha}",
43
+ "statuses_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/statuses/{sha}",
44
+ "languages_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/languages",
45
+ "stargazers_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/stargazers",
46
+ "contributors_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/contributors",
47
+ "subscribers_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/subscribers",
48
+ "subscription_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/subscription",
49
+ "commits_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/commits{/sha}",
50
+ "git_commits_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/git/commits{/sha}",
51
+ "comments_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/comments{/number}",
52
+ "issue_comment_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/issues/comments/{number}",
53
+ "contents_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/contents/{+path}",
54
+ "compare_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/compare/{base}...{head}",
55
+ "merges_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/merges",
56
+ "archive_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/{archive_format}{/ref}",
57
+ "downloads_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/downloads",
58
+ "issues_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/issues{/number}",
59
+ "pulls_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/pulls{/number}",
60
+ "milestones_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/milestones{/number}",
61
+ "notifications_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/notifications{?since,all,participating}",
62
+ "labels_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/labels{/name}",
63
+ "releases_url": "https://api.github.com/repos/DenHeadless/DTTableViewManager/releases{/id}",
64
+ "created_at": "2012-09-28T14:56:08Z",
65
+ "updated_at": "2014-03-28T15:13:30Z",
66
+ "pushed_at": "2014-03-28T15:13:32Z",
67
+ "git_url": "git://github.com/DenHeadless/DTTableViewManager.git",
68
+ "ssh_url": "git@github.com:DenHeadless/DTTableViewManager.git",
69
+ "clone_url": "https://github.com/DenHeadless/DTTableViewManager.git",
70
+ "svn_url": "https://github.com/DenHeadless/DTTableViewManager",
71
+ "homepage": "",
72
+ "size": 3168,
73
+ "stargazers_count": 59,
74
+ "watchers_count": 59,
75
+ "language": "Objective-C",
76
+ "has_issues": true,
77
+ "has_downloads": true,
78
+ "has_wiki": true,
79
+ "forks_count": 6,
80
+ "mirror_url": null,
81
+ "open_issues_count": 0,
82
+ "forks": 6,
83
+ "open_issues": 0,
84
+ "watchers": 59,
85
+ "default_branch": "master",
86
+ "master_branch": "master",
87
+ "network_count": 6,
88
+ "subscribers_count": 7
89
+ }
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,49 @@
1
- # encoding: UTF-8
2
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
3
5
 
4
- require 'rspec'
6
+ require 'bundler/setup'
7
+ require 'cocoapods'
8
+ require 'cocoapods_plugin'
5
9
 
6
10
  def fixture(name)
7
11
  File.read(File.dirname(__FILE__) + "/fixtures/#{name}")
8
12
  end
13
+
14
+ #-----------------------------------------------------------------------------#
15
+
16
+ # The CocoaPods namespace
17
+ #
18
+ module Pod
19
+
20
+ # Disable the wrapping so the output is deterministic in the tests.
21
+ #
22
+ UI.disable_wrap = true
23
+
24
+ # Redirects the messages to an internal store.
25
+ #
26
+ module UI
27
+ @output = ''
28
+ @warnings = ''
29
+
30
+ class << self
31
+ attr_accessor :output
32
+ attr_accessor :warnings
33
+
34
+ def puts(message = '')
35
+ @output << "#{message}\n"
36
+ end
37
+
38
+ def warn(message = '', actions = [])
39
+ @warnings << "#{message}\n"
40
+ end
41
+
42
+ def print(message)
43
+ @output << message
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ #-----------------------------------------------------------------------------#
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'sorted_search/github'
3
+ require 'webmock/rspec'
4
+ require 'sorted_search/credentials'
5
+
6
+ # Sorted Search Github API fetcher tests
7
+ #
8
+ module SortedSearch
9
+ #
10
+ module Github
11
+ describe "fetch repo info" do
12
+ before do
13
+ stub_request(:get, "https://api.github.com/repos/foo/bar")
14
+ .with(headers: { Authorization: "token foo" })
15
+ .to_return(body: fixture('dttableviewmanager.json'))
16
+ end
17
+
18
+ it "should receive github repo info" do
19
+ allow(SortedSearch::Credentials).to receive(:token).and_return("foo")
20
+
21
+ repo = nil
22
+ request = SortedSearch::GitHub.get_repo('foo', 'bar') do |parsed_response|
23
+ repo = parsed_response
24
+ end
25
+ request.run
26
+
27
+ repo.name.should eql('DTTableViewManager')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../../../spec_helper', __FILE__)
2
+
3
+ # CocoaPods namespace
4
+ #
5
+ module Pod
6
+ describe Command::Setup do
7
+
8
+ describe "setup github" do
9
+
10
+ it "registers itself" do
11
+ expect(Command.parse(%w(setup github))).to be_instance_of(Command::Setup::GitHub)
12
+ end
13
+
14
+ it "presents the help if no name is provided" do
15
+ command = Pod::Command.parse(['setup github'])
16
+ expect { command.validate! }.to raise_error(CLAide::Help)
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path('../../../../spec_helper', __FILE__)
2
+ # CocoaPods namespace
3
+ #
4
+ module Pod
5
+
6
+ describe "command" do
7
+
8
+ it "registers itself" do
9
+ expect(Command.parse(%w(search sort))).to be_instance_of(Command::Search::Sorted)
10
+ end
11
+
12
+ it "should correctly set stars sort order" do
13
+ command = Command.parse(%w(search sort))
14
+ expect(command.sorting_criteria).to equal(:stars)
15
+ end
16
+
17
+ it "should correctly set stars sort order" do
18
+ command = Command.parse(%w(search sort --stars))
19
+ expect(command.sorting_criteria).to equal(:stars)
20
+ end
21
+
22
+ it "should correctly set stars sort order" do
23
+ command = Command.parse(%w(search sort --forks))
24
+ expect(command.sorting_criteria).to equal(:forks)
25
+ end
26
+
27
+ it "should correctly set stars sort order" do
28
+ command = Command.parse(%w(search sort --activity))
29
+ expect(command.sorting_criteria).to equal(:activity)
30
+ end
31
+
32
+ it "should correctly set stars sort order" do
33
+ command = Command.parse(%w(search sort --stars --forks --activity))
34
+ expect(command.sorting_criteria).to equal(:stars)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../../../spec_helper', __FILE__)
2
+ require 'sorted_search/printers/printer'
3
+
4
+ #
5
+ module SortedSearch
6
+
7
+ describe Printer do
8
+
9
+ it "should raise if print method invoked" do
10
+ printer = SortedSearch::Printer.new
11
+
12
+ expect { printer.print([]) }.to raise_exception
13
+ end
14
+
15
+ end
16
+
17
+ end
data/token_example.png ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-sorted-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denys Telezhkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: osx_keychain
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: bundler
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +122,20 @@ dependencies:
80
122
  - - ">="
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: Sort CocoaPods search results by amount of stars, forks, or commit activity!
84
140
  email:
85
141
  - strangervir@gmail.com
@@ -88,6 +144,8 @@ extensions: []
88
144
  extra_rdoc_files: []
89
145
  files:
90
146
  - ".gitignore"
147
+ - ".rubocop.yml"
148
+ - ".travis.yml"
91
149
  - Gemfile
92
150
  - Gemfile.lock
93
151
  - LICENSE
@@ -96,8 +154,23 @@ files:
96
154
  - cocoapods-sorted-search.gemspec
97
155
  - example.gif
98
156
  - lib/cocoapods_plugin.rb
99
- - lib/pod/command/search_sort.rb
157
+ - lib/pod/command/search/sorted.rb
158
+ - lib/pod/command/setup/github.rb
159
+ - lib/sorted_search/credentials.rb
160
+ - lib/sorted_search/github.rb
161
+ - lib/sorted_search/printers/github_printer.rb
162
+ - lib/sorted_search/printers/pods_printer.rb
163
+ - lib/sorted_search/printers/printer.rb
164
+ - lib/sorted_search/providers/cocoapods_provider.rb
165
+ - lib/sorted_search/providers/github_provider.rb
166
+ - lib/sorted_search/providers/provider.rb
167
+ - spec/fixtures/dttableviewmanager.json
100
168
  - spec/spec_helper.rb
169
+ - spec/unit/github_spec.rb
170
+ - spec/unit/pod/command/github_setup_spec.rb
171
+ - spec/unit/pod/command/sorted_search_spec.rb
172
+ - spec/unit/sorted_search/printers/printer_spec.rb
173
+ - token_example.png
101
174
  homepage: https://github.com/DenHeadless/cocoapods-sorted-search
102
175
  licenses:
103
176
  - MIT
@@ -123,5 +196,10 @@ signing_key:
123
196
  specification_version: 4
124
197
  summary: CocoaPods plugin for sorted searching amongst CocoaPods.
125
198
  test_files:
199
+ - spec/fixtures/dttableviewmanager.json
126
200
  - spec/spec_helper.rb
201
+ - spec/unit/github_spec.rb
202
+ - spec/unit/pod/command/github_setup_spec.rb
203
+ - spec/unit/pod/command/sorted_search_spec.rb
204
+ - spec/unit/sorted_search/printers/printer_spec.rb
127
205
  has_rdoc:
@@ -1,114 +0,0 @@
1
- require 'ruby-progressbar'
2
-
3
- module Pod
4
- class Command
5
- class Search
6
- class Sorted < Search
7
- self.summary = 'Sort pod search results easily!'
8
-
9
- self.description = <<-DESC
10
- Sort CocoaPods search results by stars, forks, or repo activity.
11
- DESC
12
-
13
- self.command = "sort"
14
-
15
- def initialize(argv)
16
- super
17
- @sort_by_stars = argv.flag?('stars')
18
- @sort_by_commits = argv.flag?('activity')
19
- @sort_by_forks = argv.flag?('forks')
20
-
21
- if !@sort_by_forks && !@sort_by_commits
22
- @sort_by_stars = true
23
- end
24
- end
25
-
26
- def self.options
27
- [
28
- ["--stars", "Sort by stars"],
29
- ["--activity", "Sort by most recently changed repo"],
30
- ["--forks", "Sort by amount of forks"]
31
- ].concat(super)
32
- end
33
-
34
- def run
35
- specs = find_specs(@query)
36
- fetch_github_info(specs)
37
- sorted_pods = sort_specs(specs)
38
- print_specs(sorted_pods)
39
- end
40
-
41
- def fetch_github_info(specs)
42
- found = "\nFound " + specs.count.to_s + " specs. Fetching GitHub info, wait a moment please.\n"
43
- UI.puts found.green
44
-
45
- progress_bar = ProgressBar.create(total: specs.count, length: 60)
46
- specs.each do |spec|
47
- pod = pod_from_spec(spec)
48
- pod.github_watchers # This will force statistics provider to fetch github info unless it is already cached
49
- progress_bar.increment
50
- end
51
- end
52
-
53
- def pod_from_spec(spec)
54
- statistics_provider = Config.instance.spec_statistics_provider
55
- Specification::Set::Presenter.new(spec, statistics_provider)
56
- end
57
-
58
- def print_specs(sorted_pods)
59
- sorted_pods.each do |pod|
60
- UI.title("-> #{pod.name} (#{pod.version})".green, '', 1) do
61
- next unless pod.github_last_activity
62
- stars = [0x2605].pack("U") + " " + pod.github_watchers.to_s + " "
63
- forks = [0x2442].pack("U") + " " + pod.github_forks.to_s + " "
64
- commit = "Last commit: "+ pod.github_last_activity
65
-
66
- UI.puts_indented pod.summary
67
- UI.puts_indented "pod '#{pod.name}', '~> #{pod.version}'"
68
- UI.puts_indented stars.yellow + forks.yellow
69
- UI.puts_indented commit.yellow
70
- end
71
-
72
- end
73
-
74
- UI.puts
75
-
76
- end
77
-
78
- def sort_specs(specs)
79
- pods = specs.map { |spec| pod_from_spec(spec) }
80
-
81
- if @sort_by_stars
82
- return pods.sort do |x,y|
83
- y.github_watchers.to_i <=> x.github_watchers.to_i
84
- end
85
- end
86
-
87
- if @sort_by_commits
88
- return pods.sort do |x,y|
89
- y.statistics_provider.github_pushed_at(y.set).to_i <=> x.statistics_provider.github_pushed_at(x.set).to_i
90
- end
91
- end
92
-
93
- if @sort_by_forks
94
- return pods.sort do |x,y|
95
- y.github_forks.to_i <=> x.github_forks.to_i
96
- end
97
- end
98
- end
99
-
100
- def find_specs(query)
101
- sets = SourcesManager.search_by_name(query.join(' ').strip, @full_text_search)
102
- if @supported_on_ios
103
- sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
104
- end
105
- if @supported_on_osx
106
- sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:osx) }
107
- end
108
-
109
- sets
110
- end
111
- end
112
- end
113
- end
114
- end