Module: Warnr

Defined in:
lib/warnr.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Patches ActiveRecord to:

  • Store a list of ‘warning’ fields

  • Store a list of callbacks for ‘after save, if warnings exist’

  • Store a list of warning messages

  • Move messages out of the errors object if they belong in the warning object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/warnr.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
  base.class_eval do
    class_inheritable_accessor :warnr_warning_fields
    self.warnr_warning_fields = []
    define_callbacks :on_save_with_warnings
    attr_reader :warnings
    after_initialize :setup_warnr_warnings
    alias_method_chain 'valid?', 'warnr'
  end
end