Skip to content

Commit

Permalink
Merge pull request #17 from CocoaPods/rubocop-fixes
Browse files Browse the repository at this point in the history
Use RuboCop config from cocoapods-core .rubocop.yml file
  • Loading branch information
David Grandinetti committed May 2, 2014
2 parents f6b3260 + 5cd1473 commit dbf8fa9
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 134 deletions.
61 changes: 61 additions & 0 deletions .rubocop-cocoapods.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
AllCops:
Include:
- Rakefile
Exclude:
- spec/fixtures/**

#- CocoaPods -----------------------------------------------------------------#

# We adopted raise instead of fail.
SignalException:
EnforcedStyle: only_raise

# They are idiomatic
AssignmentInCondition:
Enabled: false

# Allow backticks
AsciiComments:
Enabled: false

# Indentation clarifies logic branches in implementations
IfUnlessModifier:
Enabled: false

# No enforced convention here.
SingleLineBlockParams:
Enabled: false

# We only add the comment when needed.
Encoding:
Enabled: false

#- CocoaPods support for Ruby 1.8.7 ------------------------------------------#

HashSyntax:
EnforcedStyle: hash_rockets

Lambda:
Enabled: false


#- CocoaPods specs -----------------------------------------------------------#

# Allow for `should.match /regexp/`.
AmbiguousRegexpLiteral:
Exclude:
- spec/**

# Allow `object.should == object` syntax.
Void:
Exclude:
- spec/**

ClassAndModuleChildren:
Exclude:
- spec/**

UselessComparison:
Exclude:
- spec/**

51 changes: 2 additions & 49 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
HashSyntax:
EnforcedStyle: hash_rockets

StringLiterals:
Enabled: false
EnforcedStyle: double_quotes

SignalException:
EnforcedStyle: only_raise

ConstantName:
Enabled: false

IfUnlessModifier:
Enabled: false

EmptyLinesAroundBody:
Enabled: false

AsciiComments:
Enabled: false

Proc:
Enabled: false

BracesAroundHashParameters:
Enabled: false

Encoding:
Enabled: false

TrailingComma:
EnforcedStyleForMultiline: comma

FileName:
Enabled: false

#------------------------------------------------------------------------------
# Needs fixing
#------------------------------------------------------------------------------

ClassLength:
Max: 200

MethodLength:
Max: 18

LineLength:
Enabled: false
inherit_from:
- .rubocop-cocoapods.yml


8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

## 0.1.1

* Making `pod plugins` an abstract command, with `list` the default subcommand (#11 & #12)
* Making `pod plugins` an abstract command, with `list` the default subcommand (#11, #12)
[Olivier Halligon](https://github.com/AliSoftware)
* Added `search` subcommand to search plugins by name, author and description.
* Added `search` subcommand to search plugins by name, author and description. (#9)
[Olivier Halligon](https://github.com/AliSoftware)
* Refactoring, improved output formatting and fixing some coding conventions (#10)
* Refactoring (#10, #13), improved output formatting (#8)
[Olivier Halligon](https://github.com/AliSoftware)
* Fixing coding conventions and Rubocop offenses (#17)
[Olivier Halligon](https://github.com/AliSoftware)

## 0.1.0
Expand Down
10 changes: 5 additions & 5 deletions lib/pod/command/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
#
module Pod
class Command

# The pod plugins command.
#
class Plugins < Command

require 'pod/command/plugins/list'
require 'pod/command/plugins/search'
require 'pod/command/plugins/create'
Expand All @@ -19,10 +17,12 @@ class Plugins < Command

self.summary = 'Show available CocoaPods plugins'
self.description = <<-DESC
Lists or searches the available CocoaPods plugins and show if you have them installed or not.
Also allows you to quickly create a new Cocoapods plugin using a provided template.
DESC
Lists or searches the available CocoaPods plugins
and show if you have them installed or not.
Also allows you to quickly create a new Cocoapods
plugin using a provided template.
DESC
end
end
end
24 changes: 15 additions & 9 deletions lib/pod/command/plugins/create.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module Pod
class Command
class Plugins

# The create subcommand. Used to create a new plugin using either the
# default template (CocoaPods/cocoapods-plugin-template) or a custom
# template
#
class Create < Plugins

self.summary = 'Creates a new plugin'
self.description = <<-DESC
Creates a scaffold for the development of a new plugin according to the CocoaPods best practices.
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.
Creates a scaffold for the development of a new plugin
according to the CocoaPods best practices.
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.
DESC

self.arguments = 'NAME [TEMPLATE_URL]'
Expand All @@ -24,8 +26,12 @@ def initialize(argv)

def validate!
super
help! 'A name for the plugin is required.' if @name.nil? || @name.empty?
help! 'The plugin name cannot contain spaces.' if @name.match(/\s/)
if @name.nil? || @name.empty?
help! 'A name for the plugin is required.'
end
if @name.match(/\s/)
help! 'The plugin name cannot contain spaces.'
end
end

def run
Expand All @@ -43,8 +49,9 @@ def run
executable :git
executable :ruby

TEMPLATE_REPO = 'https://github.com/CocoaPods/cocoapods-plugin-template.git'
TEMPLATE_INFO_URL = 'https://github.com/CocoaPods/cocoapods-plugin-template'
TEMPLATE_BASE_URL = 'https://github.com/CocoaPods/'
TEMPLATE_REPO = TEMPLATE_BASE_URL + 'cocoapods-plugin-template.git'
TEMPLATE_INFO_URL = TEMPLATE_BASE_URL + 'cocoapods-plugin-template'

# Clones the template from the remote in the working directory using
# the name of the plugin.
Expand Down Expand Up @@ -81,7 +88,6 @@ def template_repo_url
@template_url || TEMPLATE_REPO
end
end

end
end
end
11 changes: 5 additions & 6 deletions lib/pod/command/plugins/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
module Pod
class Command
class Plugins

# The list subcommand. Used to list all known plugins
#
class List < Plugins

self.summary = 'List all known plugins'
self.description = <<-DESC
List all known plugins (according to the list hosted on github.com/CocoaPods/cocoapods.org)
List all known plugins (according to the list
hosted on github.com/CocoaPods/cocoapods.org)
DESC

def self.options
Expand All @@ -21,12 +20,12 @@ def run
plugins = PluginsHelper.known_plugins

UI.title 'Available CocoaPods Plugins:' do
plugins.each { |plugin| PluginsHelper.print_plugin plugin, self.verbose? }
plugins.each do |plugin|
PluginsHelper.print_plugin plugin, self.verbose?
end
end
end

end

end
end
end
19 changes: 10 additions & 9 deletions lib/pod/command/plugins/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
module Pod
class Command
class Plugins

# The search subcommand. Used to search a plugin in the list of known plugins,
# The search subcommand.
# Used to search a plugin in the list of known plugins,
# searching into the name, author description fields
#
class Search < Plugins

self.summary = 'Search for known plugins'
self.description = <<-DESC
Searches plugins whose name contains the given text (ignoring case).
With --full, it searches by name but also by author and description.
Searches plugins whose name contains the given text
(ignoring case).
With --full, it also searches by author and description.
DESC

self.arguments = 'QUERY'

def self.options
[
['--full', 'Search by name, author, and description'],
['--full', 'Search by name, author, and description']
].concat(super.reject { |option, _| option == '--silent' })
end

Expand All @@ -43,11 +44,11 @@ def run
plugins = PluginsHelper.matching_plugins(@query, @full_text_search)

UI.title "Available CocoaPods Plugins matching '#{@query}':"
plugins.each { |plugin| PluginsHelper.print_plugin plugin, self.verbose? }
plugins.each do |plugin|
PluginsHelper.print_plugin plugin, self.verbose?
end
end

end

end
end
end
63 changes: 46 additions & 17 deletions lib/pod/command/plugins_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Pod
class Command

# This module is used by Command::Plugins::List and Command::Plugins::Search
# to download and parse the JSON describing the plugins list and manipulate it
# This module is used by Command::Plugins::List
# and Command::Plugins::Search to download and parse
# the JSON describing the plugins list and manipulate it
#
module PluginsHelper

PLUGINS_URL = 'https://raw.githubusercontent.com/CocoaPods/cocoapods.org/master/data/plugins.json'
PLUGINS_URL = 'https://raw.githubusercontent.com/CocoaPods/' \
'cocoapods.org/master/data/plugins.json'

# Force-download the JSON
#
Expand All @@ -16,17 +16,15 @@ def self.download_json
UI.puts 'Downloading Plugins list...'
response = REST.get(PLUGINS_URL)
if response.ok?
begin
JSON.parse(response.body)
rescue JSON::ParserError => e
raise Informative, "Invalid plugins list from cocoapods.org: #{e}"
end
parse_json(response.body)
else
raise Informative, "Could not download plugins list from cocoapods.org: #{response.inspect}"
raise Informative, 'Could not download plugins list ' \
"from cocoapods.org: #{response.inspect}"
end
end

# The list of all known plugins, according to the JSON hosted on github's cocoapods.org
# The list of all known plugins, according to
# the JSON hosted on github's cocoapods.org
#
# @return [Array] all known plugins, as listed in the downloaded JSON
#
Expand Down Expand Up @@ -77,15 +75,14 @@ def self.gem_installed?(gem_name)
# Display information about a plugin
#
# @param [Hash] plugin
# The hash describing the plugin's name, description, gem, url and author
# The hash describing the plugin
#
# @param [Bool] verbose
# If true, will also print the author of the plugins. Defaults to false.
# If true, will also print the author of the plugins.
# Defaults to false.
#
def self.print_plugin(plugin, verbose = false)
plugin_name = "-> #{plugin['name']}"
installed = gem_installed?(plugin['gem'])
plugin_colored_name = installed ? plugin_name.green : plugin_name.yellow
plugin_colored_name = plugin_title(plugin)

UI.title(plugin_colored_name, '', 1) do
UI.puts_indented plugin['description']
Expand All @@ -94,6 +91,38 @@ def self.print_plugin(plugin, verbose = false)
UI.labeled('Author', plugin['author']) if verbose
end
end

#----------------#

private

# Parse the given JSON data, handling parsing errors if any
#
# @param [String] json_str
# The string representation of the JSON to parse
#
def self.parse_json(json_str)
JSON.parse(json_str)
rescue JSON::ParserError => e
raise Informative, "Invalid plugins list from cocoapods.org: #{e}"
end

# Format the title line to print the plugin info with print_plugin
# coloring it according to whether the plugin is installed or not
#
# @param [Hash] plugin
# The hash describing the plugin
#
# @return [String] The formatted and colored title
#
def self.plugin_title(plugin)
plugin_name = "-> #{plugin['name']}"
if gem_installed?(plugin['gem'])
plugin_name.green
else
plugin_name.yellow
end
end
end
end
end

0 comments on commit dbf8fa9

Please sign in to comment.