Sha256: d36f2a7970aa04c50ec35ca025c88aa1302e1991d0571e470cb548c07328a210

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

require 'rails/generators'
require 'rails/generators/named_base'

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

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

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

        puts "access token: " << access_token

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

        # TODO run rake test task
      end

      #def add_options!(opt)
      #  opt.on('-a', '--access-token=token', String, "Your Rollbar project access token") { |v| options[:access_token] = v }
      #end
#
#      def manifest
#        if !access_token_configured? && !options[:access_token]
#          puts "access_token is required. Pass --access-token=YOUR_ACCESS_TOKEN"
#          exit
#        end
#        
#        record do |m|
#          m.template 'initializer.rb', 'config/initializers/rollbar.rb',
#            :assigns => { :access_token => access_token_expr }
#          # TODO run rake test task
#        end
#      end

      def access_token_expr
        "'#{access_token}'"
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rollbar-0.9.4 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.9.3 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.9.2 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.9.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.9.0 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.8.3 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.8.2 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.8.1 lib/generators/rollbar/rollbar_generator.rb
rollbar-0.8.0 lib/generators/rollbar/rollbar_generator.rb