Sha256: 68181c479df6bb84f45ad784eb5db42dc19d433d05f80646843d7620be0cb43b

Contents?: true

Size: 1.5 KB

Versions: 13

Compression:

Stored size: 1.5 KB

Contents

module Intercom
  module Generators
    class ConfigGenerator < ::Rails::Generators::Base

      def self.source_root
        File.dirname(__FILE__)
      end

      argument :app_id, :desc => "Your Intercom app-id, which can be found here: https://www.intercom.io/apps/api_keys"
      argument :api_secret, :desc => "Your Intercom api-secret, used for secure mode", :optional => true
      argument :api_key, :desc => "An Intercom API key, for various rake tasks", :optional => true

      FALSEY_RESPONSES = ['n', 'no']
      def create_config_file
        @app_id = app_id
        @api_secret = api_secret
        @api_key = api_key

        introduction = <<-desc
Intercom will automatically insert its javascript before the closing '</body>' 
tag on every page where it can find a logged-in user. Intercom by default
looks for logged-in users, in the controller, via 'current_user' and '@user'.

Is the logged-in user accessible via either 'current_user' or '@user'? [Yn]
        desc

        print "#{introduction.strip} "
        default_ok = $stdin.gets.strip.downcase 

        if FALSEY_RESPONSES.include?(default_ok) 
          custom_current_user_question = <<-desc

How do you access the logged-in user in your controllers? This can be
any Ruby code, e.g. 'current_customer', '@admin', etc.:
          desc

          print "#{custom_current_user_question.rstrip} "
          @current_user = $stdin.gets.strip
        end

        template("intercom.rb.erb", "config/initializers/intercom.rb")
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
intercom-rails-0.2.24 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.23 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.22 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.21 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.20 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.19 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.18 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.17 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.16 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.15 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.14 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.13 lib/rails/generators/intercom/config/config_generator.rb
intercom-rails-0.2.12 lib/rails/generators/intercom/config/config_generator.rb