Module: Dry::Schema::Extensions::Hints::MessageCompilerMethods
- Included in:
- MessageCompiler
- Defined in:
- lib/dry/schema/extensions/hints/message_compiler_methods.rb
Constant Summary collapse
- HINT_TYPE_EXCLUSION =
%i[ key? nil? bool? str? int? float? decimal? date? date_time? time? hash? array? ].freeze
- HINT_OTHER_EXCLUSION =
%i[format? filled?].freeze
Instance Attribute Summary collapse
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
Instance Method Summary collapse
- #exclude?(messages, opts) ⇒ Boolean private
- #filter(messages, opts) ⇒ Object private
- #hints? ⇒ Boolean private
- #initialize(*args) ⇒ Object
- #message_type(options) ⇒ Object private
- #visit_each(node, opts) ⇒ Object private
- #visit_hint(node, opts) ⇒ Object private
- #visit_predicate(node, opts) ⇒ Object private
Instance Attribute Details
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
15 16 17 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 15 def hints @hints end |
Instance Method Details
#exclude?(messages, opts) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 33 def exclude?(, opts) Array().all? do |msg| hints = opts .hints .reject { |hint| msg == hint } .reject { |hint| hint.predicate == :filled? } key_failure = opts.key_failure?(msg.path) predicate = msg.predicate (HINT_TYPE_EXCLUSION.include?(predicate) && !key_failure) || (msg.predicate == :filled? && key_failure) || (!key_failure && HINT_TYPE_EXCLUSION.include?(predicate) && !hints.empty? && hints.any? { |hint| hint.path == msg.path }) || HINT_OTHER_EXCLUSION.include?(predicate) end end |
#filter(messages, opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 28 def filter(, opts) Array().flatten.map { |msg| msg unless exclude?(msg, opts) }.compact.uniq end |
#hints? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 23 def hints? hints.equal?(true) end |
#initialize(*args) ⇒ Object
17 18 19 20 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 17 def initialize(*args) super @hints = @options.fetch(:hints, true) end |
#message_type(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 52 def () [:message_type].equal?(:hint) ? Hint : Message end |
#visit_each(node, opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 74 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 71 def visit_each(node, opts) # TODO: we can still generate a hint for elements here! [] end |
#visit_hint(node, opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 57 def visit_hint(node, opts) if hints? filter(visit(node, opts.(message_type: :hint)), opts) end end |
#visit_predicate(node, opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 67 68 |
# File 'lib/dry/schema/extensions/hints/message_compiler_methods.rb', line 64 def visit_predicate(node, opts) = super opts. << end |