Sha256: 703bc9c18ff10f0bf5a44dcf9871b49bacddd83a6ee361858eeac5d1f420b389

Contents?: true

Size: 670 Bytes

Versions: 1

Compression:

Stored size: 670 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
      HoptoadNotifier.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.1.2 lib/notify_if_invalid.rb