Class: SimpleRecord::SimpleRecord_errors
- Inherits:
-
Object
- Object
- SimpleRecord::SimpleRecord_errors
- Defined in:
- lib/simple_record/errors.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #add(attribute, message, options = {}) ⇒ Object
- #add_to_base(msg) ⇒ Object
- #clear ⇒ Object
- #empty? ⇒ Boolean
- #full_messages ⇒ Object
-
#initialize(*params) ⇒ SimpleRecord_errors
constructor
A new instance of SimpleRecord_errors.
- #length ⇒ Object (also: #count, #size)
- #on(attribute) ⇒ Object (also: #[])
- #on_base ⇒ Object
Constructor Details
#initialize(*params) ⇒ SimpleRecord_errors
Returns a new instance of SimpleRecord_errors.
54 55 56 57 |
# File 'lib/simple_record/errors.rb', line 54 def initialize(*params) super(*params) @errors={} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
52 53 54 |
# File 'lib/simple_record/errors.rb', line 52 def errors @errors end |
Instance Method Details
#add(attribute, message, options = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/simple_record/errors.rb', line 63 def add(attribute, , = {}) # options param note used; just for drop in compatibility with ActiveRecord error, = , nil if .is_a?(Error) @errors[attribute.to_s] ||= [] @errors[attribute.to_s] << (error || Error.new(@base, attribute, , )) end |
#add_to_base(msg) ⇒ Object
59 60 61 |
# File 'lib/simple_record/errors.rb', line 59 def add_to_base(msg) add(:base, msg) end |
#clear ⇒ Object
83 84 85 |
# File 'lib/simple_record/errors.rb', line 83 def clear @errors.clear end |
#empty? ⇒ Boolean
87 88 89 |
# File 'lib/simple_record/errors.rb', line 87 def empty? @errors.empty? end |
#full_messages ⇒ Object
77 78 79 80 81 |
# File 'lib/simple_record/errors.rb', line 77 def @errors.values.inject([]) do |, errors| + errors.map { |error| error. } end end |
#length ⇒ Object Also known as: count, size
70 71 72 |
# File 'lib/simple_record/errors.rb', line 70 def length return @errors.length end |
#on(attribute) ⇒ Object Also known as: []
91 92 93 94 95 96 |
# File 'lib/simple_record/errors.rb', line 91 def on(attribute) attribute = attribute.to_s return nil unless @errors.has_key?(attribute) errors = @errors[attribute].map(&:to_s) errors.size == 1 ? errors.first : errors end |
#on_base ⇒ Object
100 101 102 |
# File 'lib/simple_record/errors.rb', line 100 def on_base on(:base) end |