Class: Reorm::PropertyErrors
- Inherits:
-
Object
- Object
- Reorm::PropertyErrors
- Defined in:
- lib/reorm/property_errors.rb
Instance Method Summary collapse
- #add(property, message) ⇒ Object
- #clear? ⇒ Boolean
- #each ⇒ Object
- #include?(property) ⇒ Boolean
-
#initialize ⇒ PropertyErrors
constructor
A new instance of PropertyErrors.
- #messages(property) ⇒ Object
- #properties ⇒ Object
- #reset ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ PropertyErrors
Returns a new instance of PropertyErrors.
7 8 9 |
# File 'lib/reorm/property_errors.rb', line 7 def initialize @errors = {} end |
Instance Method Details
#add(property, message) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/reorm/property_errors.rb', line 23 def add(property, ) if ![nil, ""].include?() @errors[property.to_sym] = [] if !@errors.include?(property.to_sym) @errors[property.to_sym] << end self end |
#clear? ⇒ Boolean
11 12 13 |
# File 'lib/reorm/property_errors.rb', line 11 def clear? @errors.empty? end |
#each ⇒ Object
39 40 41 |
# File 'lib/reorm/property_errors.rb', line 39 def each @errors.each {|property, | yield(property, )} end |
#include?(property) ⇒ Boolean
19 20 21 |
# File 'lib/reorm/property_errors.rb', line 19 def include?(property) @errors.include?(property.to_sym) end |
#messages(property) ⇒ Object
35 36 37 |
# File 'lib/reorm/property_errors.rb', line 35 def (property) [].concat(@errors.fetch(property.to_sym, [])) end |
#properties ⇒ Object
31 32 33 |
# File 'lib/reorm/property_errors.rb', line 31 def properties @errors.keys end |
#reset ⇒ Object
15 16 17 |
# File 'lib/reorm/property_errors.rb', line 15 def reset @errors = {} end |
#to_s ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/reorm/property_errors.rb', line 43 def to_s text = StringIO.new @errors.each do |property, | .each do || text << "#{text.size > 0 ? "\n" : ""}#{property} #{}" end end text.string end |