cocoapods-plugins 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7bc267f848ee30507851b6302b4291ac9472c34
4
- data.tar.gz: b8dc5813586a454949f0b45f6ffdbc6259ffa300
3
+ metadata.gz: 7c552838da447d326048d02eec308967695cec8f
4
+ data.tar.gz: 2b0144ca6eea883bdb3e05bd847fa5e61fbea201
5
5
  SHA512:
6
- metadata.gz: d75983946efe356128770b4670ce9ec2380f0a954bf8f9932570766d2b201f3713bf16d99ee7a6de0e248a82808ce7dca0e7602790c1ab880421480ee4cb4bf3
7
- data.tar.gz: e71de6205045275b61cd0bfced542d725784aa7bd55a08e4381cd5817f804c888093fce575491270d73a6b1e238d5e5aae08f05cf68b93f7ab416df0c90e7195
6
+ metadata.gz: dce8fd8cb5e3e86461b77ac2c8e23ea46282bbd2b9f319f06857db96d0749eb993dc2a65cad4159baf7827e84eb01db6905879e751afff5381229ca7034faa72
7
+ data.tar.gz: 89da3e37f4788a30393fd6bae3f99657bb7a25d77ab9ff6fa0f4eb567878f1c41a1f299537ff62ab333df7557d0a173b3d63c9821177638b52a8a4c2414e4ce8
data/.gitignore CHANGED
@@ -34,3 +34,7 @@ build/
34
34
  .rvmrc
35
35
 
36
36
  /coverage/
37
+
38
+ # RubyMine Editor
39
+ .idea
40
+
@@ -0,0 +1,61 @@
1
+ AllCops:
2
+ Include:
3
+ - Rakefile
4
+ Exclude:
5
+ - spec/fixtures/**
6
+
7
+ #- CocoaPods -----------------------------------------------------------------#
8
+
9
+ # We adopted raise instead of fail.
10
+ SignalException:
11
+ EnforcedStyle: only_raise
12
+
13
+ # They are idiomatic
14
+ AssignmentInCondition:
15
+ Enabled: false
16
+
17
+ # Allow backticks
18
+ AsciiComments:
19
+ Enabled: false
20
+
21
+ # Indentation clarifies logic branches in implementations
22
+ IfUnlessModifier:
23
+ Enabled: false
24
+
25
+ # No enforced convention here.
26
+ SingleLineBlockParams:
27
+ Enabled: false
28
+
29
+ # We only add the comment when needed.
30
+ Encoding:
31
+ Enabled: false
32
+
33
+ #- CocoaPods support for Ruby 1.8.7 ------------------------------------------#
34
+
35
+ HashSyntax:
36
+ EnforcedStyle: hash_rockets
37
+
38
+ Lambda:
39
+ Enabled: false
40
+
41
+
42
+ #- CocoaPods specs -----------------------------------------------------------#
43
+
44
+ # Allow for `should.match /regexp/`.
45
+ AmbiguousRegexpLiteral:
46
+ Exclude:
47
+ - spec/**
48
+
49
+ # Allow `object.should == object` syntax.
50
+ Void:
51
+ Exclude:
52
+ - spec/**
53
+
54
+ ClassAndModuleChildren:
55
+ Exclude:
56
+ - spec/**
57
+
58
+ UselessComparison:
59
+ Exclude:
60
+ - spec/**
61
+
@@ -1,51 +1,4 @@
1
- HashSyntax:
2
- EnforcedStyle: hash_rockets
3
-
4
- StringLiterals:
5
- Enabled: false
6
- EnforcedStyle: double_quotes
7
-
8
- SignalException:
9
- EnforcedStyle: only_raise
10
-
11
- ConstantName:
12
- Enabled: false
13
-
14
- IfUnlessModifier:
15
- Enabled: false
16
-
17
- EmptyLinesAroundBody:
18
- Enabled: false
19
-
20
- AsciiComments:
21
- Enabled: false
22
-
23
- Proc:
24
- Enabled: false
25
-
26
- BracesAroundHashParameters:
27
- Enabled: false
28
-
29
- Encoding:
30
- Enabled: false
31
-
32
- TrailingComma:
33
- EnforcedStyleForMultiline: comma
34
-
35
- FileName:
36
- Enabled: false
37
-
38
- #------------------------------------------------------------------------------
39
- # Needs fixing
40
- #------------------------------------------------------------------------------
41
-
42
- ClassLength:
43
- Max: 200
44
-
45
- MethodLength:
46
- Max: 18
47
-
48
- LineLength:
49
- Enabled: false
1
+ inherit_from:
2
+ - .rubocop-cocoapods.yml
50
3
 
51
4
 
@@ -1,6 +1,19 @@
1
1
  # Cocoapods::Plugins Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ * Making `pod plugins` an abstract command, with `list` the default subcommand (#11, #12)
6
+ [Olivier Halligon](https://github.com/AliSoftware)
7
+ * Added `search` subcommand to search plugins by name, author and description. (#9)
8
+ [Olivier Halligon](https://github.com/AliSoftware)
9
+ * Refactoring (#10, #13), improved output formatting (#8)
10
+ [Olivier Halligon](https://github.com/AliSoftware)
11
+ * Fixing coding conventions and Rubocop offenses (#17)
12
+ [Olivier Halligon](https://github.com/AliSoftware)
13
+
3
14
  ## 0.1.0
4
15
 
5
16
  * Initial implementation.
6
17
  [David Grandinetti](https://github.com/dbgrandi)
18
+ * Added `create` subcommand to create an empty project for a new plugin.
19
+ [Boris Bügling](https://github.com/neonichu)
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
+ gem 'cocoapods'
6
7
  gem 'bacon'
7
8
  gem 'coveralls', :require => false
8
9
  gem 'mocha-on-bacon'
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cocoapods-plugins (0.1.0)
5
- cocoapods
4
+ cocoapods-plugins (0.1.1)
6
5
  nap
7
6
 
8
7
  GEM
@@ -12,7 +11,7 @@ GEM
12
11
  i18n (~> 0.6, >= 0.6.4)
13
12
  multi_json (~> 1.0)
14
13
  addressable (2.3.6)
15
- ast (1.1.0)
14
+ ast (2.0.0)
16
15
  bacon (1.2.0)
17
16
  claide (0.5.0)
18
17
  cocoapods (0.32.1)
@@ -58,8 +57,8 @@ GEM
58
57
  multi_json (1.9.2)
59
58
  nap (0.7.0)
60
59
  open4 (1.3.3)
61
- parser (2.1.7)
62
- ast (~> 1.1)
60
+ parser (2.1.9)
61
+ ast (>= 1.1, < 3.0)
63
62
  slop (~> 3.4, >= 3.4.5)
64
63
  powerpack (0.0.9)
65
64
  prettybacon (0.0.1)
@@ -68,7 +67,7 @@ GEM
68
67
  rake (10.2.2)
69
68
  rest-client (1.6.7)
70
69
  mime-types (>= 1.16)
71
- rubocop (0.20.0)
70
+ rubocop (0.20.1)
72
71
  json (>= 1.7.7, < 2)
73
72
  parser (~> 2.1.7)
74
73
  powerpack (~> 0.0.6)
@@ -99,6 +98,7 @@ PLATFORMS
99
98
  DEPENDENCIES
100
99
  bacon
101
100
  bundler (~> 1.3)
101
+ cocoapods
102
102
  cocoapods-plugins!
103
103
  coveralls
104
104
  mocha-on-bacon
data/README.md CHANGED
@@ -4,12 +4,36 @@
4
4
  [![Coverage Status](https://coveralls.io/repos/CocoaPods/cocoapods-plugins/badge.png)](https://coveralls.io/r/CocoaPods/cocoapods-plugins)
5
5
  [![Code Climate](https://img.shields.io/codeclimate/github/CocoaPods/cocoapods-plugins.svg)](https://codeclimate.com/github/CocoaPods/cocoapods-plugins)
6
6
 
7
- CocoaPods plugin which shows info about available CocoaPods plugins. Yeah, it's very meta.
7
+ CocoaPods plugin which shows info about available CocoaPods plugins or helps you get started developing a new plugin. Yeah, it's very meta.
8
+
9
+ ## Installation
10
+
11
+ $ gem install cocoapods-plugins
8
12
 
9
13
  ## Usage
10
14
 
15
+ #####List plugins
16
+
11
17
  $ pod plugins
12
18
 
13
- ## Installation
19
+ List all known plugins (according to the list hosted on github.com/CocoaPods/cocoapods.org)
20
+
21
+ #####Search plugins
22
+
23
+ $ pod plugins search QUERY
24
+
25
+ Searches plugins whose name contains the given text (ignoring case). With --full, it searches by name but also by author and description.
26
+
27
+ #####Create a new plugin
28
+
29
+ $ pod plugins create NAME [TEMPLATE_URL]
30
+
31
+ Creates a scaffold for the development of a new plugin according to the CocoaPods best practices.
32
+ If a `TEMPLATE_URL`, pointing to a git repo containing a compatible template, is specified, it will be used in place of the default one.
33
+
34
+ ## Get your plugin listed
35
+
36
+ The list of plugins is in the cocoapods.org repository at [https://github.com/CocoaPods/cocoapods.org/blob/master/data/plugins.json](https://github.com/CocoaPods/cocoapods.org/blob/master/data/plugins.json).
37
+
38
+ To have your plugin listed, submit a pull request that adds your plugin details.
14
39
 
15
- $ gem install cocoapods-plugins
data/Rakefile CHANGED
@@ -1,24 +1,24 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
- task :default => "spec"
3
+ task :default => 'spec'
4
4
 
5
5
  # Bootstrap
6
6
  #-----------------------------------------------------------------------------#
7
7
 
8
8
  task :bootstrap do
9
- sh "bundle install"
9
+ sh 'bundle install'
10
10
  end
11
11
 
12
12
  # Spec
13
13
  #-----------------------------------------------------------------------------#
14
14
 
15
- desc "Runs all the specs"
15
+ desc 'Runs all the specs'
16
16
  task :spec do
17
17
  start_time = Time.now
18
18
  sh "bundle exec bacon #{specs('**')}"
19
19
  duration = Time.now - start_time
20
20
  puts "Tests completed in #{duration}s"
21
- Rake::Task["rubocop"].invoke
21
+ Rake::Task['rubocop'].invoke
22
22
  end
23
23
 
24
24
  def specs(dir)
@@ -36,6 +36,6 @@ task :rubocop do
36
36
  result = cli.run(FileList['{spec,lib}/**/*.rb'])
37
37
  abort('RuboCop failed!') unless result == 0
38
38
  else
39
- puts "[!] Ruby > 1.9 is required to run style checks"
39
+ puts '[!] Ruby > 1.9 is required to run style checks'
40
40
  end
41
41
  end
@@ -4,21 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cocoapods_plugins.rb'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "cocoapods-plugins"
7
+ spec.name = 'cocoapods-plugins'
8
8
  spec.version = CocoapodsPlugins::VERSION
9
- spec.authors = ["David Grandinetti"]
9
+ spec.authors = ['David Grandinetti', 'Olivier Halligon']
10
10
  spec.summary = %q{CocoaPods plugin which shows info about available CocoaPods plugins.}
11
- spec.homepage = "https://github.com/cocoapods/cocoapods-plugins"
12
- spec.license = "MIT"
11
+ spec.description = <<-DESC
12
+ This CocoaPods plugin shows information about all available CocoaPods plugins
13
+ (yes, this is very meta!).
14
+ This CP plugin adds the "pod plugins" command to CocoaPods so that you can list
15
+ all plugins (registered in the reference JSON hosted at CocoaPods/cocoapods.org)
16
+ DESC
17
+ spec.homepage = 'https://github.com/cocoapods/cocoapods-plugins'
18
+ spec.license = 'MIT'
13
19
 
14
20
  spec.files = `git ls-files`.split($/)
15
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
18
24
 
19
- spec.add_runtime_dependency "cocoapods"
20
25
  spec.add_runtime_dependency 'nap'
21
26
 
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
27
+ spec.add_development_dependency 'bundler', '~> 1.3'
28
+ spec.add_development_dependency 'rake'
24
29
  end
@@ -2,5 +2,5 @@
2
2
  # The namespace of the Cocoapods plugins plugin.
3
3
  #
4
4
  module CocoapodsPlugins
5
- VERSION = "0.1.0"
5
+ VERSION = '0.1.1'
6
6
  end
@@ -5,151 +5,24 @@ require 'json'
5
5
  #
6
6
  module Pod
7
7
  class Command
8
-
9
8
  # The pod plugins command.
10
9
  #
11
10
  class Plugins < Command
11
+ require 'pod/command/plugins/list'
12
+ require 'pod/command/plugins/search'
13
+ require 'pod/command/plugins/create'
12
14
 
13
- PLUGINS_URL = 'https://raw.githubusercontent.com/CocoaPods/cocoapods.org/master/data/plugins.json'
14
-
15
- attr_accessor :json
15
+ self.abstract_command = true
16
+ self.default_subcommand = 'list'
16
17
 
17
18
  self.summary = 'Show available CocoaPods plugins'
18
-
19
19
  self.description = <<-DESC
20
- Shows the available CocoaPods plugins and if you have them installed or not.
21
- DESC
22
-
23
- def download_json
24
- response = REST.get(PLUGINS_URL)
25
- if response.ok?
26
- @json = JSON.parse(response.body)
27
- end
28
- end
29
-
30
- def installed?(gemname)
31
- if Gem::Specification.methods.include?(:find_all_by_name)
32
- Gem::Specification.find_all_by_name(gemname).any?
33
- else
34
- # Fallback to Gem.available? for old versions of rubygems
35
- Gem.available?(gemname)
36
- end
37
- end
38
-
39
- def run
40
- UI.puts "Downloading Plugins list..."
41
- begin
42
- download_json unless json
43
- rescue => e
44
- UI.puts e.message
45
- end
46
-
47
- if !json
48
- UI.puts "Could not download plugins list from cocoapods.org"
49
- else
50
- print_plugins
51
- end
52
- end
53
-
54
- def print_plugins
55
- UI.puts "Available CocoaPods Plugins\n\n"
56
-
57
- @json['plugins'].each do |plugin|
58
- UI.puts "Name: #{plugin['name']}"
59
-
60
- if installed?(plugin['gem'])
61
- UI.puts "Gem: #{plugin['gem']}".green
62
- else
63
- UI.puts "Gem: #{plugin['gem']}".yellow
64
- end
65
-
66
- UI.puts "URL: #{plugin['url']}"
67
- UI.puts "\n#{plugin['description']}\n\n"
68
- end
69
- end
70
-
71
- #-----------------------------------------------------------------------#
72
-
73
- # The create subcommand. Used to create a new plugin using either the
74
- # default template (CocoaPods/cocoapods-plugin-template) or a custom
75
- # template
76
- #
77
- class Create < Plugins
78
- self.summary = 'Creates a new plugin'
79
-
80
- self.description = <<-DESC
81
- Creates a scaffold for the development of a new plugin according to the CocoaPods best practices.
82
- If a `TEMPLATE_URL`, pointing to a git repo containing a compatible template, is specified, it will be used in place of the default one.
83
- DESC
84
-
85
- self.arguments = 'NAME [TEMPLATE_URL]'
86
-
87
- def initialize(argv)
88
- @name = argv.shift_argument
89
- @template_url = argv.shift_argument
90
- super
91
- end
92
-
93
- def validate!
94
- super
95
- help! "A name for the plugin is required." if @name.nil? || @name.empty?
96
- help! "The plugin name cannot contain spaces." if @name.match(/\s/)
97
- end
98
-
99
- def run
100
- clone_template
101
- configure_template
102
- end
103
-
104
- private
105
-
106
- #----------------------------------------#
107
-
108
- # !@group Private helpers
109
-
110
- extend Executable
111
- executable :git
112
- executable :ruby
113
-
114
- TEMPLATE_REPO = "https://github.com/CocoaPods/cocoapods-plugin-template.git"
115
- TEMPLATE_INFO_URL = "https://github.com/CocoaPods/cocoapods-plugin-template"
116
-
117
- # Clones the template from the remote in the working directory using
118
- # the name of the plugin.
119
- #
120
- # @return [void]
121
- #
122
- def clone_template
123
- UI.section("Creating `#{@name}` plugin") do
124
- git! "clone '#{template_repo_url}' #{@name}"
125
- end
126
- end
127
-
128
- # Runs the template configuration utilities.
129
- #
130
- # @return [void]
131
- #
132
- def configure_template
133
- UI.section("Configuring template") do
134
- Dir.chdir(@name) do
135
- if File.file? "configure"
136
- system "./configure #{@name}"
137
- else
138
- UI.warn "Template does not have a configure file."
139
- end
140
- end
141
- end
142
- end
143
-
144
- # Checks if a template URL is given else returns the TEMPLATE_REPO URL
145
- #
146
- # @return String
147
- #
148
- def template_repo_url
149
- @template_url || TEMPLATE_REPO
150
- end
151
- end
20
+ Lists or searches the available CocoaPods plugins
21
+ and show if you have them installed or not.
152
22
 
23
+ Also allows you to quickly create a new Cocoapods
24
+ plugin using a provided template.
25
+ DESC
153
26
  end
154
27
  end
155
28
  end
@@ -0,0 +1,93 @@
1
+ module Pod
2
+ class Command
3
+ class Plugins
4
+ # The create subcommand. Used to create a new plugin using either the
5
+ # default template (CocoaPods/cocoapods-plugin-template) or a custom
6
+ # template
7
+ #
8
+ class Create < Plugins
9
+ self.summary = 'Creates a new plugin'
10
+ self.description = <<-DESC
11
+ Creates a scaffold for the development of a new plugin
12
+ according to the CocoaPods best practices.
13
+
14
+ If a `TEMPLATE_URL`, pointing to a git repo containing a
15
+ compatible template, is specified, it will be used
16
+ in place of the default one.
17
+ DESC
18
+
19
+ self.arguments = 'NAME [TEMPLATE_URL]'
20
+
21
+ def initialize(argv)
22
+ @name = argv.shift_argument
23
+ @template_url = argv.shift_argument
24
+ super
25
+ end
26
+
27
+ def validate!
28
+ super
29
+ if @name.nil? || @name.empty?
30
+ help! 'A name for the plugin is required.'
31
+ end
32
+ if @name.match(/\s/)
33
+ help! 'The plugin name cannot contain spaces.'
34
+ end
35
+ end
36
+
37
+ def run
38
+ clone_template
39
+ configure_template
40
+ end
41
+
42
+ #----------------------------------------#
43
+
44
+ private
45
+
46
+ # !@group Private helpers
47
+
48
+ extend Executable
49
+ executable :git
50
+ executable :ruby
51
+
52
+ TEMPLATE_BASE_URL = 'https://github.com/CocoaPods/'
53
+ TEMPLATE_REPO = TEMPLATE_BASE_URL + 'cocoapods-plugin-template.git'
54
+ TEMPLATE_INFO_URL = TEMPLATE_BASE_URL + 'cocoapods-plugin-template'
55
+
56
+ # Clones the template from the remote in the working directory using
57
+ # the name of the plugin.
58
+ #
59
+ # @return [void]
60
+ #
61
+ def clone_template
62
+ UI.section("Creating `#{@name}` plugin") do
63
+ git! "clone '#{template_repo_url}' #{@name}"
64
+ end
65
+ end
66
+
67
+ # Runs the template configuration utilities.
68
+ #
69
+ # @return [void]
70
+ #
71
+ def configure_template
72
+ UI.section('Configuring template') do
73
+ Dir.chdir(@name) do
74
+ if File.file? 'configure'
75
+ system "./configure #{@name}"
76
+ else
77
+ UI.warn 'Template does not have a configure file.'
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ # Checks if a template URL is given else returns the TEMPLATE_REPO URL
84
+ #
85
+ # @return String
86
+ #
87
+ def template_repo_url
88
+ @template_url || TEMPLATE_REPO
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,31 @@
1
+ require 'pod/command/plugins_helper'
2
+
3
+ module Pod
4
+ class Command
5
+ class Plugins
6
+ # The list subcommand. Used to list all known plugins
7
+ #
8
+ class List < Plugins
9
+ self.summary = 'List all known plugins'
10
+ self.description = <<-DESC
11
+ List all known plugins (according to the list
12
+ hosted on github.com/CocoaPods/cocoapods.org)
13
+ DESC
14
+
15
+ def self.options
16
+ super.reject { |option, _| option == '--silent' }
17
+ end
18
+
19
+ def run
20
+ plugins = PluginsHelper.known_plugins
21
+
22
+ UI.title 'Available CocoaPods Plugins:' do
23
+ plugins.each do |plugin|
24
+ PluginsHelper.print_plugin plugin, self.verbose?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ require 'pod/command/plugins_helper'
2
+
3
+ module Pod
4
+ class Command
5
+ class Plugins
6
+ # The search subcommand.
7
+ # Used to search a plugin in the list of known plugins,
8
+ # searching into the name, author description fields
9
+ #
10
+ class Search < Plugins
11
+ self.summary = 'Search for known plugins'
12
+ self.description = <<-DESC
13
+ Searches plugins whose name contains the given text
14
+ (ignoring case).
15
+
16
+ With --full, it also searches by author and description.
17
+ DESC
18
+
19
+ self.arguments = 'QUERY'
20
+
21
+ def self.options
22
+ [
23
+ ['--full', 'Search by name, author, and description']
24
+ ].concat(super.reject { |option, _| option == '--silent' })
25
+ end
26
+
27
+ def initialize(argv)
28
+ @full_text_search = argv.flag?('full')
29
+ @query = argv.shift_argument unless argv.arguments.empty?
30
+ super
31
+ end
32
+
33
+ def validate!
34
+ super
35
+ help! 'A search query is required.' if @query.nil? || @query.empty?
36
+ begin
37
+ /#{@query}/
38
+ rescue RegexpError
39
+ help! 'A valid regular expression is required.'
40
+ end
41
+ end
42
+
43
+ def run
44
+ plugins = PluginsHelper.matching_plugins(@query, @full_text_search)
45
+
46
+ UI.title "Available CocoaPods Plugins matching '#{@query}':"
47
+ plugins.each do |plugin|
48
+ PluginsHelper.print_plugin plugin, self.verbose?
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,128 @@
1
+ module Pod
2
+ class Command
3
+ # This module is used by Command::Plugins::List
4
+ # and Command::Plugins::Search to download and parse
5
+ # the JSON describing the plugins list and manipulate it
6
+ #
7
+ module PluginsHelper
8
+ PLUGINS_URL = 'https://raw.githubusercontent.com/CocoaPods/' \
9
+ 'cocoapods.org/master/data/plugins.json'
10
+
11
+ # Force-download the JSON
12
+ #
13
+ # @return [Hash] The hash representing the JSON with all known plugins
14
+ #
15
+ def self.download_json
16
+ UI.puts 'Downloading Plugins list...'
17
+ response = REST.get(PLUGINS_URL)
18
+ if response.ok?
19
+ parse_json(response.body)
20
+ else
21
+ raise Informative, 'Could not download plugins list ' \
22
+ "from cocoapods.org: #{response.inspect}"
23
+ end
24
+ end
25
+
26
+ # The list of all known plugins, according to
27
+ # the JSON hosted on github's cocoapods.org
28
+ #
29
+ # @return [Array] all known plugins, as listed in the downloaded JSON
30
+ #
31
+ def self.known_plugins
32
+ json = download_json
33
+ json['plugins']
34
+ end
35
+
36
+ # Filter plugins to return only matching ones
37
+ #
38
+ # @param [String] query
39
+ # A query string that corresponds to a valid RegExp pattern.
40
+ #
41
+ # @param [Bool] full_text_search
42
+ # false only searches in the plugin's name.
43
+ # true searches in the plugin's name, author and description.
44
+ #
45
+ # @return [Array] all plugins matching the query
46
+ #
47
+ def self.matching_plugins(query, full_text_search)
48
+ query_regexp = /#{query}/i
49
+ known_plugins.reject do |plugin|
50
+ texts = [plugin['name']]
51
+ if full_text_search
52
+ texts << plugin['author'] if plugin['author']
53
+ texts << plugin['description'] if plugin['description']
54
+ end
55
+ texts.grep(query_regexp).empty?
56
+ end
57
+ end
58
+
59
+ # Tells if a gem is installed
60
+ #
61
+ # @param [String] gem_name
62
+ # The name of the plugin gem to test
63
+ #
64
+ # @return [Bool] true if the gem is installed, false otherwise.
65
+ #
66
+ def self.gem_installed?(gem_name)
67
+ if Gem::Specification.methods.include?(:find_all_by_name)
68
+ Gem::Specification.find_all_by_name(gem_name).any?
69
+ else
70
+ # Fallback to Gem.available? for old versions of rubygems
71
+ Gem.available?(gem_name)
72
+ end
73
+ end
74
+
75
+ # Display information about a plugin
76
+ #
77
+ # @param [Hash] plugin
78
+ # The hash describing the plugin
79
+ #
80
+ # @param [Bool] verbose
81
+ # If true, will also print the author of the plugins.
82
+ # Defaults to false.
83
+ #
84
+ def self.print_plugin(plugin, verbose = false)
85
+ plugin_colored_name = plugin_title(plugin)
86
+
87
+ UI.title(plugin_colored_name, '', 1) do
88
+ UI.puts_indented plugin['description']
89
+ UI.labeled('Gem', plugin['gem'])
90
+ UI.labeled('URL', plugin['url'])
91
+ UI.labeled('Author', plugin['author']) if verbose
92
+ end
93
+ end
94
+
95
+ #----------------#
96
+
97
+ private
98
+
99
+ # Parse the given JSON data, handling parsing errors if any
100
+ #
101
+ # @param [String] json_str
102
+ # The string representation of the JSON to parse
103
+ #
104
+ def self.parse_json(json_str)
105
+ JSON.parse(json_str)
106
+ rescue JSON::ParserError => e
107
+ raise Informative, "Invalid plugins list from cocoapods.org: #{e}"
108
+ end
109
+
110
+ # Format the title line to print the plugin info with print_plugin
111
+ # coloring it according to whether the plugin is installed or not
112
+ #
113
+ # @param [Hash] plugin
114
+ # The hash describing the plugin
115
+ #
116
+ # @return [String] The formatted and colored title
117
+ #
118
+ def self.plugin_title(plugin)
119
+ plugin_name = "-> #{plugin['name']}"
120
+ if gem_installed?(plugin['gem'])
121
+ plugin_name.green
122
+ else
123
+ plugin_name.yellow
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ # The CocoaPods namespace
4
+ #
5
+ module Pod
6
+ describe Command::Plugins::Create do
7
+ extend SpecHelper::PluginsCreateCommand
8
+
9
+ before do
10
+ UI.output = ''
11
+ end
12
+
13
+ it 'registers itself' do
14
+ Command.parse(%w(plugins create))
15
+ .should.be.instance_of Command::Plugins::Create
16
+ end
17
+
18
+ #--- Validation
19
+
20
+ it 'should require a name is passed in' do
21
+ @command = create_command
22
+ # rubocop:disable Lambda
23
+ lambda { @command.validate! }
24
+ .should.raise(CLAide::Help)
25
+ .message.should.match(/A name for the plugin is required./)
26
+ # rubocop:enable Lambda
27
+ end
28
+
29
+ it 'should require a non-empty name is passed in' do
30
+ @command = create_command('')
31
+ # rubocop:disable Lambda
32
+ lambda { @command.validate! }
33
+ .should.raise(CLAide::Help)
34
+ .message.should.match(/A name for the plugin is required./)
35
+ # rubocop:enable Lambda
36
+ end
37
+
38
+ it 'should require the name does not have spaces' do
39
+ @command = create_command('my gem')
40
+ # rubocop:disable Lambda
41
+ lambda { @command.validate! }
42
+ .should.raise(CLAide::Help)
43
+ .message.should.match(/The plugin name cannot contain spaces./)
44
+ # rubocop:enable Lambda
45
+ end
46
+
47
+ #--- Template download
48
+
49
+ it 'should download the default template repository' do
50
+ @command = create_command('cocoapods-banana')
51
+
52
+ template_repo = 'https://github.com/CocoaPods/' \
53
+ 'cocoapods-plugin-template.git'
54
+ git_command = "clone '#{template_repo}' cocoapods-banana"
55
+ @command.expects(:git!).with(git_command)
56
+ @command.expects(:configure_template)
57
+ @command.run
58
+ UI.output.should.include('Creating `cocoapods-banana` plugin')
59
+ end
60
+
61
+ it 'should download the passed in template repository' do
62
+ alt_repo = 'https://github.com/CocoaPods/' \
63
+ 'cocoapods-banana-plugin-template.git'
64
+ @command = create_command('cocoapods-banana', alt_repo)
65
+
66
+ @command.expects(:git!).with("clone '#{alt_repo}' cocoapods-banana")
67
+ @command.expects(:configure_template)
68
+ @command.run
69
+ UI.output.should.include('Creating `cocoapods-banana` plugin')
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ # The CocoaPods namespace
4
+ #
5
+ module Pod
6
+ describe Command::Plugins::List do
7
+ extend SpecHelper::PluginsStubs
8
+
9
+ before do
10
+ UI.output = ''
11
+ @command = Pod::Command::Plugins::List.new CLAide::ARGV.new []
12
+ end
13
+
14
+ it 'registers itself' do
15
+ Command.parse(%w(plugins list))
16
+ .should.be.instance_of Command::Plugins::List
17
+ end
18
+
19
+ #--- Output printing
20
+
21
+ it 'prints out all plugins' do
22
+ stub_plugins_json_request
23
+ @command.run
24
+ UI.output.should.include('github.com/CocoaPods/cocoapods-fake-1')
25
+ UI.output.should.include('github.com/CocoaPods/cocoapods-fake-2')
26
+ UI.output.should.include('github.com/chneukirchen/bacon')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ # The CocoaPods namespace
4
+ #
5
+ module Pod
6
+ describe Command::Plugins::Search do
7
+ extend SpecHelper::PluginsStubs
8
+ extend SpecHelper::PluginsSearchCommand
9
+
10
+ before do
11
+ UI.output = ''
12
+ end
13
+
14
+ it 'registers itself' do
15
+ Command.parse(%w(plugins search))
16
+ .should.be.instance_of Command::Plugins::Search
17
+ end
18
+
19
+ #--- Validation
20
+
21
+ it 'should require a non-empty query' do
22
+ @command = search_command
23
+ # rubocop:disable Lambda
24
+ lambda { @command.validate! }
25
+ .should.raise(CLAide::Help)
26
+ .message.should.match(/A search query is required./)
27
+ # rubocop:enable Lambda
28
+ end
29
+
30
+ it 'should require a valid RegExp as query' do
31
+ @command = search_command('[invalid')
32
+ # rubocop:disable Lambda
33
+ lambda { @command.validate! }
34
+ .should.raise(CLAide::Help)
35
+ .message.should.match(/A valid regular expression is required./)
36
+ # rubocop:enable Lambda
37
+ end
38
+
39
+ #--- Output printing
40
+
41
+ it 'should filter plugins only by name without full search' do
42
+ stub_plugins_json_request
43
+ @command = search_command('search')
44
+ @command.run
45
+ UI.output.should.not.include('-> CocoaPods Fake Gem')
46
+ UI.output.should.include('-> CocoaPods Searchable Fake Gem')
47
+ UI.output.should.not.include('-> Bacon')
48
+ end
49
+
50
+ it 'should filter plugins by name, author, description with full search' do
51
+ stub_plugins_json_request
52
+ @command = search_command('--full', 'search')
53
+ @command.run
54
+ UI.output.should.include('-> CocoaPods Fake Gem')
55
+ UI.output.should.include('-> CocoaPods Searchable Fake Gem')
56
+ UI.output.should.not.include('-> Bacon')
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ # The CocoaPods namespace
4
+ #
5
+ module Pod
6
+ describe Command::PluginsHelper do
7
+ extend SpecHelper::PluginsStubs
8
+
9
+ it 'downloads the json file' do
10
+ stub_plugins_json_request
11
+ json = Command::PluginsHelper.download_json
12
+ json.should.not.be.nil?
13
+ json.should.be.kind_of? Hash
14
+ json['plugins'].size.should.eql? 3
15
+ end
16
+
17
+ it 'handles empty/bad JSON' do
18
+ stub_plugins_json_request 'This is not JSON'
19
+ # rubocop:disable Lambda
20
+ lambda { Command::PluginsHelper.download_json }
21
+ .should.raise(Pod::Informative)
22
+ .message.should.match(/Invalid plugins list from cocoapods.org/)
23
+ # rubocop:enable Lambda
24
+ end
25
+
26
+ it 'notifies the user if the download fails' do
27
+ stub_plugins_json_request '', [404, 'Not Found']
28
+ # rubocop:disable Lambda
29
+ lambda { Command::PluginsHelper.download_json }
30
+ .should.raise(Pod::Informative)
31
+ .message.should
32
+ .match(/Could not download plugins list from cocoapods.org/)
33
+ # rubocop:enable Lambda
34
+ end
35
+
36
+ it 'detects if a gem is installed' do
37
+ Helper = Command::PluginsHelper
38
+ Helper.gem_installed?('bacon').should.be.true
39
+ Helper.gem_installed?('fake-fake-fake-gem').should.be.false
40
+ end
41
+ end
42
+ end
@@ -4,118 +4,17 @@ require File.expand_path('../../spec_helper', __FILE__)
4
4
  #
5
5
  module Pod
6
6
  describe Command::Plugins do
7
-
8
7
  before do
9
8
  argv = CLAide::ARGV.new([])
10
9
  @command = Command::Plugins.new(argv)
11
10
  end
12
11
 
13
- it "registers it self" do
14
- Command.parse(%w(plugins)).should.be.instance_of Command::Plugins
12
+ it 'registers itself and uses the default subcommand' do
13
+ Command.parse(%w(plugins)).should.be.instance_of Command::Plugins::List
15
14
  end
16
15
 
17
- it "exists" do
16
+ it 'exists' do
18
17
  @command.should.not.be.nil?
19
18
  end
20
-
21
- it "has a json attribute that starts out nil" do
22
- @command.json.should.be.nil?
23
- end
24
-
25
- it "downloads the json file" do
26
- json = File.read(fixture('plugins.json'))
27
- stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
28
- @command.download_json
29
- @command.json.should.not.be.nil?
30
- @command.json.should.be.kind_of? Hash
31
- @command.json['plugins'].size.should.eql? 2
32
- end
33
-
34
- it "handles empty/bad JSON" do
35
- stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => "This is not JSON", :headers => {})
36
- @command.run
37
- UI.output.should.include("Could not download plugins list from cocoapods.org")
38
- @command.json.should.be.nil?
39
- end
40
-
41
- it "notifies the user if the download fails" do
42
- stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => [404, "Not Found"])
43
- @command.run
44
- UI.output.should.include("Could not download plugins list from cocoapods.org")
45
- @command.json.should.be.nil?
46
- end
47
-
48
- it "prints out each plugin" do
49
- json_fixture = fixture('plugins.json')
50
- @json = JSON.parse(File.read(json_fixture))
51
- @command.json = @json
52
- @command.run
53
- UI.output.should.include("github.com/CocoaPods/cocoapods-fake")
54
- UI.output.should.include("github.com/chneukirchen/bacon")
55
- end
56
-
57
- it "detects if a gem is installed" do
58
- @command.installed?("bacon").should.be.true
59
- @command.installed?("fake-fake-fake-gem").should.be.false
60
- end
61
-
62
- end
63
-
64
- describe Command::Plugins::Create do
65
- extend SpecHelper::PluginCreateCommand
66
-
67
- it "registers itself" do
68
- Command.parse(%w(plugins create)).should.be.instance_of Command::Plugins::Create
69
- end
70
-
71
- it "should require a name is passed in" do
72
- @command = create_command(argv)
73
- # rubocop:disable Lambda
74
- lambda { @command.validate! }
75
- .should.raise(CLAide::Help)
76
- .message.should.match(/A name for the plugin is required./)
77
- # rubocop:enable Lambda
78
- end
79
-
80
- it "should require a non-empty name is passed in" do
81
- @command = create_command(argv(""))
82
- # rubocop:disable Lambda
83
- lambda { @command.validate! }
84
- .should.raise(CLAide::Help)
85
- .message.should.match(/A name for the plugin is required./)
86
- # rubocop:enable Lambda
87
- end
88
-
89
- it "should require the name does not have spaces" do
90
- @command = create_command(argv("my gem"))
91
- # rubocop:disable Lambda
92
- lambda { @command.validate! }
93
- .should.raise(CLAide::Help)
94
- .message.should.match(/The plugin name cannot contain spaces./)
95
- # rubocop:enable Lambda
96
- end
97
-
98
- it "should download the default template repository" do
99
- @command = create_command(argv("cocoapods-banana"))
100
- # @command = Command::Plugins::Create.new(argv("cocoapods-banana"))
101
-
102
- git_command = "clone 'https://github.com/CocoaPods/cocoapods-plugin-template.git' cocoapods-banana"
103
- @command.expects(:git!).with(git_command)
104
- @command.expects(:configure_template)
105
- @command.run
106
- UI.output.should.include("Creating `cocoapods-banana` plugin")
107
- end
108
-
109
- it "should download the passed in template repository" do
110
- alt_repository = "https://github.com/CocoaPods/cocoapods-banana-plugin-template.git"
111
- @command = create_command(argv("cocoapods-banana", alt_repository))
112
-
113
- @command.expects(:git!).with("clone '#{alt_repository}' cocoapods-banana")
114
- @command.expects(:configure_template)
115
- @command.run
116
- UI.output.should.include("Creating `cocoapods-banana` plugin")
117
- end
118
-
119
19
  end
120
-
121
20
  end
@@ -1,16 +1,22 @@
1
1
  {
2
2
  "plugins":[
3
3
  {
4
- "gem":"cocoapods-fake-fake-fake",
4
+ "gem":"cocoapods-fake-fake-fake-1",
5
5
  "name":"CocoaPods Fake Gem",
6
- "url":"https://github.com/CocoaPods/cocoapods-fake",
7
- "description":"A Pod that should not exist."
6
+ "url":"https://github.com/CocoaPods/cocoapods-fake-1",
7
+ "description":"A Pod that should not exist and should only be found by full search"
8
8
  },
9
9
  {
10
10
  "gem":"bacon",
11
11
  "name":"Bacon",
12
12
  "url":"https://github.com/chneukirchen/bacon",
13
13
  "description":"A minimal RSpec clone."
14
- }
14
+ },
15
+ {
16
+ "gem":"cocoapods-fake-fake-fake-2",
17
+ "name":"CocoaPods Searchable Fake Gem",
18
+ "url":"https://github.com/CocoaPods/cocoapods-fake-2",
19
+ "description":"A Pod that should not exist but should be found with search"
20
+ }
15
21
  ]
16
22
  }
@@ -38,7 +38,6 @@ require 'cocoapods_plugin'
38
38
  # The CocoaPods namespace
39
39
  #
40
40
  module Pod
41
-
42
41
  # Disable the wrapping so the output is deterministic in the tests.
43
42
  #
44
43
  UI.disable_wrap = true
@@ -85,19 +84,30 @@ end
85
84
 
86
85
  #-----------------------------------------------------------------------------#
87
86
 
88
- # Pod namespace
87
+ # SpecHelper namespace
89
88
  #
90
89
  module SpecHelper
91
- # Add this as an extention into the Create specs
92
- module PluginCreateCommand
93
-
94
- def argv(*args)
95
- CLAide::ARGV.new(args)
90
+ # Add this as an extension into the Search and List specs
91
+ # to help stub the plugins.json request
92
+ module PluginsStubs
93
+ def stub_plugins_json_request(json = nil, status = 200)
94
+ body = json || File.read(fixture('plugins.json'))
95
+ stub_request(:get, Pod::Command::PluginsHelper::PLUGINS_URL)
96
+ .to_return(:status => status, :body => body, :headers => {})
96
97
  end
98
+ end
97
99
 
98
- def create_command(args)
99
- Pod::Command::Plugins::Create.new(args)
100
+ # Add this as an extension into the Create specs
101
+ module PluginsCreateCommand
102
+ def create_command(*args)
103
+ Pod::Command::Plugins::Create.new CLAide::ARGV.new(args)
100
104
  end
105
+ end
101
106
 
107
+ # Add this as an extension into the Search specs
108
+ module PluginsSearchCommand
109
+ def search_command(*args)
110
+ Pod::Command::Plugins::Search.new CLAide::ARGV.new(args)
111
+ end
102
112
  end
103
113
  end
metadata CHANGED
@@ -1,29 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Grandinetti
8
+ - Olivier Halligon
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
12
13
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: cocoapods
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
14
  - !ruby/object:Gem::Dependency
28
15
  name: nap
29
16
  requirement: !ruby/object:Gem::Requirement
@@ -66,13 +53,18 @@ dependencies:
66
53
  - - '>='
67
54
  - !ruby/object:Gem::Version
68
55
  version: '0'
69
- description:
56
+ description: |2
57
+ This CocoaPods plugin shows information about all available CocoaPods plugins
58
+ (yes, this is very meta!).
59
+ This CP plugin adds the "pod plugins" command to CocoaPods so that you can list
60
+ all plugins (registered in the reference JSON hosted at CocoaPods/cocoapods.org)
70
61
  email:
71
62
  executables: []
72
63
  extensions: []
73
64
  extra_rdoc_files: []
74
65
  files:
75
66
  - .gitignore
67
+ - .rubocop-cocoapods.yml
76
68
  - .rubocop.yml
77
69
  - .travis.yml
78
70
  - CHANGELOG.md
@@ -85,6 +77,14 @@ files:
85
77
  - lib/cocoapods_plugin.rb
86
78
  - lib/cocoapods_plugins.rb
87
79
  - lib/pod/command/plugins.rb
80
+ - lib/pod/command/plugins/create.rb
81
+ - lib/pod/command/plugins/list.rb
82
+ - lib/pod/command/plugins/search.rb
83
+ - lib/pod/command/plugins_helper.rb
84
+ - spec/command/plugins/create_spec.rb
85
+ - spec/command/plugins/list_spec.rb
86
+ - spec/command/plugins/search_spec.rb
87
+ - spec/command/plugins_helper_spec.rb
88
88
  - spec/command/plugins_spec.rb
89
89
  - spec/fixtures/plugins.json
90
90
  - spec/spec_helper.rb
@@ -108,11 +108,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.0.6
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: CocoaPods plugin which shows info about available CocoaPods plugins.
115
115
  test_files:
116
+ - spec/command/plugins/create_spec.rb
117
+ - spec/command/plugins/list_spec.rb
118
+ - spec/command/plugins/search_spec.rb
119
+ - spec/command/plugins_helper_spec.rb
116
120
  - spec/command/plugins_spec.rb
117
121
  - spec/fixtures/plugins.json
118
122
  - spec/spec_helper.rb