lib/dry/schema/macros/dsl.rb in dry-schema-1.8.0 vs lib/dry/schema/macros/dsl.rb in dry-schema-1.9.0

- old
+ new

@@ -56,13 +56,13 @@ # required(:name).value { filled? & min_size?(2) } # # @return [Macros::Core] # # @api public - def value(*predicates, &block) + def value(...) append_macro(Macros::Value) do |macro| - macro.call(*predicates, &block) + macro.call(...) end end ruby2_keywords :value if respond_to?(:ruby2_keywords, true) # Prepends `:filled?` predicate @@ -74,13 +74,13 @@ # required(:name).filled(:string, format?: /\w+/) # # @return [Macros::Core] # # @api public - def filled(*args, &block) + def filled(...) append_macro(Macros::Filled) do |macro| - macro.call(*args, &block) + macro.call(...) end end ruby2_keywords :filled if respond_to?(:ruby2_keywords, true) # Specify a nested hash without enforced `hash?` type-check @@ -95,13 +95,13 @@ # end # # @return [Macros::Core] # # @api public - def schema(*args, &block) + def schema(...) append_macro(Macros::Schema) do |macro| - macro.call(*args, &block) + macro.call(...) end end ruby2_keywords :schema if respond_to?(:ruby2_keywords, true) # Specify a nested hash with enforced `hash?` type-check @@ -110,13 +110,13 @@ # required(:tags).hash do # required(:name).value(:string) # end # # @api public - def hash(*args, &block) + def hash(...) append_macro(Macros::Hash) do |macro| - macro.call(*args, &block) + macro.call(...) end end ruby2_keywords :hash if respond_to?(:ruby2_keywords, true) # Specify predicates that should be applied to each element of an array @@ -134,13 +134,13 @@ # end # # @return [Macros::Core] # # @api public - def each(*args, &block) + def each(...) append_macro(Macros::Each) do |macro| - macro.value(*args, &block) + macro.value(...) end end ruby2_keywords :each if respond_to?(:ruby2_keywords, true) # Like `each` but sets `array?` type-check @@ -154,13 +154,13 @@ # end # # @return [Macros::Core] # # @api public - def array(*args, &block) + def array(...) append_macro(Macros::Array) do |macro| - macro.value(*args, &block) + macro.value(...) end end ruby2_keywords :array if respond_to?(:ruby2_keywords, true) # Set type spec @@ -198,14 +198,15 @@ macro end end # @api private + # rubocop: disable Metrics/PerceivedComplexity def extract_type_spec(*args, nullable: false, set_type: true) type_spec = args[0] unless schema_or_predicate?(args[0]) - predicates = Array(type_spec ? args[1..-1] : args) + predicates = Array(type_spec ? args[1..] : args) type_rule = nil if type_spec resolved_type = resolve_type(type_spec, nullable) @@ -226,10 +227,11 @@ yield(*predicates, type_spec: nil, type_rule: type_rule) else yield(*predicates, type_spec: type_spec, type_rule: nil) end end + # rubocop: enable Metrics/PerceivedComplexity # @api private def resolve_type(type_spec, nullable) resolved = schema_dsl.resolve_type(type_spec) @@ -241,11 +243,11 @@ end # @api private def schema_or_predicate?(arg) arg.is_a?(Dry::Schema::Processor) || - arg.is_a?(Symbol) && - arg.to_s.end_with?(QUESTION_MARK) + (arg.is_a?(Symbol) && + arg.to_s.end_with?(QUESTION_MARK)) end end end end end