Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kwargs instead of hash for options argument #13

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ConnectionAdapters
module Redshift
module OID # :nodoc:
class Decimal < Type::Decimal # :nodoc:
def infinity(options = {})
def infinity(**options)
BigDecimal.new("Infinity") * (options[:negative] ? -1 : 1)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ module ColumnMethods
# require you to assure that you always provide a UUID value before saving
# a record (as primary keys cannot be +nil+). This might be done via the
# +SecureRandom.uuid+ method and a +before_save+ callback, for instance.
def primary_key(name, type = :primary_key, options = {})
def primary_key(name, type = :primary_key, **options)
return super unless type == :uuid
options[:default] = options.fetch(:default, 'uuid_generate_v4()')
options[:primary_key] = true
column name, type, options
end

def json(name, options = {})
def json(name, **options)
column(name, :json, options)
end

def jsonb(name, options = {})
def jsonb(name, **options)
column(name, :jsonb, options)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def add_column_options!(sql, options)
module SchemaStatements
# Drops the database specified on the +name+ attribute
# and creates it again using the provided +options+.
def recreate_database(name, options = {}) #:nodoc:
def recreate_database(name, **options) #:nodoc:
drop_database(name)
create_database(name, options)
end
Expand All @@ -56,7 +56,7 @@ def recreate_database(name, options = {}) #:nodoc:
# Example:
# create_database config[:database], config
# create_database 'foo_development', encoding: 'unicode'
def create_database(name, options = {})
def create_database(name, **options)
options = { encoding: 'utf8' }.merge!(options.symbolize_keys)

option_string = options.inject("") do |memo, (key, value)|
Expand Down Expand Up @@ -151,7 +151,7 @@ def view_exists?(view_name) # :nodoc:
SQL
end

def drop_table(table_name, options = {})
def drop_table(table_name, **options)
execute "DROP TABLE #{quote_table_name(table_name)}#{' CASCADE' if options[:force] == :cascade}"
end

Expand Down Expand Up @@ -221,7 +221,7 @@ def create_schema schema_name
end

# Drops the schema for the given schema name.
def drop_schema(schema_name, options = {})
def drop_schema(schema_name, **options)
execute "DROP SCHEMA#{' IF EXISTS' if options[:if_exists]} #{quote_schema_name(schema_name)} CASCADE"
end

Expand Down Expand Up @@ -289,13 +289,13 @@ def rename_table(table_name, new_name)
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME TO #{quote_table_name(new_name)}"
end

def add_column(table_name, column_name, type, options = {}) #:nodoc:
def add_column(table_name, column_name, type, **options) #:nodoc:
clear_cache!
super
end

# Changes the column of a table.
def change_column(table_name, column_name, type, options = {})
def change_column(table_name, column_name, type, **options)
clear_cache!
quoted_table_name = quote_table_name(table_name)
sql_type = type_to_sql(type, limit: options[:limit], precision: options[:precision], scale: options[:scale])
Expand Down Expand Up @@ -342,7 +342,7 @@ def rename_column(table_name, column_name, new_column_name) #:nodoc:
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}"
end

def add_index(table_name, column_name, options = {}) #:nodoc:
def add_index(table_name, column_name, **options) #:nodoc:
end

def remove_index!(table_name, index_name) #:nodoc:
Expand Down
2 changes: 1 addition & 1 deletion test/active_record/connection_adapters/fake_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def primary_key(table)
@primary_keys[table]
end

def merge_column(table_name, name, sql_type = nil, options = {})
def merge_column(table_name, name, sql_type = nil, **options)
@columns[table_name] << ActiveRecord::ConnectionAdapters::Column.new(
name.to_s,
options[:default],
Expand Down
4 changes: 2 additions & 2 deletions test/cases/adapters/sqlite3/copy_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class << @connection
end
end

def test_copy_table(from = 'customers', to = 'customers2', options = {})
def test_copy_table(from = 'customers', to = 'customers2', **options)
assert_nothing_raised {copy_table(from, to, options)}
assert_equal row_count(from), row_count(to)

Expand Down Expand Up @@ -77,7 +77,7 @@ def test_copy_table_with_binary_column
end

protected
def copy_table(from, to, options = {})
def copy_table(from, to, **options)
@connection.copy_table(from, to, {:temporary => true}.merge(options))
end

Expand Down
4 changes: 2 additions & 2 deletions test/cases/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def assert_sql(*patterns_to_match)
assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map{ |p| p.inspect }.join(', ')} not found.#{SQLCounter.log.size == 0 ? '' : "\nQueries:\n#{SQLCounter.log.join("\n")}"}"
end

def assert_queries(num = 1, options = {})
def assert_queries(num = 1, **options)
ignore_none = options.fetch(:ignore_none) { num == :any }
SQLCounter.clear_log
x = yield
Expand All @@ -45,7 +45,7 @@ def assert_queries(num = 1, options = {})
x
end

def assert_no_queries(options = {}, &block)
def assert_no_queries(**options, &block)
options.reverse_merge! ignore_none: true
assert_queries(0, options, &block)
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.extended(base)
end

# mock out self.columns so no pesky db is needed for these tests
def column(name, sql_type = nil, options = {})
def column(name, sql_type = nil, **options)
connection.merge_column(table_name, name, sql_type, options)
end
end
Expand Down