Sha256: 4ec5b3f5777acbd8ea205286eb65c836c5a0f448a62f38615ff95fde7687a821

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

require "rails/generators"
require_relative "../../actions"

module Suspenders
  module Production
    class ErrorReportingGenerator < Generators::Base
      def add_sentry
        gem "sentry-raven"
        Bundler.with_clean_env { run "bundle install" }
      end

      def set_up_sentry
        copy_file "sentry.rb", "config/initializers/sentry.rb"
      end

      def configure_sentry_context
        inject_into_class(
          "app/controllers/application_controller.rb",
          'ApplicationController',
          context_configuration
        )
      end

      def env_vars
        expand_json(
          "app.json",
          env: {
            SENTRY_DSN: { required: true },
            SENTRY_ENV: { required: true }
          }
        )
      end

      private

      def context_configuration
        <<-RUBY
    before_action :set_raven_context

    private

    def set_raven_context
      Raven.user_context(id: session[:current_user_id])
      Raven.extra_context(params: params.to_unsafe_h, url: request.url)
    end
        RUBY
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
welaika-suspenders-2.33 lib/suspenders/generators/production/error_reporting_generator.rb
welaika-suspenders-2.32.2 lib/suspenders/generators/production/error_reporting_generator.rb
welaika-suspenders-2.32.1 lib/suspenders/generators/production/error_reporting_generator.rb
welaika-suspenders-2.32.0 lib/suspenders/generators/production/error_reporting_generator.rb
welaika-suspenders-2.31.0 lib/suspenders/generators/production/error_reporting_generator.rb
welaika-suspenders-2.30.0 lib/suspenders/generators/production/error_reporting_generator.rb