Skip to content

Commit

Permalink
Fixes #15016 - Upgrade rubocop (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddavis committed May 12, 2016
1 parent c22b974 commit 5126dd0
Show file tree
Hide file tree
Showing 36 changed files with 151 additions and 116 deletions.
9 changes: 6 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ FormatString:
Style/WordArray:
Enabled: false # don't force usage of %w()

Style/LineLength:
Metrics/LineLength:
Max: 120

Style/GuardClause:
Enabled: false

Style/ClassLength:
Metrics/ClassLength:
Max: 600

Style/CyclomaticComplexity:
Metrics/CyclomaticComplexity:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/SignalException:
EnforcedStyle: semantic
18 changes: 18 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-05-11 14:40:15 -0400 using RuboCop version 0.39.0.
# 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: 39
Metrics/AbcSize:
Max: 60

# Offense count: 7
Metrics/PerceivedComplexity:
Max: 15

Style/Alias:
Enabled: false
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ language:
- ruby

rvm:
- "1.9.3"
- "2.0.0"
- "2.2.0"

script:
- bundle install --without debug
- bundle exec rake test
- bundle exec rake rubocop
- bundle exec rake test
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ group :test do
gem 'minitest', '~> 4.7'
gem 'parseconfig'
gem 'mocha', "~> 0.14.0"
gem 'rubocop', "0.24.1"
gem 'rubocop', "0.39.0"
gem 'coveralls'
end
24 changes: 12 additions & 12 deletions lib/runcible/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def call(method, path, options = {})
#on occation path will already have prefix (sync cancel)
path = clone_config[:api_path] + path unless path.start_with?(clone_config[:api_path])

RestClient.log = []
RestClient.log = []
headers = clone_config[:headers].clone

get_params = options[:params] if options[:params]
path = combine_get_params(path, get_params) if get_params

client_options = {}
client_options[:timeout] = clone_config[:timeout] if clone_config[:timeout]
client_options[:open_timeout] = clone_config[:open_timeout] if clone_config[:open_timeout]
client_options[:verify_ssl] = clone_config[:verify_ssl] unless clone_config[:verify_ssl].nil?
client_options[:timeout] = clone_config[:timeout] if clone_config[:timeout]
client_options[:open_timeout] = clone_config[:open_timeout] if clone_config[:open_timeout]
client_options[:verify_ssl] = clone_config[:verify_ssl] unless clone_config[:verify_ssl].nil?

if clone_config[:oauth]
headers = add_oauth_header(method, path, headers)
Expand All @@ -52,7 +52,7 @@ def call(method, path, options = {})
client_options[:ssl_client_cert] = clone_config[:cert_auth][:ssl_client_cert]
client_options[:ssl_client_key] = clone_config[:cert_auth][:ssl_client_key]
else
client_options[:user] = clone_config[:user]
client_options[:user] = clone_config[:user]
client_options[:password] = config[:http_auth][:password]
end

Expand Down Expand Up @@ -83,7 +83,7 @@ def get_response(client, path, *args)
end

def combine_get_params(path, params)
query_string = params.map do |k, v|
query_string = params.map do |k, v|
if v.is_a? Array
v.map { |y| "#{k}=#{y}" }.join('&')
else
Expand All @@ -105,11 +105,11 @@ def generate_payload(options)
def format_payload_json(payload_hash)
if payload_hash
if payload_hash[:optional]
if payload_hash[:required]
payload = payload_hash[:required].merge(payload_hash[:optional])
else
payload = payload_hash[:optional]
end
payload = if payload_hash[:required]
payload_hash[:required].merge(payload_hash[:optional])
else
payload_hash[:optional]
end
elsif payload_hash[:delta]
payload = payload_hash
else
Expand All @@ -128,7 +128,7 @@ def process_response(response)
if body.respond_to? :with_indifferent_access
body = body.with_indifferent_access
elsif body.is_a? Array
body = body.map do |i|
body = body.map do |i|
i.respond_to?(:with_indifferent_access) ? i.with_indifferent_access : i
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/runcible/extensions/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ def generate_content(type_id, units, options = {})
units.each do |unit|
content_unit = {}
content_unit[:type_id] = type_id
if unit.is_a?(Hash)
#allow user to pass in entire unit
content_unit[:unit_key] = unit
else
content_unit[:unit_key] = { unit_key => unit }
end
content_unit[:unit_key] = if unit.is_a?(Hash)
#allow user to pass in entire unit
unit
else
{ unit_key => unit }
end

content.push(content_unit)
end
Expand All @@ -132,7 +132,7 @@ def generate_content(type_id, units, options = {})
# @param [String, Array] ids array of consumer ids
# @return [RestClient::Response]
def regenerate_applicability_by_ids(ids)
criteria = {
criteria = {
'consumer_criteria' => { 'filters' => { 'id' => { '$in' => ids } } }
}
regenerate_applicability(criteria)
Expand All @@ -149,7 +149,7 @@ def regenerate_applicability_by_ids(ids)
def applicable_errata(ids)
ids = [ids] if ids.is_a? String

criteria = {
criteria = {
'criteria' => { 'filters' => { 'id' => { '$in' => ids } } },
'content_types' => [Runcible::Extensions::Errata.content_type]
}
Expand Down
12 changes: 5 additions & 7 deletions lib/runcible/extensions/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ def create_with_distributors(id, distributors)
# @param [Hash] optional container for all optional parameters
# @return [RestClient::Response] the created repository
def create_with_importer_and_distributors(id, importer, distributors = [], optional = {})
if importer.is_a?(Runcible::Models::Importer)
if importer && importer.is_a?(Runcible::Models::Importer)
optional[:importer_type_id] = importer.id
optional[:importer_config] = importer.config
else
elsif importer
optional[:importer_type_id] = importer.delete('id') || importer.delete(:id)
optional[:importer_config] = importer
end if importer
end

repo_type = if importer.methods.include?(:repo_type)
importer.repo_type
elsif importer.is_a?(Hash) && importer.key?(:repo_type)
importer[:repo_type]
else
nil
end

if optional.key?(:importer_type_id) && repo_type
Expand Down Expand Up @@ -326,7 +324,7 @@ def docker_images(id)
# the [{:image_id => <image hash>, :tag =>"value"}]
# @return [RestClient::Response]
def update_docker_tags(id, tags)
update(id, :scratchpad => {:tags => tags})
update(id, :scratchpad => {:tags => tags})
end

# Creates or updates a sync schedule for a repository
Expand Down Expand Up @@ -387,7 +385,7 @@ def retrieve_with_details(repo_id)
# False is the default option.
# @return [RestClient::Response]
def regenerate_applicability_by_ids(ids, parallel = false)
criteria = {
criteria = {
'parallel' => parallel,
'repo_criteria' => { 'filters' => { 'id' => { '$in' => ids } } }
}
Expand Down
42 changes: 23 additions & 19 deletions lib/runcible/instance.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
module Runcible
class Instance
# rubocop:disable Style/ClassVars
def self.resource_classes
@@resource_classes ||= gather_classes('resources')
@@resource_classes
end

def self.extension_classes
@@extension_classes ||= gather_classes('extensions')
@@extension_classes
end

attr_accessor :resources
attr_accessor :extensions

Expand Down Expand Up @@ -50,6 +39,29 @@ def update_config(key, value)

attr_reader :config

class << self
# rubocop:disable Style/ClassVars
def resource_classes
@@resource_classes ||= gather_classes('resources')
@@resource_classes
end

def extension_classes
@@extension_classes ||= gather_classes('extensions')
@@extension_classes
end

private

def gather_classes(type)
const = Runcible
const = const.const_get(type.camelize)
path = File.dirname(__FILE__) + "/#{type}/*.rb"
base_names = Dir.glob(path).map { |f| File.basename(f, '.rb') }
base_names.map { |name| const.const_get(name.camelize) }
end
end

private

def initialize_wrappers
Expand All @@ -72,14 +84,6 @@ def accessible_class(class_object)
# (e.g. consumer_group)
class_object.name.split('::').last.underscore
end

def self.gather_classes(type)
const = Runcible
const = const.const_get(type.camelize)
path = File.dirname(__FILE__) + "/#{type}/*.rb"
base_names = Dir.glob(path).map { |f| File.basename(f, '.rb') }
base_names.map { |name| const.const_get(name.camelize) }
end
end

#Wrapper class to provide access to instances
Expand Down
2 changes: 1 addition & 1 deletion lib/runcible/models/docker_distributor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Models
class DockerDistributor < Distributor
#optional attributes
attr_accessor 'docker_publish_directory', 'protected',
'redirect_url', 'repo_registry_id'
'redirect_url', 'repo_registry_id'

def initialize(params = {})
super(params)
Expand Down
4 changes: 2 additions & 2 deletions lib/runcible/models/docker_importer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Runcible
module Models
class DockerImporter < Importer
ID = 'docker_importer'
REPO_TYPE = 'docker-repo'
ID = 'docker_importer'.freeze
REPO_TYPE = 'docker-repo'.freeze

attr_accessor 'upstream_name', 'mask_id', 'enable_v1'

Expand Down
2 changes: 1 addition & 1 deletion lib/runcible/models/iso_importer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Runcible
module Models
class IsoImporter < Importer
ID = 'iso_importer'
ID = 'iso_importer'.freeze

# Importer Type id
#
Expand Down
4 changes: 2 additions & 2 deletions lib/runcible/models/ostree_importer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Runcible
module Models
class OstreeImporter < Importer
ID = 'ostree_web_importer'
REPO_TYPE = 'OSTREE'
ID = 'ostree_web_importer'.freeze
REPO_TYPE = 'OSTREE'.freeze

attr_accessor 'branches'

Expand Down
4 changes: 2 additions & 2 deletions lib/runcible/models/puppet_importer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Runcible
module Models
class PuppetImporter < Importer
ID = 'puppet_importer'
REPO_TYPE = 'puppet-repo'
ID = 'puppet_importer'.freeze
REPO_TYPE = 'puppet-repo'.freeze

attr_accessor 'queries'

Expand Down
4 changes: 2 additions & 2 deletions lib/runcible/models/python_importer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Runcible
module Models
class PythonImporter < Importer
ID = 'python_importer'
REPO_TYPE = 'python-repo'
ID = 'python_importer'.freeze
REPO_TYPE = 'python-repo'.freeze

attr_accessor 'packages_names'

Expand Down
10 changes: 5 additions & 5 deletions lib/runcible/models/yum_importer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Runcible
module Models
class YumImporter < Importer
ID = 'yum_importer'
REPO_TYPE = 'rpm-repo'
DOWNLOAD_IMMEDIATE = 'immediate'
DOWNLOAD_ON_DEMAND = 'on_demand'
DOWNLOAD_BACKGROUND = 'background'
ID = 'yum_importer'.freeze
REPO_TYPE = 'rpm-repo'.freeze
DOWNLOAD_IMMEDIATE = 'immediate'.freeze
DOWNLOAD_ON_DEMAND = 'on_demand'.freeze
DOWNLOAD_BACKGROUND = 'background'.freeze
DOWNLOAD_POLICIES = [DOWNLOAD_IMMEDIATE, DOWNLOAD_ON_DEMAND, DOWNLOAD_BACKGROUND].freeze

attr_accessor 'download_policy'
Expand Down
2 changes: 1 addition & 1 deletion lib/runcible/resources/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Consumer < Runcible::Base
# @param [String] id the ID of the consumer
# @return [String] the consumer path, may contain the id if passed
def self.path(id = nil)
(id.nil?) ? 'consumers/' : "consumers/#{id}/"
id.nil? ? 'consumers/' : "consumers/#{id}/"
end

# Creates a consumer
Expand Down
2 changes: 1 addition & 1 deletion lib/runcible/resources/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Content < Runcible::Base
# @param [String] upload_id the id of the upload_request
# @return [String] the content path, may contain the upload_id if passed
def upload_path(upload_id = nil)
(upload_id.nil?) ? 'content/uploads/' : "content/uploads/#{upload_id}/"
upload_id.nil? ? 'content/uploads/' : "content/uploads/#{upload_id}/"
end

# Creates an Upload Request
Expand Down
12 changes: 6 additions & 6 deletions lib/runcible/resources/event_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ module Resources
# @see https://pulp-dev-guide.readthedocs.org/en/latest/events/index.html
class EventNotifier < Runcible::Base
class EventTypes
REPO_SYNC_COMPLETE = 'repo.sync.finish'
REPO_SYNC_START = 'repo.sync.start'
REPO_PUBLISH_COMPLETE = 'repo.publish.finish'
REPO_PUBLISH_START = 'repo.publish.start'
REPO_SYNC_COMPLETE = 'repo.sync.finish'.freeze
REPO_SYNC_START = 'repo.sync.start'.freeze
REPO_PUBLISH_COMPLETE = 'repo.publish.finish'.freeze
REPO_PUBLISH_START = 'repo.publish.start'.freeze
end

class NotifierTypes
REST_API = 'http'
REST_API = 'http'.freeze
end

# Generates the API path for Event Notifiers
#
# @param [String] id the ID of the event notifier
# @return [String] the event notifier path, may contain the ID if passed
def self.path(id = nil)
(id.nil?) ? 'events/' : "events/#{id}/"
id.nil? ? 'events/' : "events/#{id}/"
end

# Creates an Event Notification
Expand Down
Loading

0 comments on commit 5126dd0

Please sign in to comment.