class Lexicon::Cli::Extension::ProductionExtension

Constants

DATABASE
DATABASE_URL

Public Instance Methods

boot(container) click to toggle source
# File lib/lexicon/cli/extension/production_extension.rb, line 13
def boot(container)
  register_parameters(
    container,
    {
      DATABASE_URL => database_url
    }
  )

  container.add_definition(Lexicon::Common::Production::FileLoader) do
    args(shell: Lexicon::Common::ShellExecutor, database_url: ProductionExtension::DATABASE_URL)
  end
  container.add_definition(Lexicon::Common::Production::DatasourceLoader) do
    args(
      shell: Lexicon::Common::ShellExecutor,
      database_factory: Lexicon::Common::Database::Factory,
      file_loader: Lexicon::Common::Production::FileLoader,
      database_url: ProductionExtension::DATABASE_URL
    )
  end
  container.add_definition(DATABASE)
end
commands() click to toggle source
# File lib/lexicon/cli/extension/production_extension.rb, line 35
def commands
  proc do
    desc 'production', 'Production related commands'
    subcommand 'production', Command::ProductionCommand
  end
end

Private Instance Methods

database_url() click to toggle source
# File lib/lexicon/cli/extension/production_extension.rb, line 44
def database_url
  user = ENV.fetch('PRODUCTION_DATABASE_USER', 'postgres')
  password = ENV.fetch('PRODUCTION_DATABASE_PASSWORD', nil)
  host = ENV.fetch('PRODUCTION_DATABASE_HOST', '127.0.0.1')
  port = ENV.fetch('PRODUCTION_DATABASE_PORT', '5432')
  name = ENV.fetch('PRODUCTION_DATABASE_NAME', 'lexicon')

  credentials = if password.nil?
                  user
                else
                  "#{user}:#{password}"
                end

  "postgres://#{credentials}@#{host}:#{port}/#{name}"
end