Class: Ruflet::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_desktop_flag_to_binstubsObject



39
40
41
42
43
44
# File 'lib/generators/ruflet/install/install_generator.rb', line 39

def add_desktop_flag_to_binstubs
  return unless desktop_requested?

  install_desktop_flag_bootstrap("bin/rails")
  install_desktop_flag_bootstrap("bin/dev")
end

#add_routesObject



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

def add_routes
  target = File.join(destination_root, "config/routes.rb")
  return unless File.file?(target)

  route = Ruflet::Rails::InstallSupport.route_snippet(entrypoint: entrypoint_path)
  source = File.read(target)
  return if source.include?(route)

  insert_into_file target, "  #{route}\n", after: /Rails\.application\.routes\.draw do\s*\n/
end

#create_app_entrypointObject



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

def create_app_entrypoint
  target = File.join(destination_root, entrypoint_path)
  return if File.exist?(target)

  create_file target, Ruflet::Rails::InstallSupport.default_app_template(app_title: app_name)
end

#create_ruflet_yamlObject



21
22
23
24
25
26
# File 'lib/generators/ruflet/install/install_generator.rb', line 21

def create_ruflet_yaml
  target = File.join(destination_root, "ruflet.yaml")
  return if File.exist?(target)

  create_file target, Ruflet::Rails::InstallSupport.default_ruflet_yaml(app_name: app_name)
end

#download_prebuilt_clientObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/ruflet/install/install_generator.rb', line 46

def download_prebuilt_client
  client = requested_client
  return if client == "none"

  require "ruflet/cli"
  exit_code = Dir.chdir(destination_root) do
    Ruflet::CLI.command_update([client])
  end
  unless exit_code.to_i.zero?
    @client_download_failed = true
    say_status(:warn, "Ruflet client download failed; install files were generated and build/update steps are printed below", :yellow)
  end
rescue StandardError => e
  @client_download_failed = true
  say_status(:warn, "Ruflet client download failed: #{e.class}: #{e.message}", :yellow)
end


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

def print_install_status
  Ruflet::Rails::InstallSupport.install_next_steps(
    target: install_target,
    entrypoint: entrypoint_path,
    client: requested_client
  ).each { |line| say line }
end