Class: Sequelizer::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/sequelizer/cli.rb

Overview

CLI

Command line interface for Sequelizer gem using Thor. Provides commands for:

  • Updating Gemfile with database adapters
  • Initializing .env files with database configuration
  • Displaying current configuration

Examples:

sequelizer update_gemfile
sequelizer init_env --adapter postgres --host localhost
sequelizer config

Instance Method Summary collapse

Instance Method Details

#configObject

Displays the current database configuration and extensions.

This command shows the resolved configuration options that would be used for database connections, including all merged sources and any Sequel extensions that would be loaded.



93
94
95
96
97
# File 'lib/sequelizer/cli.rb', line 93

def config
  opts = Options.new
  pp opts.to_hash
  pp opts.extensions
end

#init_envObject

Creates a .env file with database configuration parameters.

This command generates a .env file with SEQUELIZER_* environment variables based on the provided options. It will not overwrite an existing .env file.

Parameters:

  • options (Hash)

    a customizable set of options

Raises:

  • (SystemExit)

    if .env file already exists



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sequelizer/cli.rb', line 75

def init_env
  if File.exist?('.env')
    puts ".env already exists!  I'm too cowardly to overwrite it!"
    puts "Here's what I would have put in there:"
    puts make_env(options)
    exit(1)
  end
  File.open('.env', 'w') do |file|
    file.puts make_env(options)
  end
end

#update_gemfileObject

Updates the Gemfile to include the appropriate database adapter gem.

This command analyzes your current database configuration and adds or updates the corresponding database adapter gem in your Gemfile. It supports various adapters including PostgreSQL, MySQL, SQLite, and JDBC-based adapters.

Parameters:

  • options (Hash)

    a customizable set of options



33
34
35
# File 'lib/sequelizer/cli.rb', line 33

def update_gemfile
  GemfileModifier.new(options).modify
end