lib/dry/schema/processor.rb in dry-schema-1.0.3 vs lib/dry/schema/processor.rb in dry-schema-1.1.0
- old
+ new
@@ -27,13 +27,16 @@
extend Dry::Initializer
extend Dry::Configurable
setting :key_map_type
setting :type_registry, TypeRegistry.new
+ setting :filter_empty_string, false
- param :steps, default: -> { EMPTY_ARRAY.dup }
+ option :steps, default: -> { EMPTY_ARRAY.dup }
+ option :schema_dsl
+
class << self
# Return DSL configured via #define
#
# @return [DSL]
# @api private
@@ -58,13 +61,15 @@
# Build a new processor object
#
# @return [Processor]
#
# @api public
- def new(&block)
- if block
- super.tap(&block)
+ def new(options = nil, &block)
+ if options || block
+ processor = super
+ yield(processor) if block
+ processor
elsif definition
definition.call
else
raise ArgumentError, 'Cannot create a schema without a definition'
end
@@ -175,8 +180,22 @@
# @api private
def rule_applier
@rule_applier ||= steps.last
end
alias_method :to_rule, :rule_applier
+
+ # Check if there are filter rules
+ #
+ # @api private
+ def filter_rules?
+ @filter_rules_predicate ||= schema_dsl.filter_rules?
+ end
+
+ # Return filter schema
+ #
+ # @api private
+ def filter_schema
+ @filter_schema ||= schema_dsl.filter_schema
+ end
end
end
end