Skip to content

Commit

Permalink
Ruby {key: key} -> {key:} simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Nov 10, 2024
1 parent 5e967ec commit 6fbe364
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion app/controllers/authentications/google_oauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def initialize_google_person
def add_person_credentials(type)
p = Current.person || @person
c = p.user.credentials.build(
type: type,
type:,
oauth_id: auth[:uid],
oauth_email: auth[:info][:email],
oauth_token: auth[:credentials][:token],
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ def div_tag(content_or_options_with_block = nil, options = nil, &block)
end

def meta_tag(name, content)
tag.meta(name: name, content: content)
tag.meta(name:, content:)
end

def charset_tag(charset)
tag.meta(charset: charset)
tag.meta(charset:)
end

def viewport_tag(content)
tag.meta(name: "viewport", content: content)
tag.meta(name: "viewport", content:)
end

def n_a_if_blank(value, n_a = "Not Available")
value.blank? ? n_a : value.to_s
end

def to_dollars(cents, precision: 2)
number_to_currency(cents / 100.0, precision: precision)
number_to_currency(cents / 100.0, precision:)
end
end
2 changes: 1 addition & 1 deletion app/jobs/get_next_ai_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def self.broadcast_updated_message(message, locals = {})
html = ApplicationController.render(
partial: "messages/message",
locals: {
message: message,
message:,
only_scroll_down_if_was_bottom: true,
streamed: true,
message_counter: message.index
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/send_reset_password_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def perform(email, os, browser)
Rails.logger.info "Sending reset password email to #{email} from #{os} with #{browser}"

if person&.user # make sure the user exists (i.e. user has not become a tombstone)
PasswordMailer.with(person: person, os: os, browser: browser).reset.deliver_now
PasswordMailer.with(person:, os:, browser:).reset.deliver_now
end
end
end
2 changes: 1 addition & 1 deletion app/mailers/password_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def reset
purpose: Email::PasswordReset::TOKEN_PURPOSE,
expires_in: @token_ttl
)
@edit_url = edit_password_credential_url(token: token)
@edit_url = edit_password_credential_url(token:)

mail(
to: person.email,
Expand Down
4 changes: 2 additions & 2 deletions app/models/message/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def set_next_conversation_index_and_version
else
if version.negative? || version > max_version
errors.add(:version, "#{version} is invalid for this index")
elsif conversation.messages.exists?(index: index, version: version)
elsif conversation.messages.exists?(index:, version:)
errors.add(:version, "#{version} already exists for this index")
elsif versions.present? && version < versions.max && !conversation.messages.exists?(index: index-1, version: version)
elsif versions.present? && version < versions.max && !conversation.messages.exists?(index: index-1, version:)
errors.add(:version, "#{version} is invalid for this index")
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/services/ai_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def initialize(user, assistant, conversation = nil, message = nil)

def get_oneoff_message(instructions, messages, params = {})
set_client_config(
instructions: instructions,
instructions:,
messages: preceding_messages(messages),
params: params,
params:,
)
response = @client.send(client_method_name, ** @client_config)

Expand Down Expand Up @@ -77,7 +77,7 @@ def preceding_messages(messages = [])
role = (i % 2).zero? ? "user" : "assistant"

{
role: role,
role:,
content: msg
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/ai_backend/open_ai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def stream_handler(&chunk_handler)
def system_message(content)
[{
role: "system",
content: content,
content:,
}]
end

Expand Down
24 changes: 12 additions & 12 deletions app/services/sdk.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
class SDK
def get(url, token = nil)
SDK::Get.new(
url: url,
url:,
bearer_token: token || bearer_token,
expected_status: expected_status,
header: header,
expected_status:,
header:,
calling_method: calling_method(__method__),
)
end

def post(url, token = nil)
SDK::Post.new(
url: url,
url:,
bearer_token: token || bearer_token,
expected_status: expected_status,
header: header,
expected_status:,
header:,
calling_method: calling_method(__method__),
)
end

def patch(url, token = nil)
SDK::Patch.new(
url: url,
url:,
bearer_token: token || bearer_token,
expected_status: expected_status,
header: header,
expected_status:,
header:,
calling_method: calling_method(__method__),
)
end

def delete(url, token = nil)
SDK::Delete.new(
url: url,
url:,
bearer_token: token || bearer_token,
expected_status: expected_status,
header: header,
expected_status:,
header:,
calling_method: calling_method(__method__),
)
end
Expand Down
14 changes: 7 additions & 7 deletions app/services/toolbox/gmail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def body_html

def to_h
{
id: id,
thread_id: thread_id,
date: date,
from: from,
to: to,
subject: subject,
snippet: snippet,
id:,
thread_id:,
date:,
from:,
to:,
subject:,
snippet:,
body: body || body_html,
}
end
Expand Down
12 changes: 6 additions & 6 deletions app/services/toolbox/google_tasks/api_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def get_tasks_for_list(list, due_min: nil, due_max: nil)
def create_task_for_list(list, title:, notes: nil, due: nil)
refresh_token_if_needed do
post("https://tasks.googleapis.com/tasks/v1/lists/#{list.id}/tasks").param(
title: title,
notes: notes,
title:,
notes:,
due: format_time(due),
status: "needsAction",
)
Expand All @@ -58,7 +58,7 @@ def move_task_to_list(task, list, keep_due: true)
delete_task(task)
create_task_for_list(list,
title: task.title,
notes: notes,
notes:,
due: keep_due.presence && task.try(:due),
)
end
Expand All @@ -73,12 +73,12 @@ def update_task(task, title: nil, notes: nil, due: nil, completed: nil, deleted:
refresh_token_if_needed do
patch("https://tasks.googleapis.com/tasks/v1/lists/#{list_id_of(task)}/tasks/#{task.id}").param( {
id: task.id,
title: title,
notes: notes,
title:,
notes:,
due: format_time(due),
status: !!completed ? "completed" : "needsAction",
completed: completed.presence && format_time(completed),
deleted: deleted,
deleted:,
}.compact) # w/o this it updates values to nil
end
end
Expand Down
46 changes: 23 additions & 23 deletions lib/active_storage/service/postgresql_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ def initialize(public: false, **options)
end

def upload(key, io, checksum: nil, **)
instrument :upload, key: key, checksum: checksum do
ActiveStorage::Postgresql::File.create!(key: key, io: io, checksum: checksum)
instrument :upload, key:, checksum: do
ActiveStorage::Postgresql::File.create!(key:, io:, checksum:)
end
end

def download(key)
if block_given?
instrument :streaming_download, key: key do
instrument :streaming_download, key: do
ActiveStorage::Postgresql::File.open(key) do |file|
while data = file.read(5.megabytes)
yield data
end
end
end
else
instrument :download, key: key do
instrument :download, key: do
ActiveStorage::Postgresql::File.open(key) do |file|
file.read
end
Expand All @@ -31,7 +31,7 @@ def download(key)
end

def download_chunk(key, range)
instrument :download_chunk, key: key, range: range do
instrument :download_chunk, key:, range: do
ActiveStorage::Postgresql::File.open(key) do |file|
file.seek(range.first)
file.read(range.size)
Expand All @@ -40,14 +40,14 @@ def download_chunk(key, range)
end

def delete(key)
instrument :delete, key: key do
ActiveStorage::Postgresql::File.find_by(key: key).try(&:destroy)
instrument :delete, key: do
ActiveStorage::Postgresql::File.find_by(key:).try(&:destroy)
end
end

def exist?(key)
instrument :exist, key: key do |payload|
answer = ActiveStorage::Postgresql::File.where(key: key).exists?
instrument :exist, key: do |payload|
answer = ActiveStorage::Postgresql::File.where(key:).exists?
payload[:exist] = answer
answer
end
Expand All @@ -60,11 +60,11 @@ def delete_prefixed(prefix)
end

def private_url(key, expires_in:, filename:, content_type:, disposition:, **)
generate_url(key, expires_in: expires_in, filename: filename, content_type: content_type, disposition: disposition)
generate_url(key, expires_in:, filename:, content_type:, disposition:)
end

def public_url(key, filename:, content_type: nil, disposition: :attachment, **)
generate_url(key, expires_in: nil, filename: filename, content_type: content_type, disposition: disposition)
generate_url(key, expires_in: nil, filename:, content_type:, disposition:)
end

def url(key, **options)
Expand All @@ -90,23 +90,23 @@ def generate_url(key, expires_in:, filename:, disposition:, content_type:)
counter = counter.to_i
# End hack

instrument :url, key: key do |payload|
content_disposition = content_disposition_with(type: disposition, filename: filename)
instrument :url, key: do |payload|
content_disposition = content_disposition_with(type: disposition, filename:)
verified_key_with_expiration = ActiveStorage.verifier.generate(
{
key: key,
key:,
disposition: content_disposition,
content_type: content_type
content_type:
},
expires_in: expires_in,
expires_in:,
purpose: :blob_key
)

generated_url = url_helpers.rails_postgresql_service_url(verified_key_with_expiration,
**url_options,
disposition: content_disposition,
content_type: content_type,
filename: filename,
content_type:,
filename:,
retry_count: counter
)
payload[:url] = generated_url
Expand All @@ -116,15 +116,15 @@ def generate_url(key, expires_in:, filename:, disposition:, content_type:)
end

def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
instrument :url, key: key do |payload|
instrument :url, key: do |payload|
verified_token_with_expiration = ActiveStorage.verifier.generate(
{
key: key,
content_type: content_type,
key:,
content_type:,
content_length: content_length,
checksum: checksum
checksum:
},
expires_in: expires_in,
expires_in:,
purpose: :blob_token
)

Expand Down
8 changes: 4 additions & 4 deletions test/controllers/password_credentials_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PasswordCredentialsControllerTest < ActionDispatch::IntegrationTest
test "should get edit" do
token = get_test_user_token(@user)

get edit_password_credential_url, params: { token: token }
get edit_password_credential_url, params: { token: }

assert_response :success
assert assigns(:user).is_a?(User)
Expand All @@ -37,7 +37,7 @@ class PasswordCredentialsControllerTest < ActionDispatch::IntegrationTest
token = get_test_user_token(@user)
@user.destroy # make sure the user doesn't exist when we try to find it

get edit_password_credential_url, params: { token: token }
get edit_password_credential_url, params: { token: }

assert_response :not_found
end
Expand All @@ -46,7 +46,7 @@ class PasswordCredentialsControllerTest < ActionDispatch::IntegrationTest
token = get_test_user_token(@user)
new_password = "new_password"

patch password_credential_url, params: { token: token, password: new_password }
patch password_credential_url, params: { token:, password: new_password }

assert_response :redirect
assert_redirected_to root_path
Expand All @@ -61,7 +61,7 @@ class PasswordCredentialsControllerTest < ActionDispatch::IntegrationTest
token = get_test_user_token(@user)
new_password = "new_password"

patch password_credential_url, params: { token: token, password: new_password }
patch password_credential_url, params: { token:, password: new_password }

assert_response :redirect
assert_redirected_to root_path
Expand Down
Loading

0 comments on commit 6fbe364

Please sign in to comment.