Skip to content

Commit

Permalink
Revert "Fix rubocop offenses"
Browse files Browse the repository at this point in the history
This reverts commit cc52c72.
  • Loading branch information
sferik committed Sep 14, 2015
1 parent a541b41 commit 109d7c2
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 107 deletions.
113 changes: 77 additions & 36 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,108 @@
Metrics/AbcSize:
AbcSize:
Enabled: false

Metrics/BlockNesting:
Max: 2
# Enforce outdenting of access modifiers (i.e. public, private, protected)
AccessModifierIndentation:
EnforcedStyle: outdent

Metrics/LineLength:
AllowURI: true
Enabled: false
AllCops:
Include:
- 'Gemfile'
- 'Rakefile'
- 'delayed_job.gemspec'

Metrics/MethodLength:
CountComments: false
Max: 47 # TODO: Lower to 15
# Avoid more than `Max` levels of nesting.
BlockNesting:
Max: 2

Metrics/ModuleLength:
Max: 150 # TODO: Lower to 100
# Indentation of when/else
CaseIndentation:
IndentWhenRelativeTo: end
IndentOneStep: false

Metrics/ParameterLists:
Max: 4
CountKeywordArgs: true

Style/AccessModifierIndentation:
EnforcedStyle: outdent
ClassLength:
Max: 100

Style/CollectionMethods:
# Align with the style guide.
CollectionMethods:
PreferredMethods:
map: 'collect'
collect: 'map'
collect!: 'map!'
reduce: 'inject'
find: 'detect'
find_all: 'select'

Style/Documentation:
# Disable documentation checking until a class needs to be documented once
Documentation:
Enabled: false

Style/DotPosition:
# Allow dots at the end of lines
DotPosition:
EnforcedStyle: trailing

Style/DoubleNegation:
DoubleNegation:
Enabled: false

Style/EachWithObject:
Enabled: false
EmptyLinesAroundAccessModifier:
Enabled: true

Style/Encoding:
# Don't require magic comment at the top of every file
Encoding:
Enabled: false

Style/HashSyntax:
# Align ends correctly
EndAlignment:
AlignWith: variable

# Enforce Ruby 1.8-compatible hash syntax
HashSyntax:
EnforcedStyle: hash_rockets

Style/Lambda:
Lambda:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact
LineLength:
Enabled: false

MethodLength:
CountComments: false
Max: 53

MultilineOperationIndentation:
EnforcedStyle: indented

# Avoid long parameter lists
ParameterLists:
Max: 4
CountKeywordArgs: true

Style/RegexpLiteral:
Exclude:
- lib/delayed/psych_ext.rb
PercentLiteralDelimiters:
PreferredDelimiters:
'%': ()
'%i': ()
'%q': ()
'%Q': ()
'%r': '{}'
'%s': ()
'%w': '[]'
'%W': '[]'
'%x': ()

RaiseArgs:
EnforcedStyle: exploded

RescueModifier:
Enabled: false

Style/SpaceInsideHashLiteralBraces:
SignalException:
EnforcedStyle: only_raise

# No spaces inside hash literals
SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Style/StructInheritance:
SymbolProc:
Enabled: false

Style/TrailingComma:
EnforcedStyleForMultiline: 'comma'
TrailingComma:
Enabled: false
4 changes: 2 additions & 2 deletions delayed_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Gem::Specification.new do |spec|
spec.authors = ['Brandon Keepers', 'Brian Ryckbost', 'Chris Gaffney', 'David Genord II', 'Erik Michaels-Ober', 'Matt Griffin', 'Steve Richert', 'Tobias Lütke']
spec.description = 'Delayed_job (or DJ) encapsulates the common pattern of asynchronously executing longer tasks in the background. It is a direct extraction from Shopify where the job table is responsible for a multitude of core tasks.'
spec.email = ['[email protected]']
spec.files = %w(CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job.gemspec)
spec.files += Dir.glob('{contrib,lib,recipes,spec}/**/*')
spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile delayed_job.gemspec]
spec.files += Dir.glob('{contrib,lib,recipes,spec}/**/*')
spec.homepage = 'http:https://github.com/collectiveidea/delayed_job'
spec.licenses = ['MIT']
spec.name = 'delayed_job'
Expand Down
8 changes: 4 additions & 4 deletions lib/delayed/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module ClassMethods
def enqueue(*args) # rubocop:disable CyclomaticComplexity
options = args.extract_options!
options[:payload_object] ||= args.shift
options[:priority] ||= Delayed::Worker.default_priority
options[:priority] ||= Delayed::Worker.default_priority

if options[:queue].nil?
if options[:payload_object].respond_to?(:queue_name)
Expand All @@ -26,7 +26,7 @@ def enqueue(*args) # rubocop:disable CyclomaticComplexity
end

unless options[:payload_object].respond_to?(:perform)
fail ArgumentError.new('Cannot enqueue items which do not respond to perform')
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
end

new(options).tap do |job|
Expand Down Expand Up @@ -74,7 +74,7 @@ def failed?
end
alias_method :failed, :failed?

ParseObjectFromYaml = %r{\!ruby/\w+\:([^\s]+)} # rubocop:disable ConstantName
ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/ # rubocop:disable ConstantName

def name
@name ||= payload_object.respond_to?(:display_name) ? payload_object.display_name : payload_object.class.name
Expand All @@ -90,7 +90,7 @@ def payload_object=(object)
def payload_object
@payload_object ||= YAML.load_dj(handler)
rescue TypeError, LoadError, NameError, ArgumentError, SyntaxError, Psych::SyntaxError => e
raise DeserializationError.new("Job failed to load: #{e.message}. Handler: #{handler.inspect}")
raise DeserializationError, "Job failed to load: #{e.message}. Handler: #{handler.inspect}"
end

def invoke_job
Expand Down
10 changes: 5 additions & 5 deletions lib/delayed/backend/shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def create_job(opts = {})
CallbackJob.messages = []
end

%w(before success after).each do |callback|
%w[before success after].each do |callback|
it "calls #{callback} with job" do
job = described_class.enqueue(CallbackJob.new)
expect(job.payload_object).to receive(callback).with(job)
Expand All @@ -154,7 +154,7 @@ def create_job(opts = {})
job = described_class.enqueue(CallbackJob.new)
expect(CallbackJob.messages).to eq(['enqueue'])
job.invoke_job
expect(CallbackJob.messages).to eq(%w(enqueue before perform success after))
expect(CallbackJob.messages).to eq(%w[enqueue before perform success after])
end

it 'calls the after callback with an error' do
Expand Down Expand Up @@ -374,7 +374,7 @@ def create_job(opts = {})

context 'when worker has two queue set' do
before(:each) do
worker.queues = %w(large small)
worker.queues = %w[large small]
end

it 'only works off jobs which are from its queue' do
Expand Down Expand Up @@ -472,7 +472,7 @@ def create_job(opts = {})
if story.respond_to?(:new_record?)
expect { story.delay.tell }.to raise_error(
ArgumentError,
"job cannot be created for non-persisted record: #{story.inspect}",
"job cannot be created for non-persisted record: #{story.inspect}"
)
end
end
Expand All @@ -482,7 +482,7 @@ def create_job(opts = {})
story.destroy
expect { story.delay.tell }.to raise_error(
ArgumentError,
"job cannot be created for non-persisted record: #{story.inspect}",
"job cannot be created for non-persisted record: #{story.inspect}"
)
end
end
Expand Down
10 changes: 3 additions & 7 deletions lib/delayed/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(args) # rubocop:disable MethodLength
@options = {
:quiet => true,
:pid_dir => "#{root}/tmp/pids",
:log_dir => "#{root}/log",
:log_dir => "#{root}/log"
}

@worker_count = 1
Expand Down Expand Up @@ -88,7 +88,7 @@ def daemonize # rubocop:disable PerceivedComplexity
setup_pools
elsif @options[:identifier]
if worker_count > 1
fail ArgumentError.new('Cannot specify both --number-of-workers and --identifier')
raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
else
run_process("delayed_job.#{@options[:identifier]}", @options)
end
Expand Down Expand Up @@ -147,11 +147,7 @@ def parse_worker_pool(pool)
else
queues = queues.split(',')
end
worker_count = begin
(worker_count || 1).to_i
rescue
1
end
worker_count = (worker_count || 1).to_i rescue 1
@worker_pools << [queues, worker_count]
end

Expand Down
8 changes: 4 additions & 4 deletions lib/delayed/lifecycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Lifecycle
:perform => [:worker, :job],
:error => [:worker, :job],
:failure => [:worker, :job],
:invoke_job => [:job],
:invoke_job => [:job]
}

def initialize
Expand All @@ -34,7 +34,7 @@ def run_callbacks(event, *args, &block)
missing_callback(event) unless @callbacks.key?(event)

unless EVENTS[event].size == args.size
fail ArgumentError.new("Callback #{event} expects #{EVENTS[event].size} parameter(s): #{EVENTS[event].join(', ')}")
raise ArgumentError, "Callback #{event} expects #{EVENTS[event].size} parameter(s): #{EVENTS[event].join(', ')}"
end

@callbacks[event].execute(*args, &block)
Expand All @@ -48,7 +48,7 @@ def add(type, event, &block)
end

def missing_callback(event)
fail InvalidCallback.new("Unknown callback event: #{event}")
raise InvalidCallback, "Unknown callback event: #{event}"
end
end

Expand Down Expand Up @@ -78,7 +78,7 @@ def add(type, &callback)
chain = @around # use a local variable so that the current chain is closed over in the following lambda
@around = lambda { |*a, &block| chain.call(*a) { |*b| callback.call(*b, &block) } }
else
fail InvalidCallback.new("Invalid callback type: #{type}")
raise InvalidCallback, "Invalid callback type: #{type}"
end
end
end
Expand Down
16 changes: 6 additions & 10 deletions lib/delayed/message_sending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ def send_at(time, method, *args)

module ClassMethods
def handle_asynchronously(method, opts = {})
aliased_method = method.to_s.sub(/([?!=])$/, '')
punctuation = $1 # rubocop:disable PerlBackrefs
with_method = "#{aliased_method}_with_delay#{punctuation}"
without_method = "#{aliased_method}_without_delay#{punctuation}"
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1 # rubocop:disable PerlBackrefs
with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}"
define_method(with_method) do |*args|
curr_opts = opts.clone
curr_opts.each_key do |key|
next unless (val = curr_opts[key]).is_a?(Proc)
curr_opts[key] = begin
if val.arity == 1
val.call(self)
else
val.call
end
curr_opts[key] = if val.arity == 1
val.call(self)
else
val.call
end
end
delay(curr_opts).__send__(without_method, *args)
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/performable_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def delay(options = {})

Mail::Message.class_eval do
def delay(*_args)
fail 'Use MyMailer.delay.mailer_action(args) to delay sending of emails.'
raise 'Use MyMailer.delay.mailer_action(args) to delay sending of emails.'
end
end
4 changes: 2 additions & 2 deletions lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class PerformableMethod
delegate :method, :to => :object

def initialize(object, method_name, args)
fail NoMethodError.new("undefined method `#{method_name}' for #{object.inspect}") unless object.respond_to?(method_name, true)
raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

if object.respond_to?(:persisted?) && !object.persisted?
fail ArgumentError.new("job cannot be created for non-persisted record: #{object.inspect}")
raise(ArgumentError, "job cannot be created for non-persisted record: #{object.inspect}")
end

self.object = object
Expand Down
10 changes: 5 additions & 5 deletions lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def encode_with(coder)
coder.map = {
'object' => object,
'method_name' => method_name,
'args' => args,
'args' => args
}
end
end
Expand Down Expand Up @@ -39,7 +39,7 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
begin
klass.find(id)
rescue ActiveRecord::RecordNotFound => error # rubocop:disable BlockNesting
raise Delayed::DeserializationError.new("ActiveRecord::RecordNotFound, class: #{klass}, primary key: #{id} (#{error.message})")
raise Delayed::DeserializationError, "ActiveRecord::RecordNotFound, class: #{klass}, primary key: #{id} (#{error.message})"
end
else
result
Expand All @@ -52,7 +52,7 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
begin
klass.unscoped.find(id)
rescue ActiveRecord::RecordNotFound => error
raise Delayed::DeserializationError.new("ActiveRecord::RecordNotFound, class: #{klass}, primary key: #{id} (#{error.message})")
raise Delayed::DeserializationError, "ActiveRecord::RecordNotFound, class: #{klass}, primary key: #{id} (#{error.message})"
end
when /^!ruby\/Mongoid:(.+)$/
klass = resolve_class(Regexp.last_match[1])
Expand All @@ -61,7 +61,7 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
begin
klass.find(id)
rescue Mongoid::Errors::DocumentNotFound => error
raise Delayed::DeserializationError.new("Mongoid::Errors::DocumentNotFound, class: #{klass}, primary key: #{id} (#{error.message})")
raise Delayed::DeserializationError, "Mongoid::Errors::DocumentNotFound, class: #{klass}, primary key: #{id} (#{error.message})"
end
when /^!ruby\/DataMapper:(.+)$/
klass = resolve_class(Regexp.last_match[1])
Expand All @@ -71,7 +71,7 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
key_names = primary_keys.map { |p| p.name.to_s }
klass.get!(*key_names.map { |k| payload['attributes'][k] })
rescue DataMapper::ObjectNotFoundError => error
raise Delayed::DeserializationError.new("DataMapper::ObjectNotFoundError, class: #{klass} (#{error.message})")
raise Delayed::DeserializationError, "DataMapper::ObjectNotFoundError, class: #{klass} (#{error.message})"
end
else
super
Expand Down
Loading

0 comments on commit 109d7c2

Please sign in to comment.