Merge pull request #370 from dry-rb/fix-keyword-warnings
Fix all keyword warnings shown by Ruby 2.7
This commit is contained in:
commit
cbe69c1f59
|
@ -15,7 +15,7 @@ module Dry
|
|||
|
||||
# @api private
|
||||
def initialize(**options)
|
||||
super(::Object, options)
|
||||
super(::Object, **options)
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
|
@ -30,7 +30,7 @@ module Dry
|
|||
# @return [Type]
|
||||
#
|
||||
# @api public
|
||||
def with(new_options)
|
||||
def with(**new_options)
|
||||
self.class.new(**options, meta: @meta, **new_options)
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module Dry
|
|||
# @option options [Type] :member
|
||||
#
|
||||
# @api private
|
||||
def initialize(primitive, options = {})
|
||||
def initialize(primitive, **options)
|
||||
@member = options.fetch(:member)
|
||||
super
|
||||
end
|
||||
|
@ -100,7 +100,7 @@ module Dry
|
|||
#
|
||||
# @api public
|
||||
def lax
|
||||
Lax.new(Member.new(primitive, { **options, member: member.lax, meta: meta }))
|
||||
Lax.new(Member.new(primitive, **options, member: member.lax, meta: meta))
|
||||
end
|
||||
|
||||
# @see Nominal#to_ast
|
||||
|
|
|
@ -127,7 +127,7 @@ module Dry
|
|||
#
|
||||
# @api public
|
||||
def constructor(constructor = nil, **options, &block)
|
||||
constructor_type.new(with(options), fn: constructor || block)
|
||||
constructor_type.new(with(**options), fn: constructor || block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,12 +68,12 @@ module Dry
|
|||
|
||||
def visit_hash(node)
|
||||
opts, meta = node
|
||||
registry['nominal.hash'].with(opts.merge(meta: meta))
|
||||
registry['nominal.hash'].with(**opts, meta: meta)
|
||||
end
|
||||
|
||||
def visit_schema(node)
|
||||
keys, options, meta = node
|
||||
registry['nominal.hash'].schema(keys.map { |key| visit(key) }).with(options.merge(meta: meta))
|
||||
registry['nominal.hash'].schema(keys.map { |key| visit(key) }).with(**options, meta: meta)
|
||||
end
|
||||
|
||||
def visit_json_hash(node)
|
||||
|
|
|
@ -24,7 +24,7 @@ module Dry
|
|||
# @param [Hash] options
|
||||
#
|
||||
# @api public
|
||||
def initialize(type, options)
|
||||
def initialize(type, **options)
|
||||
super
|
||||
@rule = options.fetch(:rule)
|
||||
end
|
||||
|
|
|
@ -85,7 +85,7 @@ module Dry
|
|||
#
|
||||
# @api public
|
||||
def constructor(new_fn = nil, **options, &block)
|
||||
with({**options, fn: fn >> (new_fn || block)})
|
||||
with(**options, fn: fn >> (new_fn || block))
|
||||
end
|
||||
alias_method :append, :constructor
|
||||
alias_method :>>, :constructor
|
||||
|
@ -114,7 +114,7 @@ module Dry
|
|||
#
|
||||
# @api public
|
||||
def prepend(new_fn = nil, **options, &block)
|
||||
with({**options, fn: fn << (new_fn || block)})
|
||||
with(**options, fn: fn << (new_fn || block))
|
||||
end
|
||||
alias_method :<<, :prepend
|
||||
|
||||
|
@ -123,7 +123,7 @@ module Dry
|
|||
# @return [Lax]
|
||||
# @api public
|
||||
def lax
|
||||
Lax.new(Constructor.new(type.lax, options))
|
||||
Lax.new(Constructor.new(type.lax, **options))
|
||||
end
|
||||
|
||||
# Wrap the type with a proc
|
||||
|
@ -158,7 +158,7 @@ module Dry
|
|||
response = type.public_send(method, *args, &block)
|
||||
|
||||
if response.is_a?(Type) && type.class == response.class
|
||||
response.constructor_type.new(response, options)
|
||||
response.constructor_type.new(response, **options)
|
||||
else
|
||||
response
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module Dry
|
|||
attr_reader :type
|
||||
|
||||
# @param [Type] type
|
||||
def initialize(type, *)
|
||||
def initialize(type, *, **)
|
||||
super
|
||||
@type = type
|
||||
end
|
||||
|
@ -101,6 +101,7 @@ module Dry
|
|||
super
|
||||
end
|
||||
end
|
||||
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
||||
|
||||
# Replace underlying type
|
||||
#
|
||||
|
|
|
@ -27,7 +27,7 @@ module Dry
|
|||
# @option options [Array] :values
|
||||
#
|
||||
# @api private
|
||||
def initialize(type, options)
|
||||
def initialize(type, **options)
|
||||
super
|
||||
@mapping = options.fetch(:mapping).freeze
|
||||
@values = @mapping.keys.freeze
|
||||
|
|
|
@ -113,7 +113,7 @@ module Dry
|
|||
|
||||
type_map.map do |map_key, type|
|
||||
name, options = key_name(map_key)
|
||||
key = Schema::Key.new(resolve_type(type), name, options)
|
||||
key = Schema::Key.new(resolve_type(type), name, **options)
|
||||
type_transform.(key)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module Dry
|
|||
# @return [Type]
|
||||
#
|
||||
# @api public
|
||||
def with(options)
|
||||
def with(**options)
|
||||
super(meta: @meta, **options)
|
||||
end
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ module Dry
|
|||
#
|
||||
# @api public
|
||||
class Module < ::Module
|
||||
def initialize(registry, *args)
|
||||
def initialize(registry, *args, **kwargs)
|
||||
@registry = registry
|
||||
check_parameters(*args)
|
||||
constants = type_constants(*args)
|
||||
check_parameters(*args, **kwargs)
|
||||
constants = type_constants(*args, **kwargs)
|
||||
define_constants(constants)
|
||||
extend(BuilderMethods)
|
||||
|
||||
|
|
|
@ -109,7 +109,9 @@ RSpec.shared_examples_for Dry::Types::Nominal do
|
|||
end
|
||||
end
|
||||
|
||||
RSpec.shared_examples_for 'a constrained type' do |inputs: Object.new|
|
||||
RSpec.shared_examples_for 'a constrained type' do |options = { inputs: Object.new }|
|
||||
inputs = options[:inputs]
|
||||
|
||||
let(:fallback) { Object.new }
|
||||
|
||||
describe '#call' do
|
||||
|
|
|
@ -40,7 +40,7 @@ module Dry
|
|||
# @param [Hash] options
|
||||
#
|
||||
# @api private
|
||||
def initialize(left, right, options = {})
|
||||
def initialize(left, right, **options)
|
||||
super
|
||||
@left, @right = left, right
|
||||
freeze
|
||||
|
@ -146,7 +146,7 @@ module Dry
|
|||
if data.nil?
|
||||
optional? ? right.meta : super
|
||||
elsif optional?
|
||||
self.class.new(left, right.meta(data), options)
|
||||
self.class.new(left, right.meta(data), **options)
|
||||
else
|
||||
super
|
||||
end
|
||||
|
|
|
@ -138,11 +138,13 @@ RSpec.describe Dry::Types::Module do
|
|||
end
|
||||
|
||||
context 'parameters' do
|
||||
subject(:mod) { Dry::Types::Module.new(registry, *args) }
|
||||
subject(:mod) { Dry::Types::Module.new(registry, *args, **kwargs) }
|
||||
|
||||
let(:args) { [] }
|
||||
|
||||
let(:kwargs) { {} }
|
||||
|
||||
context 'no options' do
|
||||
let(:args) { [] }
|
||||
|
||||
it 'contains all types by default' do
|
||||
expect(mod.constants.to_set)
|
||||
.to be > %i[Strict Coercible Optional JSON Params Integer].to_set
|
||||
|
@ -153,7 +155,7 @@ RSpec.describe Dry::Types::Module do
|
|||
constant = Dry::Types::Inflector.camelize(ns.to_s).to_sym
|
||||
|
||||
context ns.to_s do
|
||||
subject(:args) { [ns] }
|
||||
let(:args) { [ns] }
|
||||
|
||||
it "includes only #{ns} types" do
|
||||
constants = mod.constants(false)
|
||||
|
@ -165,7 +167,7 @@ RSpec.describe Dry::Types::Module do
|
|||
end
|
||||
|
||||
context 'multiple namespaces' do
|
||||
subject(:args) { %i[strict nominal] }
|
||||
let(:args) { %i[strict nominal] }
|
||||
|
||||
it 'adds only two constants' do
|
||||
constants = mod.constants(false)
|
||||
|
@ -175,7 +177,9 @@ RSpec.describe Dry::Types::Module do
|
|||
|
||||
context 'default types' do
|
||||
context 'several namespaces with default' do
|
||||
subject(:args) { [:nominal, default: :strict] }
|
||||
let(:args) { [:nominal] }
|
||||
|
||||
let(:kwargs) { { default: :strict } }
|
||||
|
||||
it 'adds strict types as default' do
|
||||
expect(mod::Integer).to be(Dry::Types['strict.integer'])
|
||||
|
@ -186,15 +190,13 @@ RSpec.describe Dry::Types::Module do
|
|||
|
||||
context 'any' do
|
||||
context 'no options' do
|
||||
subject(:args) { [] }
|
||||
|
||||
it 'is available by default' do
|
||||
expect(mod::Any).to be(registry['any'])
|
||||
end
|
||||
end
|
||||
|
||||
context 'strict' do
|
||||
subject(:args) { [default: :strict] }
|
||||
let(:kwargs) { { default: :strict } }
|
||||
|
||||
it 'is available' do
|
||||
expect(mod::Any).to be(registry['any'])
|
||||
|
@ -204,8 +206,6 @@ RSpec.describe Dry::Types::Module do
|
|||
|
||||
context 'bool' do
|
||||
context 'no options' do
|
||||
subject(:args) { [] }
|
||||
|
||||
it 'is available by default' do
|
||||
expect(mod::Bool).to be(registry['strict.bool'])
|
||||
end
|
||||
|
@ -213,7 +213,7 @@ RSpec.describe Dry::Types::Module do
|
|||
end
|
||||
|
||||
context 'without namespaces' do
|
||||
subject(:args) { [default: :strict] }
|
||||
let(:kwargs) { { default: :strict } }
|
||||
|
||||
it 'adds all namespaces wiht strict types as default' do
|
||||
expect(mod::Integer).to be(Dry::Types['strict.integer'])
|
||||
|
@ -222,7 +222,7 @@ RSpec.describe Dry::Types::Module do
|
|||
end
|
||||
|
||||
context 'disabling defaults' do
|
||||
subject(:args) { [default: false] }
|
||||
let(:kwargs) { { default: false } }
|
||||
|
||||
it "doesn't add nominal types as a default" do
|
||||
expect(mod::Nominal::Integer).to be(Dry::Types['nominal.integer'])
|
||||
|
@ -236,7 +236,7 @@ RSpec.describe Dry::Types::Module do
|
|||
end
|
||||
|
||||
context 'optional defaults' do
|
||||
subject(:args) { [default: :optional] }
|
||||
let(:kwargs) { { default: :optional } }
|
||||
|
||||
it 'adds optional types as defaults' do
|
||||
expect(mod::Strict::Integer).to be_optional
|
||||
|
|
Loading…
Reference in New Issue