From 44adaf000e1923ccc8b8ecbde82b766f561cf6d6 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 30 Apr 2015 19:34:33 +0200 Subject: [PATCH] Corrected with rubocop cop 'Style/DeprecatedHashMethods'. --- app/models/application_model.rb | 10 +++++----- app/models/channel/imap.rb | 2 +- app/models/channel/pop3.rb | 2 +- app/models/link.rb | 14 +++++++------- app/models/setting.rb | 2 +- lib/import/otrs.rb | 4 ++-- lib/import/otrs2.rb | 12 ++++++------ script/websocket-server.rb | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 27eaf0419..e2e50d9c8 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -81,7 +81,7 @@ returns # only use object attributes data = {} self.new.attributes.each {|item| - if params.has_key?(item[0]) + if params.key?(item[0]) # puts 'use ' + item[0].to_s + '-' + params[item[0]].to_s data[item[0].to_sym] = params[item[0]] end @@ -109,7 +109,7 @@ returns # set relations self.class.reflect_on_all_associations.map { |assoc| real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids' - if params.has_key?( real_key.to_sym ) + if params.key?( real_key.to_sym ) list_of_items = params[ real_key.to_sym ] if params[ real_key.to_sym ].class != Array list_of_items = [ params[ real_key.to_sym ] ] @@ -246,14 +246,14 @@ returns # delete old name / login caches if self.changed? - if self.changes.has_key?('name') + if self.changes.key?('name') name = self.changes['name'][0].to_s key = self.class.to_s + '::' + name Cache.delete( key.to_s ) key = self.class.to_s + ':f:' + name Cache.delete( key.to_s ) end - if self.changes.has_key?('login') + if self.changes.key?('login') name = self.changes['login'][0].to_s key = self.class.to_s + '::' + name Cache.delete( key.to_s ) @@ -844,7 +844,7 @@ log object update history with all updated attributes, if configured - will be e changes = self.changes if self.history_changes_last_done self.history_changes_last_done.each {|key, value| - if changes.has_key?(key) && changes[key] == value + if changes.key?(key) && changes[key] == value changes.delete(key) end } diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index 6bcb05b11..7a9508cf0 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -7,7 +7,7 @@ class Channel::IMAP < Channel::EmailParser def fetch (channel, check_type = '', verify_string = '') ssl = true port = 993 - if channel[:options].has_key?(:ssl) && channel[:options][:ssl].to_s == 'false' + if channel[:options].key?(:ssl) && channel[:options][:ssl].to_s == 'false' ssl = false port = 143 end diff --git a/app/models/channel/pop3.rb b/app/models/channel/pop3.rb index af8abee6a..6ec354757 100644 --- a/app/models/channel/pop3.rb +++ b/app/models/channel/pop3.rb @@ -7,7 +7,7 @@ class Channel::POP3 < Channel::EmailParser def fetch (channel, check_type = '', verify_string = '') ssl = true port = 995 - if channel[:options].has_key?(:ssl) && channel[:options][:ssl].to_s == 'false' + if channel[:options].key?(:ssl) && channel[:options][:ssl].to_s == 'false' ssl = false port = 110 end diff --git a/app/models/link.rb b/app/models/link.rb index 554707e30..b7b5e744b 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -74,19 +74,19 @@ class Link < ApplicationModel def self.add(data) - if data.has_key?(:link_type) + if data.key?(:link_type) linktype = self.link_type_get( name: data[:link_type] ) data[:link_type_id] = linktype.id data.delete( :link_type ) end - if data.has_key?(:link_object_source) + if data.key?(:link_object_source) linkobject = self.link_object_get( name: data[:link_object_source] ) data[:link_object_source_id] = linkobject.id data.delete( :link_object_source ) end - if data.has_key?(:link_object_target) + if data.key?(:link_object_target) linkobject = self.link_object_get( name: data[:link_object_target] ) data[:link_object_target_id] = linkobject.id data.delete( :link_object_target ) @@ -108,18 +108,18 @@ class Link < ApplicationModel =end def self.remove(data) - if data.has_key?(:link_object_source) + if data.key?(:link_object_source) linkobject = self.link_object_get( name: data[:link_object_source] ) data[:link_object_source_id] = linkobject.id end - if data.has_key?(:link_object_target) + if data.key?(:link_object_target) linkobject = self.link_object_get( name: data[:link_object_target] ) data[:link_object_target_id] = linkobject.id end # from one site - if data.has_key?(:link_type) + if data.key?(:link_type) linktype = self.link_type_get( name: data[:link_type] ) data[:link_type_id] = linktype.id end @@ -135,7 +135,7 @@ class Link < ApplicationModel } # from the other site - if data.has_key?(:link_type) + if data.key?(:link_type) linktype = self.link_type_get( name: @map[ data[:link_type] ] ) data[:link_type_id] = linktype.id end diff --git a/app/models/setting.rb b/app/models/setting.rb index 9439d3a77..57dbb7efe 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -61,7 +61,7 @@ class Setting < ApplicationModel return if !(self.state || self.state == false) - return if !( !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) ) + return if !( !self.state.respond_to?('has_key?') || !self.state.key?(:value) ) self.state = { value: self.state } end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index e0cf187dc..ec2fb7456 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -69,7 +69,7 @@ module Import::OTRS } types.each {|config_key, result_key| if config[config_key] - return false if !result[result_key].has_value?( config[config_key] ) + return false if !result[result_key].value?( config[config_key] ) end } @@ -85,7 +85,7 @@ module Import::OTRS types.each {|config_key, result_key| next if !config[config_key] config[config_key].each {|otrs_group, role| - next if !result[result_key].has_value?( otrs_group ) + next if !result[result_key].value?( otrs_group ) role_ids = user.role_ids role = Role.where( name: role ).first next if !role diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index 6731e255c..49996a7b2 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -820,7 +820,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if state.has_key?(key.to_s) + if state.key?(key.to_s) state_new[value] = state[key.to_s] end } @@ -869,7 +869,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if priority.has_key?(key.to_s) + if priority.key?(key.to_s) priority_new[value] = priority[key.to_s] end } @@ -910,7 +910,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if group.has_key?(key.to_s) + if group.key?(key.to_s) group_new[value] = group[key.to_s] end } @@ -965,7 +965,7 @@ module Import::OTRS2 group_ids: group_ids, } map.each { |key, value| - if user.has_key?(key.to_s) + if user.key?(key.to_s) user_new[value] = user[key.to_s] end } @@ -1089,7 +1089,7 @@ module Import::OTRS2 role_ids: [ role_customer.id ], } map.each { |key, value| - if user.has_key?(key.to_s) + if user.key?(key.to_s) user_new[value] = user[key.to_s] end } @@ -1153,7 +1153,7 @@ module Import::OTRS2 updated_by_id: 1, } map.each { |key, value| - if organization.has_key?(key.to_s) + if organization.key?(key.to_s) organization_new[value] = organization[key.to_s] end } diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 75c18eba6..9501ee119 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -191,7 +191,7 @@ EventMachine.run { if data['recipient'].class != Hash log 'error', "recipient attribute isn't a hash '#{ data['recipient'].inspect }'" else - if !data['recipient'].has_key?('user_id') + if !data['recipient'].key?('user_id') log 'error', "need recipient.user_id attribute '#{ data['recipient'].inspect }'" else if data['recipient']['user_id'].class != Array