Skip to content

Commit e293c12

Browse files
committed
Fix rubocop issues
1 parent 0c7c747 commit e293c12

5 files changed

Lines changed: 17 additions & 33 deletions

File tree

app/actions/route_create.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def validation_error!(error, host, path, port, space, domain)
7878

7979
error!("Reserved route ports quota exceeded for organization '#{space.organization.name}'.") if error.errors.on(:organization)&.include?(:total_reserved_route_ports_exceeded)
8080

81-
error!("Hash header must be present when loadbalancing is set to hash") if error.errors.on(:route)&.include?(:hash_header_missing)
81+
error!('Hash header must be present when loadbalancing is set to hash') if error.errors.on(:route)&.include?(:hash_header_missing)
8282

8383
validation_error_routing_api!(error)
8484
validation_error_host!(error, host, domain)

app/actions/route_update.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class Error < StandardError
44
end
55

66
def update(route:, message:)
7-
87
Route.db.transaction do
98
route.options = route.options.symbolize_keys.merge(message.options) if message.requested?(:options)
109
route.save
@@ -25,9 +24,7 @@ def update(route:, message:)
2524

2625
def validation_error!(error)
2726
# Handle hash_header validation error for hash loadbalancing
28-
if error.errors.on(:route)&.include?(:hash_header_missing)
29-
raise Error.new('Hash header must be present when loadbalancing is set to hash')
30-
end
27+
raise Error.new('Hash header must be present when loadbalancing is set to hash') if error.errors.on(:route)&.include?(:hash_header_missing)
3128

3229
# Fallback for any other validation errors
3330
raise Error.new(error.message)

app/messages/manifest_routes_update_message.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def route_options_are_valid
6161
r[:options].each_key do |key|
6262
RouteOptionsMessage.valid_route_options.exclude?(key) &&
6363
errors.add(:base,
64-
message: "Route '#{r[:route]}' contains invalid route option '#{key}'. \
64+
message: "Route '#{r[:route]}' contains invalid route option '#{key}'. \
6565
Valid keys: '#{RouteOptionsMessage.valid_route_options.join(', ')}'")
6666
end
6767
end
@@ -76,13 +76,13 @@ def loadbalancings_are_valid
7676
loadbalancing = r[:options][:loadbalancing]
7777
unless loadbalancing.is_a?(String)
7878
errors.add(:base,
79-
message: "Invalid value for 'loadbalancing' for Route '#{r[:route]}'; \
79+
message: "Invalid value for 'loadbalancing' for Route '#{r[:route]}'; \
8080
Valid values are: '#{RouteOptionsMessage.valid_loadbalancing_algorithms.join(', ')}'")
8181
next
8282
end
8383
RouteOptionsMessage.valid_loadbalancing_algorithms.exclude?(loadbalancing) &&
8484
errors.add(:base,
85-
message: "Cannot use loadbalancing value '#{loadbalancing}' for Route '#{r[:route]}'; \
85+
message: "Cannot use loadbalancing value '#{loadbalancing}' for Route '#{r[:route]}'; \
8686
Valid values are: '#{RouteOptionsMessage.valid_loadbalancing_algorithms.join(', ')}'")
8787
end
8888
end
@@ -106,12 +106,9 @@ def hash_options_are_valid
106106
hash_balance = options[:hash_balance]
107107

108108
# Validate hash_header length if present
109-
if hash_header.present?
110-
# Check length (at most 128 characters)
111-
if hash_header.to_s.length > 128
112-
errors.add(:base, message: "Route '#{r[:route]}': Hash header must be at most 128 characters")
113-
next
114-
end
109+
if hash_header.present? && (hash_header.to_s.length > 128)
110+
errors.add(:base, message: "Route '#{r[:route]}': Hash header must be at most 128 characters")
111+
next
115112
end
116113

117114
# Validate hash_balance is numeric if present
@@ -125,7 +122,7 @@ def hash_options_are_valid
125122
begin
126123
balance_float = Float(hash_balance)
127124
# Must be either 0 or >= 1.1 and <= 10.0
128-
unless balance_float == 0 || (balance_float >= 1.1 && balance_float <= 10)
125+
unless balance_float == 0 || balance_float.between?(1.1, 10)
129126
errors.add(:base, message: "Route '#{r[:route]}': Hash balance must be either 0 or between to 1.1 and 10.0")
130127
end
131128
rescue ArgumentError, TypeError

app/messages/route_options_message.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ def hash_options_are_valid
5050
# Feature flag is enabled - validate hash-specific options
5151

5252
# Validate hash_header length if present
53-
if hash_header.present?
54-
# Check length (at most 128 characters)
55-
if hash_header.to_s.length > 128
56-
errors.add(:hash_header, 'must be at most 128 characters')
57-
return
58-
end
53+
if hash_header.present? && (hash_header.to_s.length > 128)
54+
errors.add(:hash_header, 'must be at most 128 characters')
55+
return
5956
end
6057

6158
# Validate hash_balance is numeric if present
@@ -69,9 +66,7 @@ def hash_options_are_valid
6966
begin
7067
balance_float = Float(hash_balance)
7168
# Must be either 0 or >= 1.1 and <= 10.0
72-
unless balance_float == 0 || (balance_float >= 1.1 && balance_float <= 10)
73-
errors.add(:hash_balance, 'must be either 0 or between 1.1 and 10.0')
74-
end
69+
errors.add(:hash_balance, 'must be either 0 or between 1.1 and 10.0') unless balance_float == 0 || balance_float.between?(1.1, 10)
7570
rescue ArgumentError, TypeError
7671
errors.add(:hash_balance, 'must be a numeric value')
7772
end

app/models/runtime/route.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,12 @@ def as_summary_json
7171
end
7272

7373
def options_with_serialization=(opts)
74-
logger = Steno.logger('cc.model.route')
75-
caller_info = caller[0..5].join("\n ")
76-
logger.error("CRITICAL: options_with_serialization= setter called", opts: opts.inspect, caller: caller_info, location: "#{__FILE__}:#{__LINE__}")
77-
7874
cleaned_opts = remove_hash_options_for_non_hash_loadbalancing(opts)
7975
rounded_opts = round_hash_balance_to_one_decimal(cleaned_opts)
8076
normalized_opts = normalize_hash_balance_to_string(rounded_opts)
8177
# Remove nil values after all processing
8278
normalized_opts = normalized_opts.compact if normalized_opts.is_a?(Hash)
8379
self.options_without_serialization = Oj.dump(normalized_opts)
84-
85-
logger.error("CRITICAL: options_with_serialization= setter completed", normalized_opts: normalized_opts.inspect, json: self.options_without_serialization.inspect)
8680
end
8781

8882
alias_method :options_without_serialization=, :options=
@@ -339,9 +333,9 @@ def validate_route_options
339333

340334
hash_header = route_options[:hash_header] || route_options['hash_header']
341335

342-
if hash_header.blank?
343-
errors.add(:route, :hash_header_missing)
344-
end
336+
return if hash_header.present?
337+
338+
errors.add(:route, :hash_header_missing)
345339
end
346340

347341
def round_hash_balance_to_one_decimal(opts)
@@ -365,6 +359,7 @@ def round_hash_balance_to_one_decimal(opts)
365359

366360
def normalize_hash_balance_to_string(opts)
367361
return opts unless opts.is_a?(Hash)
362+
368363
# We have a flat structure on options, so no deep_symbolize required
369364
normalized = opts.symbolize_keys
370365
normalized[:hash_balance] = normalized[:hash_balance].to_s if normalized[:hash_balance].present?

0 commit comments

Comments
 (0)