Skip to content

Commit

Permalink
Resolve function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
orien committed Feb 7, 2024
1 parent 441e4f6 commit d59b55f
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/channels/deploy_notifications_channel.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class DeployNotificationsChannel < ActionCable::Channel::Base
def self.broadcast(count)
ActionCable.server.broadcast channel_name, count: count
ActionCable.server.broadcast(channel_name, {count: count})
end

# called when using javascript App.cable.subscriptions.create
Expand Down
7 changes: 4 additions & 3 deletions app/models/concerns/attr_encrypted_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ def self.included(base)
base.extend ClassMethods
end

def as_json(except: [], **options)
except += [
def as_json(options = {})
options[:except] ||= []
options[:except] += [
:encryption_key_sha,
*self.class.encrypted_attributes.keys.flat_map do |column|
[column, :"encrypted_#{column}_iv", :"encrypted_#{column}"]
end
]
super(except: except, **options)
super(options)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def csv_line
]
end

def as_json(methods: [])
hash = super(methods: [:status, :url, :production, :commit] + methods)
def as_json(options = {})
hash = super(methods: [:status, :url, :production, :commit] + options.fetch(:methods], [])
hash["summary"] = summary_for_timeline
hash
end
Expand Down
10 changes: 7 additions & 3 deletions app/presenters/user_csv_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class UserCsvPresenter
## - user_id - defaults to nil, reports on only one user (will set inherited to true)
## - datetime - defaults to now, Timestamp for when the report is kicked off and generated

def self.to_csv(
inherited: false, deleted: false, project_id: nil, user_id: nil, datetime: (Time.now.strftime "%Y%m%d_%H%M")
)
def self.to_csv(options = {})
inherited = options.fetch(:inherited, false)
deleted = options.fetch(:deleted, false)
project_id = options.fetch(:project_id, nil)
user_id = options.fetch(:user_id, nil)
datetime = options.fetch(:datetime, Time.now.strftime("%Y%m%d_%H%M"))

inherited = true if project_id || user_id
users = (deleted || user_id ? User.unscoped : User)
users = users.order(:id)
Expand Down
4 changes: 2 additions & 2 deletions lib/samson/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def only_callbacks_for_plugin(plugin_name, hook_name)
end

# use
def fire(name, *args)
traced(name) { hooks(name).map { |hook| hook.call(*args) } }
def fire(name, *args, **kwargs)
traced(name) { hooks(name).map { |hook| hook.call(*args, **kwargs) } }
end

def render_views(name, view, *args)
Expand Down
2 changes: 1 addition & 1 deletion lib/samson/secrets/vault_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sync!(other)

def create_client
VaultClientWrapper.new(
DEFAULT_CLIENT_OPTIONS.merge(
**DEFAULT_CLIENT_OPTIONS.merge(
address: address,
ssl_cert_store: cert_store,
ssl_verify: tls_verify,
Expand Down
4 changes: 2 additions & 2 deletions plugins/datadog/test/models/datadog_deploy_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
let(:deploy) { deploys(:succeeded_test) }

describe '.deliver' do
def deliver(*args)
DatadogDeployEvent.deliver(deploy, *args)
def deliver(**args)
DatadogDeployEvent.deliver(deploy, **args)
end

def expected_body(overrides = {})
Expand Down
4 changes: 2 additions & 2 deletions plugins/datadog/test/models/datadog_monitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def assert_datadog_timeout(&block)
end

it "shows Alert when groups are alerting" do
assert_datadog alerting_groups do
assert_datadog(**alerting_groups) do
monitor.state(groups).must_equal "Alert"
end
end
Expand Down Expand Up @@ -110,7 +110,7 @@ def assert_datadog_timeout(&block)
it "produces no extra sql queries" do
stage = stages(:test_production) # preload
assert_sql_queries 1 do # group-stage and groups
assert_datadog alerting_groups do
assert_datadog(**alerting_groups) do
monitor.state(stage.deploy_groups)
end
end
Expand Down
3 changes: 2 additions & 1 deletion plugins/env/app/models/environment_variable_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def variable_names
environment_variables.sort_by(&:id).map(&:name).uniq
end

def as_json(methods: [], **options)
def as_json(options = {})
methods = options.delete(:methods) || []
super({methods: [:variable_names] + methods}.merge(options))
end

Expand Down
4 changes: 2 additions & 2 deletions plugins/env/lib/samson_env/samson_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def write_dotenv(base_file, groups)
end

# TODO: use for write_env_files
Samson::Hooks.callback :deploy_env do |*args|
EnvironmentVariable.env(*args)
Samson::Hooks.callback :deploy_env do |*args, **kwargs|
EnvironmentVariable.env(*args, **kwargs)
end

Samson::Hooks.callback(:link_parts_for_resource) do
Expand Down
8 changes: 4 additions & 4 deletions plugins/kubernetes/app/models/kubernetes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ class Pod < Immutable
end

class PodDisruptionBudget < VersionedUpdate
def initialize(*)
super
def initialize(...)
super(...)
@delete_resource ||= @template[:delete] # allow deletion through release_doc logic
end
end
Expand All @@ -427,9 +427,9 @@ def template_for_update
end
end

def self.build(*args)
def self.build(*args, **kwargs)
klass = "Kubernetes::Resource::#{args.first.fetch(:kind)}".safe_constantize || VersionedUpdate
klass.new(*args)
klass.new(*args, **kwargs)
end
end
end
2 changes: 1 addition & 1 deletion plugins/sentry/lib/samson_sentry/samson_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class SamsonPlugin < Rails::Engine

Samson::Hooks.callback :error do |exception, **options|
sentry_options = options.slice(:contexts, :extra, :tags, :user, :level, :fingerprint)
Sentry.capture_exception(exception, sentry_options)
Sentry.capture_exception(exception, **sentry_options)
end
4 changes: 2 additions & 2 deletions test/lib/samson/form_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def fake_erb_rendering

# NOTE: ideally don't use a plugin model, but we need something with accepts_nested_attributes_for
describe '#fields_for_many' do
def render(*args)
def render(*args, **kwargs)
project.rollbar_dashboards_settings.build # TODO: this does not get rendered
builder.fields_for_many(*args) do |p|
builder.fields_for_many(*args, **kwargs) do |p|
p.text_field :base_url, placeholder: 'thing!'
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/lib/samson/secrets/vault_client_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it 'calls Vault::Client initialize with other arguments' do
client_args = {versioned_kv: true, use_ssl: true, timeout: 543, ssl_timeout: 345}

client = Samson::Secrets::VaultClientWrapper.new(client_args)
client = Samson::Secrets::VaultClientWrapper.new(**client_args)

client.instance_variable_get(:@ssl_verify).must_equal true
client.instance_variable_get(:@timeout).must_equal 543
Expand Down
2 changes: 1 addition & 1 deletion test/models/image_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def call(options = {})
defaults = {tag_as_latest: false, dockerfile: 'Dockerfile', tag: 'tag', cache_from: 'cache'}
ImageBuilder.build_image("foo", build, executor, defaults.merge(options))
ImageBuilder.build_image("foo", build, executor, **defaults.merge(options))
end

it "builds and pushes" do
Expand Down
6 changes: 3 additions & 3 deletions test/presenters/user_csv_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

def csv_completeness_test(options = {}, expected = {})
meta_rows = 3
UserCsvPresenter.to_csv(options).split("\n").size.must_equal expected + meta_rows
UserCsvPresenter.to_csv(options).split("\n")[-2].split(",")[-1].to_i.must_equal expected
UserCsvPresenter.to_csv(**options).split("\n").size.must_equal expected + meta_rows
UserCsvPresenter.to_csv(**options).split("\n")[-2].split(",")[-1].to_i.must_equal expected
end

# on updating #csv_line this test helper may need to be updated
# This tests the optimized logic against the non-optimized logic.
def csv_accuracy_test(options = {})
actual = CSV.parse(UserCsvPresenter.to_csv(options))
actual = CSV.parse(UserCsvPresenter.to_csv(**options))
actual.shift
actual.pop(2)
actual.each do |csv_row|
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def warden

# catch warden throw ... which would normally go into warden middleware and then be an unauthorized response
prepend(Module.new do
def process(*args)
catch(:warden) { return super }
def process(...)
catch(:warden) { return super(...) }
response.status = :unauthorized
response.body = ":warden caught in test_helper.rb"
response
Expand Down

0 comments on commit d59b55f

Please sign in to comment.