Skip to content

Commit

Permalink
Fix new RuboCop violations (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombruijn committed Apr 16, 2017
1 parent 380a755 commit 037214c
Show file tree
Hide file tree
Showing 44 changed files with 223 additions and 366 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Expand Up @@ -13,6 +13,9 @@ AllCops:
UseCache: true
CacheRootDirectory: ./tmp

# Metrics/LineLength:
# Max: 80

Style/Documentation:
Enabled: false

Expand Down Expand Up @@ -42,3 +45,6 @@ Style/IndentArray:

Style/FormatString:
EnforcedStyle: sprintf

Style/SymbolArray:
Enabled: false
38 changes: 9 additions & 29 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-12-27 10:28:00 +0100 using RuboCop version 0.45.0.
# on 2017-04-16 15:04:32 +0200 using RuboCop version 0.48.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
Expand Down Expand Up @@ -52,37 +52,17 @@ Lint/UnderscorePrefixedVariableName:
Exclude:
- 'lib/backup/encryptor/gpg.rb'

# Offense count: 154
Lint/Void:
Exclude:
- 'spec/cli_spec.rb'
- 'spec/compressor/base_spec.rb'
- 'spec/compressor/bzip2_spec.rb'
- 'spec/compressor/custom_spec.rb'
- 'spec/compressor/gzip_spec.rb'
- 'spec/config/dsl_spec.rb'
- 'spec/config_spec.rb'
- 'spec/encryptor/gpg_spec.rb'
- 'spec/encryptor/open_ssl_spec.rb'
- 'spec/logger_spec.rb'
- 'spec/model_spec.rb'
- 'spec/packager_spec.rb'
- 'spec/pipeline_spec.rb'
- 'spec/utilities_spec.rb'

# Offense count: 64
Metrics/AbcSize:
Max: 57

# Offense count: 2
# Configuration parameters: CountComments.
# Offense count: 361
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 28
Exclude:
- "backup.gemspec"
- "spec/**/*"
Max: 796

# Offense count: 1
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4

Expand All @@ -95,11 +75,11 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 15

# Offense count: 203
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# Offense count: 233
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 136
Max: 134

# Offense count: 87
# Configuration parameters: CountComments.
Expand All @@ -109,7 +89,7 @@ Metrics/MethodLength:
# Offense count: 38
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 759
Max: 753

# Offense count: 7
Metrics/PerceivedComplexity:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -4,10 +4,10 @@ gemspec

# Omitted from CI Environment
group :no_ci do
gem "pry"
gem "rb-fsevent" # Mac OS X
gem "rb-inotify" # Linux
gem "pry"

gem "yard"
gem "redcarpet"
gem "yard"
end
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -39,7 +39,7 @@ def current_branch
end

desc "Release new Backup gem version. Use this to release a new version."
task :release do # rubocop:disable Metrics/BlockLength
task :release do
puts "Current version: #{current_version}"
print "Enter new version: "
new_version = $stdin.gets.chomp
Expand Down
2 changes: 1 addition & 1 deletion backup.gemspec
Expand Up @@ -46,7 +46,7 @@ Gem::Specification.new do |gem|
gem.add_dependency "qiniu", "~> 6.5"
gem.add_dependency "nokogiri", "~> 1.7", ">= 1.7.1"

gem.add_development_dependency "rubocop", "0.45.0"
gem.add_development_dependency "rubocop", "0.48.1"
gem.add_development_dependency "rake"
gem.add_development_dependency "rspec", "3.5.0"
gem.add_development_dependency "mocha", "0.14.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/backup.rb
Expand Up @@ -120,7 +120,7 @@ module Notifier

##
# Require Backup base files
%w(
%w[
errors
logger
utilities
Expand All @@ -136,5 +136,5 @@ module Notifier
splitter
template
version
).each { |lib| require File.join(LIBRARY_PATH, lib) }
].each { |lib| require File.join(LIBRARY_PATH, lib) }
end
2 changes: 1 addition & 1 deletion lib/backup/cli.rb
Expand Up @@ -271,7 +271,7 @@ def check
desc: "Path to your Backup configuration file"

# options with their available values
%w(databases storages syncers encryptor compressor notifiers).each do |name|
%w[databases storages syncers encryptor compressor notifiers].each do |name|
path = File.join(Backup::TEMPLATE_PATH, "cli", name)
opts = Dir[path + "/*"].sort.map { |p| File.basename(p) }.join(", ")
method_option name, type: :string, desc: "(#{opts})"
Expand Down
4 changes: 3 additions & 1 deletion lib/backup/config/dsl.rb
Expand Up @@ -77,7 +77,9 @@ def initialize

# Allow users to set command line path options in config.rb
[:root_path, :data_path, :tmp_path].each do |name|
define_method name, ->(path) { _config_options[name] = path }
define_method name do |path|
_config_options[name] = path
end
end

# Allows users to create preconfigured models.
Expand Down
1 change: 0 additions & 1 deletion lib/backup/database/mongodb.rb
Expand Up @@ -58,7 +58,6 @@ def perform!
lock_database if @lock
dump!
package!

ensure
unlock_database if @lock
end
Expand Down
1 change: 0 additions & 1 deletion lib/backup/database/redis.rb
Expand Up @@ -121,7 +121,6 @@ def save!
Response was: #{resp}
EOS
end

rescue Error
if resp =~ /save already in progress/
unless (attempts ||= "0").next! == "5"
Expand Down
5 changes: 1 addition & 4 deletions lib/backup/encryptor/gpg.rb
Expand Up @@ -413,7 +413,6 @@ def encrypt_with
end

yield "#{utility(:gpg)} #{base_options} #{mode_options}", ".gpg"

ensure
cleanup
end
Expand Down Expand Up @@ -470,7 +469,7 @@ def setup_gpg_homedir
FileUtils.chown(Config.user, nil, path)
FileUtils.chmod(0o700, path)

unless %w(pubring.gpg secring.gpg trustdb.gpg)
unless %w[pubring.gpg secring.gpg trustdb.gpg]
.all? { |name| File.exist? File.join(path, name) }
run("#{utility(:gpg)} --homedir '#{path}' -K 2>&1 >/dev/null")
end
Expand Down Expand Up @@ -507,7 +506,6 @@ def setup_gpg_config
check_gpg_config(file.path)

file.path

rescue => err
cleanup
raise Error.wrap(err, "Error creating temporary file for #gpg_config.")
Expand Down Expand Up @@ -670,7 +668,6 @@ def import_key(identifier, key)
keyid = ret.match(/ 0x(\w{16})/).to_a[1]
raise "GPG Returned:\n#{ret.gsub(/^\s*/, " ")}" unless keyid
keyid

rescue => err
Logger.warn Error.wrap(
err, "Public key import failed for '#{identifier}'"
Expand Down
4 changes: 2 additions & 2 deletions lib/backup/errors.rb
Expand Up @@ -3,11 +3,11 @@ module Backup
# See the specs for details.
module NestedExceptions
def self.included(klass)
klass.extend Module.new {
klass.extend(Module.new do
def wrap(wrapped_exception, msg = nil)
new(msg, wrapped_exception)
end
}
end)
end

def initialize(obj = nil, wrapped_exception = nil)
Expand Down
5 changes: 0 additions & 5 deletions lib/backup/model.rb
Expand Up @@ -268,14 +268,11 @@ def perform!
end

syncers.each(&:perform!)

rescue Interrupt
@interrupted = true
raise

rescue Exception => err
@exception = err

ensure
unless @interrupted
set_exit_status
Expand Down Expand Up @@ -403,7 +400,6 @@ def before_hook
Logger.info "Before Hook Starting..."
before.call
Logger.info "Before Hook Finished."

rescue Exception => err
@before_hook_failed = true
ex = err.is_a?(StandardError) ? Error : FatalError
Expand All @@ -422,7 +418,6 @@ def after_hook
Logger.info "After Hook Finished."

set_exit_status # in case hook logged warnings

rescue Exception => err
fatal = !err.is_a?(StandardError)
ex = fatal ? FatalError : Error
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/notifier/mail.rb
Expand Up @@ -180,7 +180,7 @@ def notify!(status)
# Configures the Mail gem by setting the defaults.
# Creates and returns a new email, based on the @delivery_method used.
def new_email
method = %w(smtp sendmail exim file test)
method = %w[smtp sendmail exim file test]
.index(@delivery_method.to_s) ? @delivery_method.to_s : "smtp"

options =
Expand Down
23 changes: 12 additions & 11 deletions lib/backup/packager.rb
Expand Up @@ -73,20 +73,21 @@ def procedure
#
# If no Splitter was configured, the final file output will be
# piped through `cat` into the final output file.
if @splitter
stack << lambda do
@splitter.split_with do |command|
@pipeline << command
stack <<
if @splitter
lambda do
@splitter.split_with do |command|
@pipeline << command
stack.shift.call
end
end
else
lambda do
outfile = File.join(Config.tmp_path, @package.basename)
@pipeline << "#{utility(:cat)} > #{outfile}"
stack.shift.call
end
end
else
stack << lambda do
outfile = File.join(Config.tmp_path, @package.basename)
@pipeline << "#{utility(:cat)} > #{outfile}"
stack.shift.call
end
end

##
# Last Proc to be called runs the Pipeline the procedure built.
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/storage/cloud_files.rb
Expand Up @@ -130,7 +130,7 @@ def remove!(package)
end

def check_configuration
required = %w(username api_key container)
required = %w[username api_key container]
raise Error, <<-EOS if required.map { |name| send(name) }.any?(&:nil?)
Configuration Error
#{required.map { |name| "##{name}" }.join(", ")} are all required
Expand Down
4 changes: 0 additions & 4 deletions lib/backup/storage/dropbox.rb
Expand Up @@ -80,7 +80,6 @@ def connection

# will raise an error if session not authorized
@connection = DropboxClient.new(session, access_type)

rescue => err
raise Error.wrap(err, "Authorization Failed")
end
Expand All @@ -93,7 +92,6 @@ def cached_session
begin
session = DropboxSession.deserialize(File.read(cached_file))
Logger.info "Session data loaded from cache!"

rescue => err
Logger.warn Error.wrap(err, <<-EOS)
Could not read session data from cache.
Expand Down Expand Up @@ -128,7 +126,6 @@ def transfer!
uploader.finish(dest)
end
end

rescue => err
raise Error.wrap(err, "Upload Failed!")
end
Expand Down Expand Up @@ -201,7 +198,6 @@ def create_write_and_return_new_session!
template.render("storage/dropbox/cache_file_written.erb")

session

rescue => err
raise Error.wrap(err, "Could not create or authenticate a new session")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/storage/qiniu.rb
Expand Up @@ -49,7 +49,7 @@ def remove!(package)
end

def check_configuration
required = %w(access_key secret_key bucket)
required = %w[access_key secret_key bucket]

raise Error, <<-EOS if required.map { |name| send(name) }.any?(&:nil?)
Configuration Error
Expand Down
4 changes: 2 additions & 2 deletions lib/backup/storage/s3.rb
Expand Up @@ -125,9 +125,9 @@ def remove!(package)
def check_configuration
required =
if use_iam_profile
%w(bucket)
%w[bucket]
else
%w(access_key_id secret_access_key bucket)
%w[access_key_id secret_access_key bucket]
end
raise Error, <<-EOS if required.map { |name| send(name) }.any?(&:nil?)
Configuration Error
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/syncer/cloud/cloud_files.rb
Expand Up @@ -69,7 +69,7 @@ def get_remote_files(remote_base)
end

def check_configuration
required = %w(username api_key container)
required = %w[username api_key container]
raise Error, <<-EOS if required.map { |name| send(name) }.any?(&:nil?)
Configuration Error
#{required.map { |name| "##{name}" }.join(", ")} are all required
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/syncer/cloud/local_file.rb
Expand Up @@ -37,7 +37,7 @@ def new(*args)
# Returns an Array of file paths and their md5 hashes.
def find_md5(dir, excludes)
found = []
(Dir.entries(dir) - %w(. ..)).map { |e| File.join(dir, e) }.each do |path|
(Dir.entries(dir) - %w[. ..]).map { |e| File.join(dir, e) }.each do |path|
if File.directory?(path)
unless exclude?(excludes, path)
found += find_md5(path, excludes)
Expand Down
4 changes: 2 additions & 2 deletions lib/backup/syncer/cloud/s3.rb
Expand Up @@ -83,9 +83,9 @@ def get_remote_files(remote_base)
def check_configuration
required =
if use_iam_profile
%w(bucket)
%w[bucket]
else
%w(access_key_id secret_access_key bucket)
%w[access_key_id secret_access_key bucket]
end
raise Error, <<-EOS if required.map { |name| send(name) }.any?(&:nil?)
Configuration Error
Expand Down

0 comments on commit 037214c

Please sign in to comment.