module ActsAsWarnable::WarnableClassMethods

Public Instance Methods

warn_on_failure_of(*methods) click to toggle source
# File lib/acts_as_warnable.rb, line 17
def warn_on_failure_of(*methods)
  options = methods.last.is_a?(Hash) ? methods.pop : {}

  methods.each do |method_name|
    define_method "#{method_name}_with_warning" do |*args, &block|
      begin
        send("#{method_name}_without_warning", *args, &block)
      rescue Exception => e
        issue_warning(
          warning_source(method_name),
          "#{e.class.name}: #{e.message}\n\n#{e.backtrace.join("\n")}"
        )
        raise if options[:raise_anyway]
      end
    end
    alias_method_chain method_name, :warning
  end
end