Skip to content

Commit

Permalink
[Rubocop] Fixing "Method too long" offenses (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
AliSoftware committed May 2, 2014
1 parent 7c1ef13 commit 55d5f23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
48 changes: 35 additions & 13 deletions lib/pod/command/plugins_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ 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}"

This comment has been minimized.

Copy link
@AliSoftware

AliSoftware May 2, 2014

Author Contributor

Wondering if that's the right way to split a long string into multiple lines (especially, is the indentation right and all?)

This comment has been minimized.

Copy link
@segiddins

segiddins May 2, 2014

Member
raise Informative, 'Could not download plugins list ' \
  "from cocoapods.org: #{response.inspect}"

This comment has been minimized.

Copy link
@AliSoftware

AliSoftware May 2, 2014

Author Contributor

Gotcha. Fixed.

Expand Down Expand Up @@ -79,20 +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.
#
def self.print_plugin(plugin, verbose = false)
plugin_name = "-> #{plugin['name']}"
if gem_installed?(plugin['gem'])
plugin_colored_name = plugin_name.green
else
plugin_colored_name = plugin_name.yellow
end
plugin_colored_name = plugin_title(plugin)

UI.title(plugin_colored_name, '', 1) do
UI.puts_indented plugin['description']
Expand All @@ -101,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

This comment has been minimized.

Copy link
@segiddins

segiddins May 2, 2014

Member

does rubocop not complain about the indentation here? just curious

This comment has been minimized.

Copy link
@AliSoftware

AliSoftware May 2, 2014

Author Contributor

No, rubocop is quite silent here.

But I agree, I'm not very satisfied with this strange syntax.

Never saw a rescue without an explicit begin...end block (and if I wrap the method content within begin...end, of course rubocop complains about a redondant begin), so I'm not sure how to indent properly here?

This comment has been minimized.

Copy link
@segiddins

segiddins May 2, 2014

Member

I think you can just un-indent the rescue line, I've seen it done that way elsewhere in the CP codebase

This comment has been minimized.

Copy link
@AliSoftware

AliSoftware May 2, 2014

Author Contributor

You mean putting rescue at the same level as def self.parse_json, right?

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
11 changes: 0 additions & 11 deletions rubocop-todo.yml

This file was deleted.

0 comments on commit 55d5f23

Please sign in to comment.