Class: AmocrmRails::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#generate_installObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/amocrm_rails/install/install_generator.rb', line 9

def generate_install
  with = options['with']
  copy_file 'amocrm_token.yml', 'config/amocrm_token.yml'

  if with.to_s.downcase == 'devise'
    copy_file 'devise/app/controllers/amocrm_controller.rb', 'app/controllers/amocrm_controller.rb'
    copy_file 'devise/app/views/amocrm/code.html.erb', 'app/views/amocrm/code.html.erb'
    copy_file 'devise/app/views/amocrm/link.html.erb', 'app/views/amocrm/link.html.erb'
    copy_file 'devise/config/amocrm.yml', 'config/amocrm.yml'
    copy_file 'devise/config/initializers/amocrm.rb', 'config/initializers/amocrm.rb'
    route "get '/amocrm' => 'amocrm#code'"
    route "get '/amocrm/link' => 'amocrm#link'"
    route "post '/amocrm/webhook/:name' => 'amocrm#webhook'"

    inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
      include AmocrmRails::Concern
      before_action :update_auth_code
    RUBY
    end
  else
    copy_file 'amocrm.rb', 'config/initializers/amocrm.rb'
    copy_file 'amocrm.yml', 'config/amocrm.yml'
  end
end