Sha256: 9c7a16e83a8f2bca1ba89288566b9590de439bdc24e356b70cbffb4d82765db4

Contents?: true

Size: 1.92 KB

Versions: 24

Compression:

Stored size: 1.92 KB

Contents

require 'rails/generators'
require 'rails/generators/named_base'
require 'generators/rollbar/rollbar_generator'

module Rollbar
  module Generators
    class RollbarGenerator < ::Rails::Generators::Base
      argument :access_token, :type => :string, :banner => 'access_token', :default => :use_env_sentinel

      source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))

      def create_initializer
        say 'creating initializer...'
        if access_token_configured?
          say "It looks like you've already configured Rollbar."
          say 'To re-create the config file, remove it first: config/initializers/rollbar.rb'
          exit
        end

        begin
          require 'ey_config'
        rescue LoadError
        end

        if defined? EY::Config
          say 'Access token will be read from Engine Yard configuration'
        else
          if access_token === :use_env_sentinel
            say 'Generator run without an access token; assuming you want to configure using an environment variable.'
            say "You'll need to add an environment variable ROLLBAR_ACCESS_TOKEN with your access token:"
            say "\n$ export ROLLBAR_ACCESS_TOKEN=yourtokenhere"
            say "\nIf that's not what you wanted to do:"
            say "\n$ rm config/initializers/rollbar.rb"
            say '$ rails generate rollbar yourtokenhere'
            say "\n"
          else
            say 'access token: ' << access_token
          end
        end

        template 'initializer.rb', 'config/initializers/rollbar.rb', :assigns => { :access_token => access_token_expr }

        # TODO: run rake test task
      end

      def access_token_expr
        if access_token === :use_env_sentinel
          "ENV['ROLLBAR_ACCESS_TOKEN']"
        else
          "'#{access_token}'"
        end
      end

      def access_token_configured?
        File.exist?('config/initializers/rollbar.rb')
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rollbar-3.2.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-3.1.2 lib/generators/rollbar/rollbar_generator.rb
rollbar-3.1.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-3.1.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-3.0.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-3.0.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.27.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.27.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.26.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.26.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.25.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.25.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.24.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.23.2 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.23.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.23.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.22.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.22.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.21.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-2.20.2 lib/generators/rollbar/rollbar_generator.rb