Class: AdminAssistant::Request::ParamsForSave::Errors
- Inherits:
-
Object
- Object
- AdminAssistant::Request::ParamsForSave::Errors
- Defined in:
- lib/admin_assistant/request/base.rb
Instance Method Summary collapse
- #add(error_or_attr, message = nil, options = {}) ⇒ Object
- #each ⇒ Object
- #each_attribute ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
227 228 229 |
# File 'lib/admin_assistant/request/base.rb', line 227 def initialize @errors = Hash.new { |h,k| h[k] = []} end |
Instance Method Details
#add(error_or_attr, message = nil, options = {}) ⇒ Object
231 232 233 234 235 236 |
# File 'lib/admin_assistant/request/base.rb', line 231 def add(error_or_attr, = nil, = {}) error, attribute = error_or_attr.is_a?(Error) ? [error_or_attr, error_or_attr.attribute] : [nil, error_or_attr] [:message] = .delete(:default) if .has_key?(:default) @errors[attribute.to_s] << (error || Error.new(attribute, , )) end |
#each ⇒ Object
238 239 240 241 242 243 244 |
# File 'lib/admin_assistant/request/base.rb', line 238 def each @errors.each do |attr, ary| ary.each do |error| yield attr, error. end end end |
#each_attribute ⇒ Object
246 247 248 |
# File 'lib/admin_assistant/request/base.rb', line 246 def each_attribute @errors.keys.each do |key| yield key; end end |
#empty? ⇒ Boolean
250 251 252 |
# File 'lib/admin_assistant/request/base.rb', line 250 def empty? @errors.empty? end |