diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7b462b21b0..76bdfc234b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7d6f92e5b4..de22790c9b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/models/polymorphic/task.rb b/app/models/polymorphic/task.rb index 5a3fda7f33..b21c99e3e0 100644 --- a/app/models/polymorphic/task.rb +++ b/app/models/polymorphic/task.rb @@ -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 diff --git a/lib/fat_free_crm/callback.rb b/lib/fat_free_crm/callback.rb index 060a97d1f3..a6a67c1777 100644 --- a/lib/fat_free_crm/callback.rb +++ b/lib/fat_free_crm/callback.rb @@ -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)] diff --git a/lib/fat_free_crm/core_ext/string.rb b/lib/fat_free_crm/core_ext/string.rb index 4b6609c753..9bc137ab9c 100644 --- a/lib/fat_free_crm/core_ext/string.rb +++ b/lib/fat_free_crm/core_ext/string.rb @@ -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 diff --git a/spec/controllers/tasks_controller_spec.rb b/spec/controllers/tasks_controller_spec.rb index fef1a85345..aff10d4739 100644 --- a/spec/controllers/tasks_controller_spec.rb +++ b/spec/controllers/tasks_controller_spec.rb @@ -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 diff --git a/spec/support/macros.rb b/spec/support/macros.rb index eb88a95531..9d6b83ebcb 100755 --- a/spec/support/macros.rb +++ b/spec/support/macros.rb @@ -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).