Class: DuodealerApp::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_and_inject_into_omniauth_initializerObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 26

def create_and_inject_into_omniauth_initializer
  unless File.exist? "config/initializers/omniauth.rb"
    copy_file "omniauth.rb", "config/initializers/omniauth.rb"
  end

  inject_into_file(
    "config/initializers/omniauth.rb",
    File.read(File.expand_path(find_in_source_paths("duodealer_provider.rb"))),
    after: "Rails.application.config.middleware.use OmniAuth::Builder do\n"
  )
end

#create_duodealer_app_initializerObject



14
15
16
17
18
19
20
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 14

def create_duodealer_app_initializer
  @application_name = format_array_argument(options["application_name"])
  @scope = format_array_argument(options["scope"])
  @api_version = options["api_version"] || DuodealerAPI::Meta.admin_versions.find(&:latest_supported).handle

  template "duodealer_app.rb", "config/initializers/duodealer_app.rb"
end

#create_embedded_app_layoutObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 38

def create_embedded_app_layout
  return unless embedded_app?

  copy_file "embedded_app.html.erb", "app/views/layouts/embedded_app.html.erb"
  copy_file "_flash_messages.html.erb", "app/views/layouts/_flash_messages.html.erb"

  if DuodealerApp.use_webpacker?
    copy_file("duodealer_app.js", "app/javascript/duodealer_app/duodealer_app.js")
    copy_file("flash_messages.js", "app/javascript/duodealer_app/flash_messages.js")
    copy_file("duodealer_app_index.js", "app/javascript/duodealer_app/index.js")
    append_to_file("app/javascript/packs/application.js", 'require("duodealer_app")')
  else
    copy_file("duodealer_app.js", "app/assets/javascripts/duodealer_app.js")
    copy_file("flash_messages.js", "app/assets/javascripts/flash_messages.js")
  end
end

#create_session_store_initializerObject



22
23
24
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 22

def create_session_store_initializer
  copy_file("session_store.rb", "config/initializers/session_store.rb")
end

#create_user_agent_initializerObject



55
56
57
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 55

def create_user_agent_initializer
  template "user_agent.rb", "config/initializers/user_agent.rb"
end

#insert_hosts_into_development_configObject



63
64
65
66
67
68
69
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 63

def insert_hosts_into_development_config
  inject_into_file(
    "config/environments/development.rb",
    "  config.hosts = (config.hosts rescue []) << /\\h+.ngrok.io/\n",
    after: "Rails.application.configure do\n"
  )
end

#mount_engineObject



59
60
61
# File 'lib/generators/duodealer_app/install/install_generator.rb', line 59

def mount_engine
  route "mount DuodealerApp::Engine, at: '/'"
end