Class: HotCatch::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_hot_catch_configObject



32
33
34
35
36
37
# File 'lib/generators/hot_catch/install_generator.rb', line 32

def add_hot_catch_config
  create_file "config/hot_catch_config.json" do
    "/* http://[url] */
{\"url\":\"[your_server_url]\"}"
  end
end

#add_initialize_file_for_sender_logsObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/hot_catch/install_generator.rb', line 39

def add_initialize_file_for_sender_logs
  create_file "config/initializers/hot_catch_sender_logs.rb" do
    "require 'sidekiq-cron'\n" +
    "Rails.application.config.sender_logs = HotCatch::MakeHttpsRequest.new\n" +
    "Sidekiq::Cron::Job.create(name: 'NginxSystemWorker - every 1min', cron: " +
    "if Sidekiq.server?\n" +
    " '*/1 * * * *', class: 'NginxSystemWorker')\n" +
    "end\n"
  end
end

#add_rack_loggerObject

include Rails::Generators::Migration



11
12
13
# File 'lib/generators/hot_catch/install_generator.rb', line 11

def add_rack_logger
  copy_file "hot_catch_logger.rb", "config/hot_catch_logger.rb"
end

#change_filesObject



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

def change_files
  insert_into_file "config/application.rb", "\nrequire_relative 'hot_catch_logger'\n",
    :before => "module"

  application "config.middleware.insert_before Rails::Rack::Logger, Rails::Rack::HotCatchLogger\n" +
              "config.middleware.delete Rails::Rack::Logger"

  insert_string = "\n  require 'hot_catch/custom_log_subscribers.rb'" +
                  "\n  config.logger = ActiveSupport::TaggedLogging" +
                  ".new(ActiveSupport::Logger.new('tmp/hot_catch_buf_file'))\n"

  insert_into_file "config/environments/development.rb", insert_string,
    :after => "Rails.application.configure do"
  insert_into_file "config/environments/production.rb",  insert_string,
    :after => "Rails.application.configure do"
end