Skip to content

Commit

Permalink
Rubocop: each with object
Browse files Browse the repository at this point in the history
  • Loading branch information
CloCkWeRX committed Jan 10, 2017
1 parent de8a27e commit 55b04a5
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 17 deletions.
11 changes: 0 additions & 11 deletions .rubocop_todo.yml
Expand Up @@ -349,17 +349,6 @@ Style/DoubleNegation:
- 'app/models/polymorphic/task.rb'
- 'lib/gravatar_image_tag.rb'

# Offense count: 6
# Cop supports --auto-correct.
Style/EachWithObject:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/models/polymorphic/task.rb'
- 'lib/fat_free_crm/callback.rb'
- 'lib/fat_free_crm/core_ext/string.rb'
- 'spec/controllers/tasks_controller_spec.rb'
- 'spec/support/macros.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/EmptyCaseCondition:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -45,7 +45,7 @@ def auto_complete
respond_to do |format|
format.any(:js, :html) { render partial: 'auto_complete' }
format.json do
render json: @auto_complete.inject({}){|h, a|
render json: @auto_complete.each_with_object({}){|a, h|
h[a.id] = a.respond_to?(:full_name) ? h(a.full_name) : h(a.name); h
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/polymorphic/task.rb
Expand Up @@ -194,7 +194,7 @@ def self.bucket_empty?(bucket, user, view = "pending")
def self.totals(user, view = "pending")
return {} unless ALLOWED_VIEWS.include?(view)
settings = (view == "completed" ? Setting.task_completed : Setting.task_bucket)
settings.inject(HashWithIndifferentAccess[all: 0]) do |hash, key|
settings.each_with_object(HashWithIndifferentAccess[all: 0]) do |key, hash|
hash[key] = (view == "assigned" ? assigned_by(user).send(key).pending.count : my(user).send(key).send(view).count)
hash[:all] += hash[key]
hash
Expand Down
2 changes: 1 addition & 1 deletion lib/fat_free_crm/callback.rb
Expand Up @@ -52,7 +52,7 @@ def self.view_responder(method)
# - a hash of arrays containing Procs and positions to insert content.
#--------------------------------------------------------------------------
def self.view_hook(hook, caller, context = {})
view_responder(hook).inject(Hash.new([])) do |response, instance|
view_responder(hook).each_with_object(Hash.new([])) do |instance, response|
# Process each operation within each view hook, storing the data in a hash.
instance.class.view_hooks[hook].each do |op|
response[op[:position]] += [op[:proc].call(caller, context)]
Expand Down
2 changes: 1 addition & 1 deletion lib/fat_free_crm/core_ext/string.rb
Expand Up @@ -37,7 +37,7 @@ def name_permutations
(parts.size - 1).times.map do|i|
# ["A", "B", "C", "D"] => [["A B C", "D"], ["A B", "C D"], ["A", "B C D"]]
[parts[(0..i)].join(" "), parts[(i + 1)..-1].join(" ")]
end.inject([]) do |arr, perm|
end.each_with_object([]) do |perm, arr|
# Search both [first, last] and [last, first]
# e.g. for every ["A B C", "D"], also include ["D", "A B C"]
arr << perm
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/tasks_controller_spec.rb
Expand Up @@ -14,7 +14,7 @@ def update_sidebar
def produce_tasks(user, view)
settings = (view != "completed" ? Setting.task_bucket : Setting.task_completed)

settings.inject({}) do | hash, due |
settings.each_with_object({}) do | due, hash |
hash[due] ||= []
if Date.tomorrow == Date.today.end_of_week && due == :due_tomorrow
due = :due_this_week
Expand Down
2 changes: 1 addition & 1 deletion spec/support/macros.rb
Expand Up @@ -22,7 +22,7 @@ def stub_task(view)
#----------------------------------------------------------------------------
def stub_task_total(view = "pending")
settings = (view == "completed" ? Setting.task_completed : Setting.task_bucket)
settings.inject(all: 0) { |hash, key| hash[key] = 1; hash }
settings.each_with_object(all: 0) { |key, hash| hash[key] = 1; hash }
end

# Get current server timezone and set it (see rake time:zones:local for details).
Expand Down

0 comments on commit 55b04a5

Please sign in to comment.