Class: SourceMonitor::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_routes_mountObject



17
18
19
20
21
22
# File 'lib/generators/source_monitor/install/install_generator.rb', line 17

def add_routes_mount
  mount_path = normalized_mount_path
  return if engine_already_mounted?(mount_path)

  route %(mount SourceMonitor::Engine, at: "#{mount_path}")
end

#configure_queue_dispatcherObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/generators/source_monitor/install/install_generator.rb', line 70

def configure_queue_dispatcher
  queue_path = File.join(destination_root, "config/queue.yml")

  unless File.exist?(queue_path)
    say_status :skip, "config/queue.yml (file not found — create it or run rails app:update to generate)", :yellow
    return
  end

  parsed = YAML.safe_load(File.read(queue_path), aliases: true) || {}

  if queue_config_has_recurring_schedule?(parsed)
    say_status :skip, "config/queue.yml (recurring_schedule already configured)", :yellow
    return
  end

  add_recurring_schedule_to_dispatchers!(parsed)
  File.write(queue_path, YAML.dump(parsed))
  say_status :append, "config/queue.yml (added recurring_schedule to dispatchers)", :green
end

#configure_recurring_jobsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/source_monitor/install/install_generator.rb', line 36

def configure_recurring_jobs
  recurring_path = "config/recurring.yml"
  destination = File.join(destination_root, recurring_path)

  if recurring_file_has_source_monitor_entries?(destination)
    say_status :skip, "#{recurring_path} (SourceMonitor entries already present)", :yellow
    return
  end

  if File.exist?(destination)
    merge_into_existing_recurring(destination, recurring_path)
  else
    create_recurring_file(destination, recurring_path)
  end
end

#create_initializerObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/source_monitor/install/install_generator.rb', line 24

def create_initializer
  initializer_path = "config/initializers/source_monitor.rb"
  destination = File.join(destination_root, initializer_path)

  if File.exist?(destination)
    say_status :skip, initializer_path, :yellow
    return
  end

  template "source_monitor.rb.tt", initializer_path
end

#patch_procfile_devObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/generators/source_monitor/install/install_generator.rb', line 52

def patch_procfile_dev
  procfile_path = File.join(destination_root, "Procfile.dev")

  if File.exist?(procfile_path)
    content = File.read(procfile_path)
    if content.match?(/^jobs:/)
      say_status :skip, "Procfile.dev (jobs entry already present)", :yellow
      return
    end

    File.open(procfile_path, "a") { |f| f.puts("", PROCFILE_JOBS_ENTRY) }
    say_status :append, "Procfile.dev", :green
  else
    File.write(procfile_path, "web: bin/rails server -p 3000\n#{PROCFILE_JOBS_ENTRY}\n")
    say_status :create, "Procfile.dev", :green
  end
end


90
91
92
93
94
95
96
97
98
99
100
# File 'lib/generators/source_monitor/install/install_generator.rb', line 90

def print_next_steps
  say_status :info,
    "Procfile.dev configured — run bin/dev to start both web server and Solid Queue workers.",
    :green
  say_status :info,
    "Recurring jobs configured in config/recurring.yml — they'll run automatically with bin/dev or bin/jobs.",
    :green
  say_status :info,
    "Next steps: review docs/setup.md for the guided + manual install walkthrough and docs/troubleshooting.md for common fixes.",
    :green
end