Class: Watchdocs::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/watchdocs/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_initializer_fileObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/watchdocs/install_generator.rb', line 14

def create_initializer_file
  if !options['app_id'].present? || !options['app_secret'].present?
    raise MissingCredentialsError, "    --app_id or/and --app_secret options is missing\n    Please specify both with credentials from Settings tab of your project.\n    ERROR\n  end\n\n  initializer 'watchdocs.rb' do\n    <<-END.gsub(/^\\s+\\|/, '')\n      |Watchdocs::Rails.configure do |c|\n      |  c.app_id = '\#{options['app_id']}'\n      |  c.app_secret = '\#{options['app_secret']}'\n      |end\n    END\n  end\nend\n".strip_heredoc

#install_with_runtimeObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/generators/watchdocs/install_generator.rb', line 80

def install_with_runtime
  if yes?('Do you want to record your API endpoints in developent environment? [y,n]')
    application(nil, env: 'development') do
      'config.middleware.insert(0, Watchdocs::Rails::Middleware)'
    end
    if yes?('  Do you use Procfile to run your app? [y,n]')
      append_file 'Procfile', 'watchdocs: watchdocs --every 60.seconds'
      puts 'Watchdocs worker added to your Procfile!'.green
    else
      warning = "        |  To make sure we will receive all recorded request please run this worker command with your app:\n        |  -----------------------------\n        |  watchdocs --every 60.seconds\n        |  -----------------------------\n      END\n      puts warning.yellow\n\n    end\n    info = <<-END.gsub(/^\\s+\\|/, '')\n      |  If you would like to enable recording in any other environment (f.e. dev server, staging)\n      |  just add the following line to you 'config/environments/{env}.rb':\n      |  -----------------------------------------------------------\n      |    config.middleware.insert(0, Watchdocs::Rails::Middleware)\n      |  -----------------------------------------------------------\n    END\n    puts info.light_blue\n  end\n  puts 'Setup is completed. Now run your app and make some requests!\n  Check app.watchdocs.io after a minute or so.'.green\nend\n".gsub(/^\s+\|/, '')

#install_with_specsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/watchdocs/install_generator.rb', line 32

def install_with_specs
  if yes?('Do you have any request specs? Would you like to use Watchdocs with them in test environment? [y,n]')
    application(nil, env: 'test') do
      'config.middleware.insert(0, Watchdocs::Rails::Middleware)'
    end
    if yes?('  Do you test with RSpec? [y,n]')
      template 'rspec.rb', 'spec/support/watchdocs.rb'
      begin
        append_file 'spec/rails_helper.rb', "require 'support/watchdocs.rb'"
      rescue Errno::ENOENT
        warning = "          |  You don't have rails_helper.rb, so please add the following line\n          |  to the file where you have your RSpec configuration.\n          |  -------------------------------\n          |  require 'support/watchdocs.rb'\n          |  -------------------------------\n        END\n        puts warning.yellow\n      end\n    elsif yes?('  Ok, maybe you test with a Minitest? [y,n]')\n      begin\n        append_file 'test/test_helper.rb',\n                  'Minitest.after_run { Watchdocs::Rails::Recordings.export }'\n      rescue Errno::ENOENT\n        warning = <<-END.gsub(/^\\s+\\|/, '')\n          |  You don't have test_helper.rb, so please add the following line\n          |  to the file where you have your Minitest configuration.\n          |  ----------------------------------------------------------\n          |  Minitest.after_run { Watchdocs::Rails::Recordings.export }\n          |  ----------------------------------------------------------\n        END\n        puts warning.yellow\n      end\n    else\n      warning = <<-END.gsub(/^\\s+\\|/, '')\n        |  We are sorry, but we don't have auto setup for you testing framework.\n        |  You need to manually add the following line to be executed after all your specs:\n        |  -----------------------------------\n        |  Watchdocs::Rails::Recordings.export\n        |  -----------------------------------\n      END\n      puts warning.yellow\n    end\n    puts 'Watchdocs enabled for test environment!'.green\n\n  end\nend\n".gsub(/^\s+\|/, '')