Class: Dry::Validation::MessageSet
- Inherits:
-
Object
- Object
- Dry::Validation::MessageSet
- Includes:
- Core::Constants, Enumerable
- Defined in:
- lib/dry/validation/message_set.rb
Constant Summary collapse
- HINT_EXCLUSION =
i(key? filled? none? bool? str? int? float? decimal? date? date_time? time? hash? array?).freeze
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #failures? ⇒ Boolean
-
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
constructor
A new instance of MessageSet.
- #root? ⇒ Boolean
- #to_a ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
Constructor Details
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
Returns a new instance of MessageSet.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dry/validation/message_set.rb', line 17 def initialize(, = EMPTY_HASH) = @hints = .select(&:hint?) @failures = - hints @paths = failures.map(&:path).uniq = initialize_hints! initialize_placeholders! end |
Instance Attribute Details
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
11 12 13 |
# File 'lib/dry/validation/message_set.rb', line 11 def failures @failures end |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
11 12 13 |
# File 'lib/dry/validation/message_set.rb', line 11 def hints @hints end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
11 12 13 |
# File 'lib/dry/validation/message_set.rb', line 11 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/dry/validation/message_set.rb', line 11 def end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
11 12 13 |
# File 'lib/dry/validation/message_set.rb', line 11 def paths @paths end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
11 12 13 |
# File 'lib/dry/validation/message_set.rb', line 11 def placeholders @placeholders end |
Class Method Details
.[](messages, options = EMPTY_HASH) ⇒ Object
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def self.[](, = EMPTY_HASH) new(.flatten, ) end |
Instance Method Details
#dump ⇒ Object
28 29 30 |
# File 'lib/dry/validation/message_set.rb', line 28 def dump root? ? to_a : to_h end |
#each(&block) ⇒ Object
44 45 46 47 |
# File 'lib/dry/validation/message_set.rb', line 44 def each(&block) return to_enum unless block .each(&block) end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/dry/validation/message_set.rb', line 36 def empty? .empty? end |
#failures? ⇒ Boolean
32 33 34 |
# File 'lib/dry/validation/message_set.rb', line 32 def failures? [:failures].equal?(true) end |
#root? ⇒ Boolean
40 41 42 |
# File 'lib/dry/validation/message_set.rb', line 40 def root? !empty? && failures.all?(&:root?) end |
#to_a ⇒ Object
58 59 60 |
# File 'lib/dry/validation/message_set.rb', line 58 def to_a to_h.values.flatten end |
#to_h ⇒ Object Also known as: to_hash
49 50 51 52 53 54 55 |
# File 'lib/dry/validation/message_set.rb', line 49 def to_h if root? { nil => failures.map(&:to_s) } else failures? ? : hints_map end end |