Skip to content

Commit

Permalink
Merge pull request #7006 from code-dot-org/performanceRedundantMerge
Browse files Browse the repository at this point in the history
Fixes violations of Performance/RedundantMerge and reenables the rubocop check.
  • Loading branch information
ashercodeorg committed Feb 26, 2016
2 parents abf158f + 793ddb3 commit ae184c5
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 21 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ Performance/Casecmp:
Performance/RedundantBlockCall:
Enabled: false

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: MaxKeyValuePairs.
Performance/RedundantMerge:
Enabled: false

# Offense count: 11
# Cop supports --auto-correct.
Performance/StringReplacement:
Expand Down
2 changes: 1 addition & 1 deletion bin/cron/ops_data_pull
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SeamlessDatabasePool.use_persistent_read_connection do
row.merge!(level_hash)
row.merge!({:"Stage #{stage.position} Percent Complete" => percent[stage.position - 1].to_s})
end
row.merge!({:'Script Percent Complete' => percent_complete_total(script, user).to_s})
row[:'Script Percent Complete'] = percent_complete_total(script, user).to_s
headers ||= row.keys
row.values
end
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/cdo-varnish/test/shared/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def local_request(url, headers={}, cookies={})
# Send an HTTP request through the current proxy-cache configuration.
# The proxy-cache configuration is CloudFront+Varnish or Varnish-only.
def proxy_request(url, headers={}, cookies={}, method='GET')
headers.merge!(host: @proxy_host)
headers[:host] = @proxy_host
headers.merge!('X-Forwarded-Proto' => 'https'){|_, v1, _|v1}
_request("#{@proxy_address}#{url}", headers, cookies, method)
end
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/controllers/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create
params[:level][:failure_condition] = Studio.default_failure_condition
end
params[:level][:maze_data] = params[:level][:maze_data].to_json if type_class <= Grid
params.merge!(user: current_user)
params[:user] = current_user

begin
@level = type_class.create_from_level_builder(params, level_params)
Expand Down
3 changes: 2 additions & 1 deletion dashboard/app/helpers/levels_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def blockly_options
# Process level view options
level_overrides = level_view_options.dup
if level_options['embed'] || level_overrides[:embed]
level_overrides.merge!(hide_source: true, show_finish: true)
level_overrides[:hide_source] = true
level_overrides[:show_finish] = true
end
if level_overrides[:embed]
view_options(no_header: true, no_footer: true, white_background: true)
Expand Down
6 changes: 2 additions & 4 deletions dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,8 @@ def self.add_script(options, data)
name: stage_name,
script: script
)
script_level_attributes.merge!(
stage_id: stage.id,
position: (script_level_position[stage.id] += 1)
)
script_level_attributes[:stage_id] = stage.id
script_level_attributes[:position] = (script_level_position[stage.id] += 1)
script_level.reload
script_level.assign_attributes(script_level_attributes)
script_level.save! if script_level.changed?
Expand Down
6 changes: 2 additions & 4 deletions dashboard/app/models/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ def youtube_url(args={})

language = I18n.locale.to_s.downcase.split('-').first
if language != 'en'
defaults.merge!(
cc_lang_pref: language,
cc_load_policy: 1
)
defaults[:cc_lang_pref] = language
defaults[:cc_load_policy] = 1
end
defaults.merge!(args)
"#{Video.youtube_base_url}/embed/#{youtube_code}/?#{defaults.to_query}"
Expand Down
5 changes: 3 additions & 2 deletions lib/cdo/analytics/milestone_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def count_lines_of_code(log)
partial_count = cached['count']
cached_length = cached['length']
fetch_bytes = (length - cached_length)
fetch_params.merge!(range: "bytes=#{cached_length}-")
fetch_params[:range] = "bytes=#{cached_length}-"
debug "Starting content match, downloading remaining #{fetch_bytes} bytes.."
end
end
Expand All @@ -111,7 +111,8 @@ def count_lines_of_code(log)
response = {'count' => count, 'etag' => etag}
unless ext == '.gz'
md5 ||= Digest::MD5.hexdigest `cat #{path} | head -c #{COMPARE_BYTE_LENGTH}`
response.merge!('length' => length, 'md5' => md5)
response['length'] = length
response['md5'] = md5
end
FileUtils.rm path
debug "Count: #{count}"
Expand Down
2 changes: 1 addition & 1 deletion shared/middleware/helpers/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def bad_request()
def json_bad_request(details = nil)
content_type :json
body = { error: 'Bad Request' }
body.merge!(details: details) unless details.nil?
body[:details] = details unless details.nil?
halt(400, body.to_json)
end

Expand Down

0 comments on commit ae184c5

Please sign in to comment.