Class: Intercom::Generators::ConfigGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/intercom/config/config_generator.rb

Constant Summary collapse

FALSEY_RESPONSES =
['n', 'no']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



5
6
7
# File 'lib/rails/generators/intercom/config/config_generator.rb', line 5

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#create_config_fileObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rails/generators/intercom/config/config_generator.rb', line 14

def create_config_file
  @app_id = app_id
  @api_secret = api_secret
  @session_duration = session_duration
  @include_for_logged_out_users = false

  introduction = "Intercom will automatically insert its javascript before the closing '</body>'\ntag on every page where it can find a logged-in user. Intercom by default\nlooks for logged-in users, in the controller, via 'current_user' and '@user'.\n\nIs the logged-in user accessible via either 'current_user' or '@user'? [Yn]\n  desc\n\n  print \"\#{introduction.strip} \"\n  default_ok = $stdin.gets.strip.downcase\n\n  if FALSEY_RESPONSES.include?(default_ok)\n    custom_current_user_question = <<-desc\n\nHow do you access the logged-in user in your controllers? This can be\nany Ruby code, e.g. 'current_customer', '@admin', etc.:\n    desc\n\n    print \"\#{custom_current_user_question.rstrip} \"\n    @current_user = $stdin.gets.strip\n  end\n\n  template(\"intercom.rb.erb\", \"config/initializers/intercom.rb\")\nend\n"