Class: AdminAssistant::Request::ParamsForSave::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_assistant/request/base.rb

Instance Method Summary collapse

Constructor Details

#initializeErrors

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, message = nil, options = {})
  error, attribute = error_or_attr.is_a?(Error) ? [error_or_attr, error_or_attr.attribute] : [nil, error_or_attr]
  options[:message] = options.delete(:default) if options.has_key?(:default)
    
  @errors[attribute.to_s] << (error || Error.new(attribute, message, options))
end

#eachObject



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.message
    end
  end
end

#each_attributeObject



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

Returns:

  • (Boolean)


250
251
252
# File 'lib/admin_assistant/request/base.rb', line 250

def empty?
  @errors.empty?
end