Sha256: 7316ca42a592e6a8b98a998487e77a2d5071cf69fce8a3aabb829adaadc6375a

Contents?: true

Size: 663 Bytes

Versions: 1

Compression:

Stored size: 663 Bytes

Contents

class ValidationError < StandardError
end

module NotifyIfInvalid
  def self.included(base)
    base.extend ClassMethods  
  end

  module ClassMethods
    def notify_if_invalid
      after_validation :check_if_invalid
      
      include InstanceMethods
      extend SingletonMethods
    end
  end

  module SingletonMethods
  end

  module InstanceMethods
    def check_if_invalid
      return if self.errors.empty?
      message = "#{self.class.to_s} #{self.errors.full_messages.to_sentence}: #{self.inspect}"
      error = ValidationError.new message
      Airbrake.notify_or_ignore error
    end
  end
end
ActiveRecord::Base.send(:include, NotifyIfInvalid)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notify_if_invalid-0.2.0 lib/notify_if_invalid.rb