Class: Reorm::PropertyErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/reorm/property_errors.rb

Instance Method Summary collapse

Constructor Details

#initializePropertyErrors



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, message)
  if ![nil, ""].include?(message)
    @errors[property.to_sym] = [] if !@errors.include?(property.to_sym)
    @errors[property.to_sym] << message
  end
  self
end

#clear?Boolean



11
12
13
# File 'lib/reorm/property_errors.rb', line 11

def clear?
  @errors.empty?
end

#eachObject



39
40
41
# File 'lib/reorm/property_errors.rb', line 39

def each
  @errors.each {|property, messages| yield(property, messages)}
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 messages(property)
  [].concat(@errors.fetch(property.to_sym, []))
end

#propertiesObject



31
32
33
# File 'lib/reorm/property_errors.rb', line 31

def properties
  @errors.keys
end

#resetObject



15
16
17
# File 'lib/reorm/property_errors.rb', line 15

def reset
  @errors = {}
end

#to_sObject



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, messages|
    messages.each do |message|
      text << "#{text.size > 0 ? "\n" : ""}#{property} #{message}"
    end
  end
  text.string
end