From 18eaebd9b94746cb47e77d675ba2b35897bac13f Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 8 May 2015 12:33:08 +0200 Subject: [PATCH] Corrected with rubocop cop 'Lint/ShadowingOuterLocalVariable'. --- .rubocop.yml | 2 - app/controllers/long_polling_controller.rb | 6 +-- app/models/application_model.rb | 58 +++++++++++----------- app/models/channel/email_parser.rb | 6 +-- lib/sessions.rb | 4 +- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2f9e07627..d94224b97 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -202,5 +202,3 @@ Style/ClassVars: Enabled: false Lint/UselessAssignment: Enabled: false -Lint/ShadowingOuterLocalVariable: - Enabled: false diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index a9bcbd9ae..777236c37 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -73,9 +73,9 @@ class LongPollingController < ApplicationController # broadcast to recipient list if params['data']['recipient'] && params['data']['recipient']['user_id'] - params['data']['recipient']['user_id'].each { |user_id| - if local_client[:user]['id'].to_s == user_id.to_s - log "send broadcast from (#{client_id}) to (user_id #{user_id})", local_client_id + params['data']['recipient']['user_id'].each { |loop_user_id| + if local_client[:user]['id'].to_s == loop_user_id.to_s + log "send broadcast from (#{client_id}) to (user_id #{loop_user_id})", local_client_id Sessions.send( local_client_id, params['data'] ) end } diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 97d82864c..81f48305b 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -320,10 +320,10 @@ returns return cache if cache records = where( name: data[:name] ) - records.each {|record| - if record.name == data[:name] - cache_set( data[:name], record ) - return record + records.each {|loop_record| + if loop_record.name == data[:name] + cache_set( data[:name], loop_record ) + return loop_record end } return @@ -332,10 +332,10 @@ returns return cache if cache records = where( login: data[:login] ) - records.each {|record| - if record.login == data[:login] - cache_set( data[:login], record ) - return record + records.each {|loop_record| + if loop_record.login == data[:login] + cache_set( data[:login], loop_record ) + return loop_record end } return @@ -362,18 +362,18 @@ returns return record if record elsif data[:name] records = where( name: data[:name] ) - records.each {|record| - return record if record.name == data[:name] + records.each {|loop_record| + return loop_record if loop_record.name == data[:name] } elsif data[:login] records = where( login: data[:login] ) - records.each {|record| - return record if record.login == data[:login] + records.each {|loop_record| + return loop_record if loop_record.login == data[:login] } elsif data[:locale] && data[:source] records = where( locale: data[:locale], source: data[:source] ) - records.each {|record| - return record if record.source == data[:source] + records.each {|loop_record| + return loop_record if loop_record.source == data[:source] } end create(data) @@ -394,19 +394,19 @@ returns def self.create_or_update(data) if data[:id] records = where( id: data[:id] ) - records.each {|record| - record.update_attributes( data ) - return record + records.each {|loop_record| + loop_record.update_attributes( data ) + return loop_record } record = new( data ) record.save return record elsif data[:name] records = where( name: data[:name] ) - records.each {|record| - if record.name == data[:name] - record.update_attributes( data ) - return record + records.each {|loop_record| + if loop_record.name == data[:name] + loop_record.update_attributes( data ) + return loop_record end } record = new( data ) @@ -414,10 +414,10 @@ returns return record elsif data[:login] records = where( login: data[:login] ) - records.each {|record| - if record.login.downcase == data[:login].downcase - record.update_attributes( data ) - return record + records.each {|loop_record| + if loop_record.login.downcase == data[:login].downcase + loop_record.update_attributes( data ) + return loop_record end } record = new( data ) @@ -425,10 +425,10 @@ returns return record elsif data[:locale] records = where( locale: data[:locale] ) - records.each {|record| - if record.locale.downcase == data[:locale].downcase - record.update_attributes( data ) - return record + records.each {|loop_record| + if loop_record.locale.downcase == data[:locale].downcase + loop_record.update_attributes( data ) + return loop_record end } record = new( data ) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index d66d6088c..98b432b64 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -381,11 +381,11 @@ class Channel::EmailParser next if !mail[item.to_sym].tree items = mail[item.to_sym].tree - items.addresses.each {|item| + items.addresses.each {|address_data| user_create( - firstname: item.display_name, + firstname: address_data.display_name, lastname: '', - email: item.address, + email: address_data.address, ) } } diff --git a/lib/sessions.rb b/lib/sessions.rb index 5407c5993..06b558eed 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -422,8 +422,8 @@ returns def self.spool_create( msg ) path = "#{@path}/spool/" FileUtils.mkpath path - file = "#{Time.zone.now.to_f}-#{rand(99_999)}" - File.open( path + '/' + file, 'wb' ) { |file| + file_path = path + "/#{Time.zone.now.to_f}-#{rand(99_999)}" + File.open( file_path, 'wb' ) { |file| data = { msg: msg, timestamp: Time.zone.now.to_i,