class Planetscale::InstallGenerator

Constants

APPLICATION_REQUIRE_REGEX

Public Instance Methods

check_org() click to toggle source
# File lib/generators/planetscale/install_generator.rb, line 17
def check_org
  if options[:organization].empty? && @org.nil?
    puts "Usage: bundle exec rails g planetscale:install --organization ORG_NAME"
    abort
  end

  @org ||= options[:organization]
end
create_planetscale_config() click to toggle source
# File lib/generators/planetscale/install_generator.rb, line 28
    def create_planetscale_config
      create_file "config/planetscale.rb", "PlanetScale.start(org: '#{@org}')\n"
      inject_into_file "config/environment.rb", after: APPLICATION_REQUIRE_REGEX do <<~'RUBY'
        require_relative "planetscale"
      RUBY
      end
    end
print_database_yaml() click to toggle source

todo(nickvanw): When we get rid of DB passwords, this can mostly go away, and we can just return the `DATABSE_URL` that the user should use.

read_config() click to toggle source
# File lib/generators/planetscale/install_generator.rb, line 7
def read_config
  @database = "<db_name>"
  file_path = File.join(Rails.root, PlanetScale::Proxy::PLANETSCALE_FILE)
  return unless File.exist?(file_path)

  data = YAML.safe_load(File.read(file_path))
  @database = data['database']
  @org = data['org']
end