Class: Banalize::Errors
- Inherits:
-
Object
- Object
- Banalize::Errors
- Defined in:
- lib/banalize/errors.rb
Overview
Errors class provides stograge of error messages while running policy checks.
Instance Attribute Summary collapse
-
#messages ⇒ Object
Returns the value of attribute messages.
Class Method Summary collapse
-
.to_s(messages = []) ⇒ Object
Convert Array of Hashes of error messages into readable form.
Instance Method Summary collapse
- #add(message, line = nil) ⇒ Object
-
#any? ⇒ Boolean
Retrun true if there are any errors.
-
#empty? ⇒ Boolean
Retrun true if there are no errors.
-
#initialize(klass) ⇒ Errors
constructor
A new instance of Errors.
Constructor Details
#initialize(klass) ⇒ Errors
Returns a new instance of Errors.
6 7 8 9 |
# File 'lib/banalize/errors.rb', line 6 def initialize klass @klass = klass @messages = [] end |
Instance Attribute Details
#messages ⇒ Object
Returns the value of attribute messages.
11 12 13 |
# File 'lib/banalize/errors.rb', line 11 def @messages end |
Class Method Details
.to_s(messages = []) ⇒ Object
Convert Array of Hashes of error messages into readable form
34 35 36 37 38 39 40 |
# File 'lib/banalize/errors.rb', line 34 def self.to_s =[] return '' if .empty? .map do |err| "#{err[:message]}#{err[:line] ? ", on line #{err[:line]}" : ''}" end end |
Instance Method Details
#add(message, line = nil) ⇒ Object
13 14 15 |
# File 'lib/banalize/errors.rb', line 13 def add , line=nil @messages << { :message => , :line => line } end |
#any? ⇒ Boolean
Retrun true if there are any errors
26 27 28 |
# File 'lib/banalize/errors.rb', line 26 def any? ! empty? end |
#empty? ⇒ Boolean
Retrun true if there are no errors
19 20 21 |
# File 'lib/banalize/errors.rb', line 19 def empty? @messages.empty? end |