Sha256: 6628ea0de183a4ee5c5ca2d4d8e87f4be043035d2cfbd72177295e41e22a23a9

Contents?: true

Size: 1.29 KB

Versions: 11

Compression:

Stored size: 1.29 KB

Contents

Rollbar.plugins.define('active_model') do
  dependency { !configuration.disable_monkey_patch }
  dependency { defined?(ActiveModel::Validations) }
  dependency do
    require 'active_model/version'

    ActiveModel::VERSION::MAJOR >= 3
  end

  execute! do
    module Rollbar
      # Module that defines methods to be used by instances using
      # ActiveModel::Validations
      # The name is ActiveRecordExtension in order to not break backwards
      # compatibility, although probably it should be named
      # Rollbar::ValidationsExtension or similar
      module ActiveRecordExtension
        def report_validation_errors_to_rollbar
          errors.full_messages.each do |error|
            Rollbar.log_info(
              "[Rollbar] Reporting form validation error: #{error} for #{self}"
            )
            Rollbar.warning("Form Validation Error: #{error} for #{self}")
          end
        end
      end
    end
  end

  execute! do
    ActiveModel::Validations.module_eval do
      include Rollbar::ActiveRecordExtension
    end

    active_support_was_defined = defined?(ActiveRecord::Base)

    ActiveSupport.on_load(:active_record) do
      if active_support_was_defined
        ActiveRecord::Base.class_eval do
          include Rollbar::ActiveRecordExtension
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rollbar-3.6.0 lib/rollbar/plugins/validations.rb
rollbar-3.5.2 lib/rollbar/plugins/validations.rb
rollbar-3.5.1 lib/rollbar/plugins/validations.rb
rollbar-3.5.0 lib/rollbar/plugins/validations.rb
rollbar-3.4.2 lib/rollbar/plugins/validations.rb
rollbar-3.4.1 lib/rollbar/plugins/validations.rb
rollbar-3.4.0 lib/rollbar/plugins/validations.rb
rollbar-3.3.3 lib/rollbar/plugins/validations.rb
rollbar-3.3.2 lib/rollbar/plugins/validations.rb
rollbar-3.3.1 lib/rollbar/plugins/validations.rb
rollbar-3.3.0 lib/rollbar/plugins/validations.rb