Class: Sequelizer::Options

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

Overview

Options

Manages database connection options from multiple configuration sources. This class is responsible for:

  • Loading configuration from various sources (YAML files, environment variables, .env files)

  • Applying precedence rules for configuration sources

  • Processing adapter-specific options (especially PostgreSQL schema handling)

  • Managing Sequel extensions

  • Setting up after_connect callbacks

Configuration Sources (in order of precedence)

  1. Passed options (highest priority)

  2. .env file

  3. Environment variables

  4. config/database.yml

  5. ~/.config/sequelizer/database.yml (lowest priority)

Examples:

Basic usage

options = Options.new(adapter: 'postgres', host: 'localhost')
hash = options.to_hash

Loading from environment

ENV['SEQUELIZER_ADAPTER'] = 'postgres'
options = Options.new
puts options.adapter  # => 'postgres'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Options

Creates a new Options instance, processing configuration from multiple sources.

Parameters:

  • options (Hash, String, nil) (defaults to: nil)

    database connection options or connection URL If a Hash is provided, it will be merged with configuration from other sources. If a String is provided, it’s treated as a database URL and returned as-is. If nil, configuration is loaded entirely from external sources.



46
47
48
49
# File 'lib/sequelizer/options.rb', line 46

def initialize(options = nil)
  opts = fix_options(options)
  @options, @extensions = filter_extensions(opts)
end

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



38
39
40
# File 'lib/sequelizer/options.rb', line 38

def extensions
  @extensions
end

Instance Method Details

#to_hashHash

Returns the processed options as a hash suitable for Sequel.connect.

Returns:

  • (Hash)

    the database connection options



54
55
56
# File 'lib/sequelizer/options.rb', line 54

def to_hash
  @options
end