Class: ValidationErrorReporter::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/validation_error_reporter/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Error

Returns a new instance of Error.



5
6
7
# File 'lib/validation_error_reporter/error.rb', line 5

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



3
4
5
# File 'lib/validation_error_reporter/error.rb', line 3

def record
  @record
end

Instance Method Details

#model_nameObject



9
10
11
# File 'lib/validation_error_reporter/error.rb', line 9

def model_name
  record.class.model_name.name
end

#model_total_countObject



13
14
15
# File 'lib/validation_error_reporter/error.rb', line 13

def model_total_count
  record.class.count
end

#to_sObject



17
18
19
20
# File 'lib/validation_error_reporter/error.rb', line 17

def to_s
  "#{record.class.model_name.human} #{record.public_send(record.class.primary_key)}:\n" +
    record.errors.full_messages.map {|e| "  #{e}"}.join("\n")
end