Skip to content

Commit a45cc83

Browse files
committed
refactor: update method calls to use fully qualified names for clarity
1 parent ebf5887 commit a45cc83

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lib/imagekit/helpers/helper.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def build_url(options)
5757
# Build transformation string
5858
transformation_string = build_transformation_string(opts[:transformation])
5959

60-
add_as_query = TransformationUtils.add_as_query_parameter?(opts) || is_src_parameter_used_for_url
60+
add_as_query = Imagekit::Helpers::TransformationUtils.add_as_query_parameter?(opts) ||
61+
is_src_parameter_used_for_url
6162
transformation_placeholder = "PLEASEREPLACEJUSTBEFORESIGN"
6263

6364
unless is_absolute_url
@@ -71,7 +72,7 @@ def build_url(options)
7172
end
7273

7374
if !transformation_string.empty? && !add_as_query
74-
path_parts << "#{TRANSFORMATION_PARAMETER}#{TransformationUtils.get_chain_transform_delimiter}#{transformation_placeholder}"
75+
path_parts << "#{TRANSFORMATION_PARAMETER}#{Imagekit::Helpers::TransformationUtils.get_chain_transform_delimiter}#{transformation_placeholder}"
7576
end
7677

7778
path_parts << src
@@ -98,7 +99,7 @@ def build_url(options)
9899
end
99100

100101
# Sign the URL if needed
101-
if opts[:signed] == true || (opts[:expires_in] && opts[:expires_in].to_i > 0)
102+
if opts[:signed] == true || (opts[:expires_in] && opts[:expires_in].to_i.positive?)
102103
expiry_timestamp = get_signature_timestamp(opts[:expires_in])
103104

104105
url_signature = get_signature(
@@ -154,7 +155,7 @@ def build_transformation_string(transformations)
154155
next
155156
end
156157

157-
transform_key = TransformationUtils.get_transform_key(key)
158+
transform_key = Imagekit::Helpers::TransformationUtils.get_transform_key(key)
158159
transform_key = key.to_s if transform_key.empty?
159160

160161
next if transform_key.empty?
@@ -204,15 +205,15 @@ def build_transformation_string(transformations)
204205
value = value.to_i if value == value.to_i
205206
end
206207

207-
parsed_transform_step << "#{transform_key}#{TransformationUtils.get_transform_key_value_delimiter}#{value}"
208+
parsed_transform_step << "#{transform_key}#{Imagekit::Helpers::TransformationUtils.get_transform_key_value_delimiter}#{value}"
208209
end
209210

210211
unless parsed_transform_step.empty?
211-
parsed_transforms << parsed_transform_step.join(TransformationUtils.get_transform_delimiter)
212+
parsed_transforms << parsed_transform_step.join(Imagekit::Helpers::TransformationUtils.get_transform_delimiter)
212213
end
213214
end
214215

215-
parsed_transforms.join(TransformationUtils.get_chain_transform_delimiter)
216+
parsed_transforms.join(Imagekit::Helpers::TransformationUtils.get_chain_transform_delimiter)
216217
end
217218

218219
# Generates authentication parameters for client-side file uploads using ImageKit's Upload API V1.
@@ -234,7 +235,7 @@ def get_authentication_parameters(token: nil, expire: nil)
234235
# Handle falsy values - empty string and nil should generate new token
235236
final_token = token.nil? || token.to_s.empty? ? generate_token : token
236237
# Handle falsy values - nil and 0 should use default expire
237-
final_expire = expire.nil? || expire == 0 ? default_expire : expire
238+
final_expire = expire.nil? || expire.zero? ? default_expire : expire
238239

239240
get_authentication_parameters_internal(final_token, final_expire, @client.private_key)
240241
end
@@ -263,7 +264,7 @@ def get_authentication_parameters_internal(token, expire, private_key)
263264
signature: ""
264265
}
265266

266-
signature = CryptoUtils.create_hmac_sha1(private_key, token.to_s + expire.to_s)
267+
signature = Imagekit::Helpers::CryptoUtils.create_hmac_sha1(private_key, token.to_s + expire.to_s)
267268
auth_parameters[:signature] = signature
268269

269270
auth_parameters
@@ -278,7 +279,7 @@ def remove_trailing_slash(str)
278279
# Remove leading slash from string
279280
def remove_leading_slash(str)
280281
return str unless str.is_a?(String) && str.start_with?("/")
281-
str[1..-1]
282+
str[1..]
282283
end
283284

284285
# RFC 3986 path encoding - matches Node.js encodeURIPath exactly
@@ -303,7 +304,7 @@ def path_join(parts, separator = "/")
303304
next if part.empty?
304305

305306
# Remove leading slashes from all parts
306-
part = part[1..-1] while part.start_with?(separator)
307+
part = part[1..] while part.start_with?(separator)
307308

308309
# Remove trailing slashes from all parts
309310
part = part[0..-2] while part.end_with?(separator)
@@ -515,7 +516,7 @@ def add_overlay_properties(parts, overlay)
515516

516517
# Calculate expiry timestamp for URL signing
517518
def get_signature_timestamp(seconds)
518-
return DEFAULT_TIMESTAMP unless seconds && seconds.to_i > 0
519+
return DEFAULT_TIMESTAMP unless seconds && seconds.to_i.positive?
519520

520521
sec = seconds.to_i
521522
return DEFAULT_TIMESTAMP if sec <= 0
@@ -531,14 +532,14 @@ def get_signature(private_key:, url:, url_endpoint:, expiry_timestamp:)
531532
endpoint_with_slash = add_trailing_slash(url_endpoint)
532533
string_to_sign = url.gsub(endpoint_with_slash, "") + expiry_timestamp.to_s
533534

534-
CryptoUtils.create_hmac_sha1(private_key, string_to_sign)
535+
Imagekit::Helpers::CryptoUtils.create_hmac_sha1(private_key, string_to_sign)
535536
end
536537

537538
# Add trailing slash to string if not present
538539
def add_trailing_slash(str)
539540
return str unless str.is_a?(String)
540541
return str if str.end_with?("/")
541-
str + "/"
542+
"#{str}/"
542543
end
543544
end
544545
end

0 commit comments

Comments
 (0)