Skip to content

Commit

Permalink
[Rubocop] Fixing empty & long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
AliSoftware committed May 2, 2014
1 parent 61f2c89 commit 7c1ef13
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 93 deletions.
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
29 changes: 18 additions & 11 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 @@ -22,11 +22,13 @@ def self.download_json
raise Informative, "Invalid plugins list from cocoapods.org: #{e}"
end
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 +79,20 @@ 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's name,
# description, gem, url and author
#
# @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
if gem_installed?(plugin['gem'])
plugin_colored_name = plugin_name.green
else
plugin_colored_name = plugin_name.yellow
end

UI.title(plugin_colored_name, '', 1) do
UI.puts_indented plugin['description']
Expand Down
20 changes: 3 additions & 17 deletions rubocop-todo.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-05-02 03:43:41 +0200 using RuboCop version 0.20.1.
# on 2014-05-02 03:45:11 +0200 using RuboCop version 0.20.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 32
# Cop supports --auto-correct.
EmptyLinesAroundBody:
Enabled: false

# Offense count: 32
LineLength:
Max: 152

# Offense count: 1
# Offense count: 2
# Configuration parameters: CountComments.
MethodLength:
Max: 11

# Offense count: 1
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
TrailingComma:
Enabled: false
Max: 12
17 changes: 9 additions & 8 deletions spec/command/plugins/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# The CocoaPods namespace
#
module Pod

describe Command::Plugins::Create do
extend SpecHelper::PluginsCreateCommand

Expand All @@ -12,7 +11,8 @@ module Pod
end

it 'registers itself' do
Command.parse(%w(plugins create)).should.be.instance_of Command::Plugins::Create
Command.parse(%w(plugins create))
.should.be.instance_of Command::Plugins::Create
end

#--- Validation
Expand Down Expand Up @@ -49,23 +49,24 @@ module Pod
it 'should download the default template repository' do
@command = create_command('cocoapods-banana')

git_command = "clone 'https://github.com/CocoaPods/cocoapods-plugin-template.git' cocoapods-banana"
template_repo = 'https://github.com/CocoaPods/' \
'cocoapods-plugin-template.git'
git_command = "clone '#{template_repo}' cocoapods-banana"
@command.expects(:git!).with(git_command)
@command.expects(:configure_template)
@command.run
UI.output.should.include('Creating `cocoapods-banana` plugin')
end

it 'should download the passed in template repository' do
alt_repository = 'https://github.com/CocoaPods/cocoapods-banana-plugin-template.git'
@command = create_command('cocoapods-banana', alt_repository)
alt_repo = 'https://github.com/CocoaPods/' \
'cocoapods-banana-plugin-template.git'
@command = create_command('cocoapods-banana', alt_repo)

@command.expects(:git!).with("clone '#{alt_repository}' cocoapods-banana")
@command.expects(:git!).with("clone '#{alt_repo}' cocoapods-banana")
@command.expects(:configure_template)
@command.run
UI.output.should.include('Creating `cocoapods-banana` plugin')
end

end

end
6 changes: 2 additions & 4 deletions spec/command/plugins/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# The CocoaPods namespace
#
module Pod

describe Command::Plugins::List do
extend SpecHelper::PluginsStubs

Expand All @@ -13,7 +12,8 @@ module Pod
end

it 'registers itself' do
Command.parse(%w(plugins list)).should.be.instance_of Command::Plugins::List
Command.parse(%w(plugins list))
.should.be.instance_of Command::Plugins::List
end

#--- Output printing
Expand All @@ -25,7 +25,5 @@ module Pod
UI.output.should.include('github.com/CocoaPods/cocoapods-fake-2')
UI.output.should.include('github.com/chneukirchen/bacon')
end

end

end
10 changes: 4 additions & 6 deletions spec/command/plugins/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# The CocoaPods namespace
#
module Pod

describe Command::Plugins::Search do
extend SpecHelper::PluginsStubs
extend SpecHelper::PluginsSearchCommand
Expand All @@ -13,7 +12,8 @@ module Pod
end

it 'registers itself' do
Command.parse(%w(plugins search)).should.be.instance_of Command::Plugins::Search
Command.parse(%w(plugins search))
.should.be.instance_of Command::Plugins::Search
end

#--- Validation
Expand All @@ -38,7 +38,7 @@ module Pod

#--- Output printing

it 'should filter plugins by name when full search is not enabled' do
it 'should filter plugins only by name without full search' do
stub_plugins_json_request
@command = search_command('search')
@command.run
Expand All @@ -47,15 +47,13 @@ module Pod
UI.output.should.not.include('-> Bacon')
end

it 'should filter plugins by name and description when full search is enabled' do
it 'should filter plugins by name, author, description with full search' do
stub_plugins_json_request
@command = search_command('--full', 'search')
@command.run
UI.output.should.include('-> CocoaPods Fake Gem')
UI.output.should.include('-> CocoaPods Searchable Fake Gem')
UI.output.should.not.include('-> Bacon')
end

end

end

0 comments on commit 7c1ef13

Please sign in to comment.