Class: ActiveModel::BetterErrors::Errors

Inherits:
Object
  • Object
show all
Includes:
Emulation
Defined in:
lib/active_model/better_errors/errors.rb

Overview

Errors

Constant Summary

Constants included from Emulation

ActiveModel::BetterErrors::Emulation::MESSAGE_REPORTER_METHODS, ActiveModel::BetterErrors::Emulation::MODEL_METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Emulation

#add, #add_on_blank, #add_on_empty, #as_json, included, #to_xml

Constructor Details

#initialize(base) ⇒ Errors

Returns a new instance of Errors.



12
13
14
15
16
# File 'lib/active_model/better_errors/errors.rb', line 12

def initialize(base)
  @base = base
  @reporters = {}
  @reporter_classes = reporter_classes
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



11
12
13
# File 'lib/active_model/better_errors/errors.rb', line 11

def base
  @base
end

Instance Method Details

#array_reporterObject



30
31
32
# File 'lib/active_model/better_errors/errors.rb', line 30

def array_reporter
  get_reporter(:array)
end

#error_collectionObject



18
19
20
# File 'lib/active_model/better_errors/errors.rb', line 18

def error_collection
  @error_collection ||= ErrorCollection.new(@base)
end

#get_reporter(type) ⇒ Object



43
44
45
46
47
# File 'lib/active_model/better_errors/errors.rb', line 43

def get_reporter(type)
  type = type.to_s
  klass = get_reporter_class(type)
  @reporters[type] = klass.new(error_collection)
end

#get_reporter_class(type) ⇒ Object



53
54
55
56
# File 'lib/active_model/better_errors/errors.rb', line 53

def get_reporter_class(type)
  type = type.to_s
  @reporter_classes[type]
end

#hash_reporterObject



26
27
28
# File 'lib/active_model/better_errors/errors.rb', line 26

def hash_reporter
  get_reporter(:hash)
end

#message_reporterObject



22
23
24
# File 'lib/active_model/better_errors/errors.rb', line 22

def message_reporter
  get_reporter(:message)
end

#reporter_classesObject



49
50
51
# File 'lib/active_model/better_errors/errors.rb', line 49

def reporter_classes
  ::ActiveModel::BetterErrors.reporters
end

#set_reporter(type, reporter) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/active_model/better_errors/errors.rb', line 34

def set_reporter(type, reporter)
  type = type.to_s
  klass = ::ActiveModel::BetterErrors
    .get_reporter_class(type, reporter)

  @reporter_classes[type] = klass
  @reporters.delete type
end