Class: Graphiti::Util::SimpleErrors
- Includes:
- Enumerable
- Defined in:
- lib/graphiti/util/simple_errors.rb
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #add(attribute, code, message: nil) ⇒ Object
- #added?(attribute, code) ⇒ Boolean
- #clear ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean (also: #blank?)
- #full_message(attribute, message) ⇒ Object
- #full_messages ⇒ Object (also: #to_a)
- #full_messages_for(attribute) ⇒ Object
-
#initialize(validation_target) ⇒ SimpleErrors
constructor
A new instance of SimpleErrors.
- #keys ⇒ Object
- #size ⇒ Object (also: #count)
- #values ⇒ Object
Constructor Details
#initialize(validation_target) ⇒ SimpleErrors
Returns a new instance of SimpleErrors.
11 12 13 14 15 16 |
# File 'lib/graphiti/util/simple_errors.rb', line 11 def initialize(validation_target) @target = validation_target @messages = apply_default_array({}) @details = apply_default_array({}) @errors = apply_default_array({}) end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
9 10 11 |
# File 'lib/graphiti/util/simple_errors.rb', line 9 def details @details end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
9 10 11 |
# File 'lib/graphiti/util/simple_errors.rb', line 9 def @messages end |
Instance Method Details
#[](attribute) ⇒ Object
23 24 25 |
# File 'lib/graphiti/util/simple_errors.rb', line 23 def [](attribute) [attribute.to_sym] end |
#add(attribute, code, message: nil) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/graphiti/util/simple_errors.rb', line 53 def add(attribute, code, message: nil) ||= "is #{code.to_s.humanize.downcase}" details[attribute.to_sym] << {error: code} [attribute.to_sym] << end |
#added?(attribute, code) ⇒ Boolean
60 61 62 |
# File 'lib/graphiti/util/simple_errors.rb', line 60 def added?(attribute, code) details[attribute.to_sym].include?({error: code}) end |
#clear ⇒ Object
18 19 20 21 |
# File 'lib/graphiti/util/simple_errors.rb', line 18 def clear .clear details.clear end |
#each ⇒ Object
27 28 29 30 31 |
# File 'lib/graphiti/util/simple_errors.rb', line 27 def each .each_key do |attribute| [attribute].each { |error| yield attribute, error } end end |
#empty? ⇒ Boolean Also known as: blank?
48 49 50 |
# File 'lib/graphiti/util/simple_errors.rb', line 48 def empty? size.zero? end |
#full_message(attribute, message) ⇒ Object
74 75 76 77 |
# File 'lib/graphiti/util/simple_errors.rb', line 74 def (attribute, ) return if attribute == :base "#{attribute} #{}" end |
#full_messages ⇒ Object Also known as: to_a
64 65 66 |
# File 'lib/graphiti/util/simple_errors.rb', line 64 def map { |attribute, | (attribute, ) } end |
#full_messages_for(attribute) ⇒ Object
69 70 71 72 |
# File 'lib/graphiti/util/simple_errors.rb', line 69 def (attribute) attribute = attribute.to_sym [attribute].map { || (attribute, ) } end |
#keys ⇒ Object
42 43 44 45 46 |
# File 'lib/graphiti/util/simple_errors.rb', line 42 def keys .select { |key, value| !value.empty? }.keys end |
#size ⇒ Object Also known as: count
33 34 35 |
# File 'lib/graphiti/util/simple_errors.rb', line 33 def size values.flatten.size end |
#values ⇒ Object
38 39 40 |
# File 'lib/graphiti/util/simple_errors.rb', line 38 def values .values.reject(&:empty?) end |