Skip to content

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
AS-AlStar committed Dec 9, 2024
1 parent 50a7371 commit ddfe667
Show file tree
Hide file tree
Showing 36 changed files with 146 additions and 146 deletions.
2 changes: 1 addition & 1 deletion lib/table_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class << self

def sync(object_class, **options)
setup.new(
object_class: object_class,
object_class:,
on: options[:on],
if_condition: options[:if],
unless_condition: options[:unless],
Expand Down
6 changes: 3 additions & 3 deletions lib/table_sync/instrument_adapter/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module ActiveSupport

def notify(table:, schema:, event:, direction:, count: 1)
::ActiveSupport::Notifications.instrument "tablesync.#{direction}.#{event}",
count: count,
count:,
table: table.to_s,
schema: schema.to_s,
event: event,
direction: direction
event:,
direction:
end
end
end
2 changes: 1 addition & 1 deletion lib/table_sync/publishing/data/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(objects:, event:, custom_version:)

def construct
{
model: model,
model:,
attributes: attributes_for_sync,
version: custom_version || version,
event: event.resolve,
Expand Down
12 changes: 6 additions & 6 deletions lib/table_sync/publishing/message/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ def empty?

def find_or_init_objects
TableSync::Publishing::Helpers::Objects.new(
object_class: object_class, original_attributes: original_attributes, event: event,
object_class:, original_attributes:, event:,
).construct_list
end

# MESSAGE PARAMS

def message_params
params.merge(data: data)
params.merge(data:)
end

def data
TableSync::Publishing::Data::Objects.new(
objects: objects,
event: event,
custom_version: custom_version,
objects:,
event:,
custom_version:,
).construct
end

Expand All @@ -63,7 +63,7 @@ def notify!
TableSync::Instrument.notify(
table: model_naming.table,
schema: model_naming.schema,
event: event,
event:,
direction: :publish,
count: objects.count,
)
Expand Down
10 changes: 5 additions & 5 deletions lib/table_sync/publishing/message/raw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def notify!
TableSync::Instrument.notify(
table: table_name,
schema: schema_name,
event: event,
event:,
count: original_attributes.count,
direction: :publish,
)
Expand All @@ -35,15 +35,15 @@ def notify!
# MESSAGE PARAMS

def message_params
params.merge(data: data)
params.merge(data:)
end

def data
TableSync::Publishing::Data::Raw.new(
model_name: model_name,
model_name:,
attributes_for_sync: original_attributes,
event: event,
custom_version: custom_version,
event:,
custom_version:,
).construct
end

Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/publishing/message/single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def object
end

def params
TableSync::Publishing::Params::Single.new(object: object).construct
TableSync::Publishing::Params::Single.new(object:).construct
end
end
end
6 changes: 3 additions & 3 deletions lib/table_sync/publishing/params/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Base

def construct
DEFAULT_PARAMS.merge(
routing_key: routing_key,
headers: headers,
exchange_name: exchange_name,
routing_key:,
headers:,
exchange_name:,
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/table_sync/publishing/single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def publish_now

memoize def debounce
TableSync::Publishing::Helpers::Debounce.new(
object_class: object_class,
object_class:,
needle: message.object.needle,
debounce_time: debounce_time,
event: event,
debounce_time:,
event:,
)
end

Expand Down
14 changes: 7 additions & 7 deletions lib/table_sync/receiving/config_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def initialize(config:, event:, model:, version:, project_id:, raw_data:)
@config = config

@default_params = {
event: event,
model: model,
version: version,
project_id: project_id,
raw_data: raw_data,
event:,
model:,
version:,
project_id:,
raw_data:,
}
end
# rubocop:enable Metrics/ParameterLists

def method_missing(name, **additional_params, &block)
def method_missing(name, **additional_params, &)
value = @config.send(name)
value.is_a?(Proc) ? value.call(@default_params.merge(additional_params), &block) : value
value.is_a?(Proc) ? value.call(@default_params.merge(additional_params), &) : value
end
end
end
2 changes: 1 addition & 1 deletion lib/table_sync/receiving/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def receive(source, to_table: nil, to_model: nil, events: [:update, :destroy], &

TableSync::Utils::InterfaceChecker.new(model).implements(:receiving_model)

config = ::TableSync::Receiving::Config.new(model: model, events: events)
config = ::TableSync::Receiving::Config.new(model:, events:)

config.instance_exec(&block) if block

Expand Down
40 changes: 20 additions & 20 deletions lib/table_sync/receiving/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ def call

next if data.empty?

version_key = config.version_key(data: data)
version_key = config.version_key(data:)
data.each { |row| row[version_key] = version }

target_keys = config.target_keys(data: data)
target_keys = config.target_keys(data:)

validate_data(data, target_keys: target_keys)
validate_data(data, target_keys:)

data.sort_by! { |row| row.values_at(*target_keys).map { |value| sort_key(value) } }

params = { data: data, target_keys: target_keys, version_key: version_key }
params = { data:, target_keys:, version_key: }

if event == :update
params[:default_values] = config.default_values(data: data)
params[:default_values] = config.default_values(data:)
end

config.wrap_receiving(event: event, **params) do
config.wrap_receiving(event:, **params) do
perform(config, params)
end
end
Expand Down Expand Up @@ -64,12 +64,12 @@ def configs
configs = configs.sort_by { |config| "#{config.model.schema}.#{config.model.table}" }
configs.map do |config|
::TableSync::Receiving::ConfigDecorator.new(
config: config,
config:,
# next parameters will be send to each proc-options from config
event: event,
model: model,
version: version,
project_id: project_id,
event:,
model:,
version:,
project_id:,
raw_data: data,
)
end
Expand All @@ -78,22 +78,22 @@ def configs

def processed_data(config)
data.filter_map do |row|
next if config.skip(row: row)
next if config.skip(row:)

row = row.dup

config.mapping_overrides(row: row).each do |before, after|
config.mapping_overrides(row:).each do |before, after|
row[after] = row.delete(before)
end

config.except(row: row).each { |x| row.delete(x) }
config.except(row:).each { |x| row.delete(x) }

row.merge!(config.additional_data(row: row))
row.merge!(config.additional_data(row:))

only = config.only(row: row)
only = config.only(row:)
row, rest = row.partition { |key, _| key.in?(only) }.map(&:to_h)

rest_key = config.rest_key(row: row, rest: rest)
rest_key = config.rest_key(row:, rest:)
(row[rest_key] ||= {}).merge!(rest) if rest_key

row
Expand Down Expand Up @@ -139,13 +139,13 @@ def perform(config, params)

model.after_commit do
TableSync::Instrument.notify table: model.table, schema: model.schema,
count: results.count, event: event, direction: :receive
count: results.count, event:, direction: :receive
end

if event == :update
model.after_commit { config.after_commit_on_update(**params.merge(results: results)) }
model.after_commit { config.after_commit_on_update(**params.merge(results:)) }
else
model.after_commit { config.after_commit_on_destroy(**params.merge(results: results)) }
model.after_commit { config.after_commit_on_destroy(**params.merge(results:)) }
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/table_sync/receiving/model/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(table_name)
self.inheritance_column = nil
end

model_naming = ::TableSync::NamingResolver::ActiveRecord.new(table_name: table_name)
model_naming = ::TableSync::NamingResolver::ActiveRecord.new(table_name:)

@table = model_naming.table.to_sym
@schema = model_naming.schema.to_sym
Expand Down Expand Up @@ -66,7 +66,7 @@ def upsert(data:, target_keys:, version_key:, default_values:)
row = raw_model.lock("FOR NO KEY UPDATE").where(conditions)

if row.to_a.size > 1
raise TableSync::UpsertError.new(data: datum, target_keys: target_keys, result: row)
raise TableSync::UpsertError.new(data: datum, target_keys:, result: row)
end

row = row.first
Expand Down Expand Up @@ -99,18 +99,18 @@ def destroy(data:, target_keys:, version_key:)
result = query.destroy_all.map { |x| row_to_hash(x) }

if result.size > data.size
raise TableSync::DestroyError.new(data: data, target_keys: target_keys, result: result)
raise TableSync::DestroyError.new(data:, target_keys:, result:)
end

result
end

def transaction(&block)
::ActiveRecord::Base.transaction(&block)
def transaction(&)
::ActiveRecord::Base.transaction(&)
end

def after_commit(&block)
db.add_transaction_record(AfterCommitWrap.new(&block))
def after_commit(&)
db.add_transaction_record(AfterCommitWrap.new(&))
end

private
Expand Down
12 changes: 6 additions & 6 deletions lib/table_sync/receiving/model/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(table_name)
@raw_model = Class.new(::Sequel::Model(table_name)).tap(&:unrestrict_primary_key)

model_naming = ::TableSync::NamingResolver::Sequel.new(
table_name: table_name,
table_name:,
db: @raw_model.db,
)

Expand Down Expand Up @@ -46,18 +46,18 @@ def destroy(data:, target_keys:, version_key:)
result = dataset.returning.where(::Sequel.|(*sanitized_data)).delete

if result.size > data.size
raise TableSync::DestroyError.new(data: data, target_keys: target_keys, result: result)
raise TableSync::DestroyError.new(data:, target_keys:, result:)
end

result
end

def transaction(&block)
db.transaction(&block)
def transaction(&)
db.transaction(&)
end

def after_commit(&block)
db.after_commit(&block)
def after_commit(&)
db.after_commit(&)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/setup/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def define_after_commit(event)
TableSync::Publishing::Single.new(
object_class: self.class.name,
original_attributes: attributes,
event: event,
event:,
debounce_time: options[:debounce_time],
).publish_later
end
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/setup/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def options_exposed_for_block
{
if: if_condition,
unless: unless_condition,
debounce_time: debounce_time,
debounce_time:,
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/setup/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def define_after_commit(event)
TableSync::Publishing::Single.new(
object_class: self.class.name,
original_attributes: values,
event: event,
event:,
debounce_time: options[:debounce_time],
).publish_later
end
Expand Down
8 changes: 4 additions & 4 deletions lib/table_sync/utils/proc_array.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

class TableSync::Utils::ProcArray < Proc
def initialize(&block)
def initialize(&)
@array = []
super(&block)
super(&)
end

def push(&block)
@array.push(block)
self
end

def call(*args, &block)
super(@array, args, &block)
def call(*args, &)
super(@array, args, &)
end
end
Loading

0 comments on commit ddfe667

Please sign in to comment.