diff --git a/Gemfile b/Gemfile index fd231f958..0025b968b 100644 --- a/Gemfile +++ b/Gemfile @@ -7,9 +7,9 @@ eval_gemfile "Gemfile.devtools" gemspec gem "dry-configurable", github: "dry-rb/dry-configurable", branch: "main" +gem "dry-core", github: "dry-rb/dry-core", branch: "main" gem "dry-logic", github: "dry-rb/dry-logic", branch: "main" gem "dry-types", github: "dry-rb/dry-types", branch: "main" -gem "dry-core", github: "dry-rb/dry-core", branch: "main" group :test do gem "dry-monads" diff --git a/bin/console b/bin/console index 6211105d7..3e80e695e 100755 --- a/bin/console +++ b/bin/console @@ -11,16 +11,16 @@ module Types end class Context - def schema(&block) - Dry::Schema.define(&block) + def schema(&) + Dry::Schema.define(&) end - def params(&block) - Dry::Schema.Params(&block) + def params(&) + Dry::Schema.Params(&) end - def json(&block) - Dry::Schema.JSON(&block) + def json(&) + Dry::Schema.JSON(&) end end diff --git a/lib/dry/schema.rb b/lib/dry/schema.rb index 25d8a6bbe..f25da6987 100644 --- a/lib/dry/schema.rb +++ b/lib/dry/schema.rb @@ -64,8 +64,8 @@ def self.config # @see DSL.new # # @api public - def self.define(**options, &block) - DSL.new(**options, &block).call + def self.define(...) + DSL.new(...).call end # Define a schema suitable for HTTP params @@ -83,8 +83,8 @@ def self.define(**options, &block) # @see Schema#define # # @api public - def self.Params(**options, &block) - define(**options, processor_type: Params, &block) + def self.Params(**options, &) + define(**options, processor_type: Params, &) end singleton_class.send(:alias_method, :Form, :Params) @@ -103,8 +103,8 @@ def self.Params(**options, &block) # @see Schema#define # # @api public - def self.JSON(**options, &block) - define(**options, processor_type: JSON, &block) + def self.JSON(**options, &) + define(**options, processor_type: JSON, &) end loader.setup diff --git a/lib/dry/schema/config.rb b/lib/dry/schema/config.rb index 75ba72e90..0cefa569f 100644 --- a/lib/dry/schema/config.rb +++ b/lib/dry/schema/config.rb @@ -74,9 +74,9 @@ def inspect # Forward to the underlying config object # # @api private - def method_missing(meth, *args, &block) + def method_missing(meth, ...) super unless config.respond_to?(meth) - config.public_send(meth, *args) + config.public_send(meth, ...) end end end diff --git a/lib/dry/schema/dsl.rb b/lib/dry/schema/dsl.rb index f83139cf3..8d3bc6b55 100644 --- a/lib/dry/schema/dsl.rb +++ b/lib/dry/schema/dsl.rb @@ -99,8 +99,8 @@ def self.new(**options, &block) # @return [DSL] # # @api public - def configure(&block) - config.configure(&block) + def configure(&) + config.configure(&) self end @@ -141,8 +141,8 @@ def [](name) # @return [Macros::Required] # # @api public - def required(name, &block) - key(name, macro: Macros::Required, &block) + def required(name, &) + key(name, macro: Macros::Required, &) end # Define an optional key @@ -157,8 +157,8 @@ def required(name, &block) # @return [Macros::Optional] # # @api public - def optional(name, &block) - key(name, macro: Macros::Optional, &block) + def optional(name, &) + key(name, macro: Macros::Optional, &) end # A generic method for defining keys @@ -249,8 +249,8 @@ def array # @return [DSL] # # @api public - def before(key, &block) - steps.before(key, &block) + def before(key, &) + steps.before(key, &) self end @@ -264,8 +264,8 @@ def before(key, &block) # @return [DSL] # # @api public - def after(key, &block) - steps.after(key, &block) + def after(key, &) + steps.after(key, &) self end diff --git a/lib/dry/schema/extensions/hints/message_compiler_methods.rb b/lib/dry/schema/extensions/hints/message_compiler_methods.rb index 857ab36a1..e2f6f813e 100644 --- a/lib/dry/schema/extensions/hints/message_compiler_methods.rb +++ b/lib/dry/schema/extensions/hints/message_compiler_methods.rb @@ -31,7 +31,7 @@ def hints? # @api private def filter(messages, opts) - Array(messages).flatten.map { |msg| msg unless exclude?(msg, opts) }.compact.uniq + Array(messages).flatten.reject { |msg| exclude?(msg, opts) }.uniq end # @api private diff --git a/lib/dry/schema/extensions/struct.rb b/lib/dry/schema/extensions/struct.rb index 770dffbeb..995f4653f 100644 --- a/lib/dry/schema/extensions/struct.rb +++ b/lib/dry/schema/extensions/struct.rb @@ -23,7 +23,7 @@ def visit_struct(node) def call(*args) if args.size >= 1 && struct?(args[0]) if block_given? - raise ArgumentError, "blocks are not supported when using "\ + raise ArgumentError, "blocks are not supported when using " \ "a struct class (#{name.inspect} => #{args[0]})" end diff --git a/lib/dry/schema/key_coercer.rb b/lib/dry/schema/key_coercer.rb index 1524cae59..f469765f6 100644 --- a/lib/dry/schema/key_coercer.rb +++ b/lib/dry/schema/key_coercer.rb @@ -27,8 +27,8 @@ def self.symbolized(*args) end # @api private - def initialize(key_map, &coercer) - @key_map = key_map.coercible(&coercer) + def initialize(key_map, &) + @key_map = key_map.coercible(&) end # @api private diff --git a/lib/dry/schema/key_map.rb b/lib/dry/schema/key_map.rb index 9b8119aa1..1ee996c6e 100644 --- a/lib/dry/schema/key_map.rb +++ b/lib/dry/schema/key_map.rb @@ -105,8 +105,8 @@ def to_dot_notation # Iterate over keys # # @api public - def each(&block) - keys.each(&block) + def each(&) + keys.each(&) end # Return a new key map merged with the provided one diff --git a/lib/dry/schema/macros/schema.rb b/lib/dry/schema/macros/schema.rb index 0287161c8..6e4c658fc 100644 --- a/lib/dry/schema/macros/schema.rb +++ b/lib/dry/schema/macros/schema.rb @@ -55,8 +55,8 @@ def merge_operation_types(op) # @api private # rubocop: disable Metrics/AbcSize - def define(*args, &block) - definition = schema_dsl.new(path: schema_dsl.path, &block) + def define(*args, &) + definition = schema_dsl.new(path: schema_dsl.path, &) schema = definition.call type_schema = if array_type?(parent_type) diff --git a/lib/dry/schema/macros/value.rb b/lib/dry/schema/macros/value.rb index 4984b1d00..b2cde83e1 100644 --- a/lib/dry/schema/macros/value.rb +++ b/lib/dry/schema/macros/value.rb @@ -41,7 +41,7 @@ def call(*args, **opts, &block) end end - trace_opts = opts.reject { |key, _| %i[type_spec type_rule].include?(key) } + trace_opts = opts.except(:type_spec, :type_rule) if (type_rule = opts[:type_rule]) trace.append(type_rule).evaluate(*predicates, **trace_opts) @@ -112,9 +112,9 @@ def respond_to_missing?(meth, include_private = false) private # @api private - def method_missing(meth, *args, &block) + def method_missing(meth, ...) if meth.to_s.end_with?(QUESTION_MARK) - trace.__send__(meth, *args, &block) + trace.__send__(meth, ...) else super end diff --git a/lib/dry/schema/message_compiler.rb b/lib/dry/schema/message_compiler.rb index 17f0b4d15..d51ade78f 100644 --- a/lib/dry/schema/message_compiler.rb +++ b/lib/dry/schema/message_compiler.rb @@ -212,8 +212,8 @@ def message_tokens(args) when ::Array hash[arg[0]] = arg[1].join(LIST_SEPARATOR) when ::Range - hash["#{arg[0]}_left".to_sym] = arg[1].first - hash["#{arg[0]}_right".to_sym] = arg[1].last + hash[:"#{arg[0]}_left"] = arg[1].first + hash[:"#{arg[0]}_right"] = arg[1].last else hash[arg[0]] = arg[1] end diff --git a/lib/dry/schema/messages/yaml.rb b/lib/dry/schema/messages/yaml.rb index 5bea6c388..692a0932b 100644 --- a/lib/dry/schema/messages/yaml.rb +++ b/lib/dry/schema/messages/yaml.rb @@ -165,12 +165,12 @@ def interpolate(key, options, **data) # @api private def evaluation_context(key, options) cache.fetch_or_store(get(key, options).fetch(:text)) do |input| - tokens = input.scan(TOKEN_REGEXP).flatten(1).map(&:to_sym).to_set + tokens = input.scan(TOKEN_REGEXP).flatten(1).to_set(&:to_sym) text = input.gsub("%", "#") # rubocop:disable Security/Eval evaluator = eval(<<~RUBY, EMPTY_CONTEXT, __FILE__, __LINE__ + 1) - -> (#{tokens.map { |token| "#{token}:" }.join(", ")}) { "#{text}" } + -> (#{tokens.map { |token| "#{token}:" }.join(", ")}) { "#{text}" } # -> (a:, b:) { "Translation #\{a} #\{b}" } RUBY # rubocop:enable Security/Eval diff --git a/lib/dry/schema/path.rb b/lib/dry/schema/path.rb index f3ce95eda..ab980ce6b 100644 --- a/lib/dry/schema/path.rb +++ b/lib/dry/schema/path.rb @@ -27,7 +27,7 @@ class Path def self.call(spec) case spec when ::Symbol, ::Array - new(::Array[*spec]) + new([*spec]) when ::String new(spec.split(DOT).map(&:to_sym)) when ::Hash @@ -49,7 +49,7 @@ def self.[](spec) # @api private def self.keys_from_hash(hash) hash.inject([]) { |a, (k, v)| - v.is_a?(::Hash) ? a.concat([k, *keys_from_hash(v)]) : a.concat([k, v]) + v.is_a?(::Hash) ? a.push(k, *keys_from_hash(v)) : a.push(k, v) } end @@ -66,8 +66,8 @@ def to_h(value = EMPTY_ARRAY.dup) end # @api private - def each(&block) - keys.each(&block) + def each(&) + keys.each(&) end # @api private diff --git a/lib/dry/schema/processor.rb b/lib/dry/schema/processor.rb index a52ada4c8..d25fc071f 100644 --- a/lib/dry/schema/processor.rb +++ b/lib/dry/schema/processor.rb @@ -42,9 +42,9 @@ class << self # @return [Class] # # @api public - def define(&block) + def define(&) @definition ||= DSL.new( - processor_type: self, parent: superclass.definition, **config.to_h, &block + processor_type: self, parent: superclass.definition, **config.to_h, & ) self end diff --git a/lib/dry/schema/result.rb b/lib/dry/schema/result.rb index 8674b85b6..2025e2172 100644 --- a/lib/dry/schema/result.rb +++ b/lib/dry/schema/result.rb @@ -43,18 +43,18 @@ def self.new(*, **) # @return [Result] # # @api private - def at(at_path, &block) - new(@output, path: Path.new([*path, *Path[at_path]]), &block) + def at(at_path, &) + new(@output, path: Path.new([*path, *Path[at_path]]), &) end # @api private - def new(output, **opts, &block) + def new(output, **opts, &) self.class.new( output, message_compiler: message_compiler, result_ast: result_ast, **opts, - &block + & ) end diff --git a/spec/integration/issues_spec.rb b/spec/integration/issues_spec.rb index 8aad16961..c019b8cff 100644 --- a/spec/integration/issues_spec.rb +++ b/spec/integration/issues_spec.rb @@ -63,7 +63,7 @@ end let(:calendar_date) do - Class.new(::Date) do + Class.new(Date) do def to_json(*args) strftime("--%m-%d").to_json(*args) end diff --git a/spec/integration/messages/namespaced_spec.rb b/spec/integration/messages/namespaced_spec.rb index b8d95df71..cb586bba0 100644 --- a/spec/integration/messages/namespaced_spec.rb +++ b/spec/integration/messages/namespaced_spec.rb @@ -42,7 +42,7 @@ config.messages.namespace = :post required(:post_body).filled - required(:comment).hash(::Test::CommentSchema) + required(:comment).hash(Test::CommentSchema) end end diff --git a/spec/integration/schema/type_spec.rb b/spec/integration/schema/type_spec.rb index aec46b431..6eda85c41 100644 --- a/spec/integration/schema/type_spec.rb +++ b/spec/integration/schema/type_spec.rb @@ -247,7 +247,7 @@ context "constructor on optional type" do let(:trimmed_string) do Types::String.optional.constructor do |str, &block| - if str.is_a?(::String) + if str.is_a?(String) stripped = str.strip if stripped.empty? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ee0c316ea..74ddf4149 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,8 +14,8 @@ rescue LoadError; end SPEC_ROOT = Pathname(__dir__) -Dir[SPEC_ROOT.join("shared/**/*.rb")].sort.each(&method(:require)) -Dir[SPEC_ROOT.join("support/**/*.rb")].sort.each(&method(:require)) +Dir[SPEC_ROOT.join("shared/**/*.rb")].each(&method(:require)) +Dir[SPEC_ROOT.join("support/**/*.rb")].each(&method(:require)) require "dry/schema" require "dry/types"