Class: Worktrees::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Worktrees::Generators::MiseFollowUp, Rails::Worktrees::Generators::PumaFollowUp
Defined in:
lib/generators/worktrees/install/install_generator.rb

Overview

Installs the wt wrapper, configuration, and safe database.yml updates. rubocop:disable Metrics/ClassLength

Constant Summary collapse

FILE_ENCODING =
'UTF-8'.freeze
FOLLOW_UP_TEMPLATE =
<<~TEXT.freeze
    ============================================
      rails-worktrees installed successfully! 🚂

      Installed:
  %<installed>s

      Get started:
        $ bin/wt
        $ bin/wt my-feature

      Configure:
        config/initializers/rails_worktrees.rb
  %<notes>s
    ============================================
TEXT

Instance Method Summary collapse

Instance Method Details

#apply_yolo_follow_upsObject



80
81
82
83
84
85
86
# File 'lib/generators/worktrees/install/install_generator.rb', line 80

def apply_yolo_follow_ups
  return unless options[:yolo]

  update_procfile
  update_puma_config
  update_mise_toml
end

#create_bin_wrapperObject



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

def create_bin_wrapper
  template('bin/wt', 'bin/wt')
  chmod('bin/wt', 0o755)
end

#create_browser_wrapperObject



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

def create_browser_wrapper
  return unless install_browser_wrapper?

  template('bin/ob', 'bin/ob')
  chmod('bin/ob', 0o755)
end

#create_initializerObject



70
71
72
# File 'lib/generators/worktrees/install/install_generator.rb', line 70

def create_initializer
  template('rails_worktrees.rb.tt', 'config/initializers/rails_worktrees.rb')
end

#create_procfile_worktree_exampleObject



74
75
76
77
78
# File 'lib/generators/worktrees/install/install_generator.rb', line 74

def create_procfile_worktree_example
  return if options[:yolo]

  template('Procfile.dev.worktree.example.tt', 'Procfile.dev.worktree.example')
end

#show_follow_upObject



108
109
110
# File 'lib/generators/worktrees/install/install_generator.rb', line 108

def show_follow_up
  say(follow_up_message)
end

#update_database_configurationObject



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/generators/worktrees/install/install_generator.rb', line 88

def update_database_configuration
  unless File.exist?(database_config_path)
    say_status(:skip, 'config/database.yml not found', :yellow)
    @database_outcome = :not_found
    return
  end

  result = database_update_result
  @database_outcome = result.changed? ? :updated : :identical
  announce_database_update(result)
end

#verify_installationObject



100
101
102
103
104
105
106
# File 'lib/generators/worktrees/install/install_generator.rb', line 100

def verify_installation
  if git_repo?
    say_status(:ok, 'git repository detected', :green)
  else
    say_status(:warning, 'run inside a git repository for bin/wt to work', :yellow)
  end
end