Module: Sequelizer

Defined in:
lib/sequelizer.rb,
lib/sequelizer/cli.rb,
lib/sequelizer/options.rb,
lib/sequelizer/version.rb,
lib/sequelizer/env_config.rb,
lib/sequelizer/yaml_config.rb,
lib/sequelizer/options_hash.rb,
lib/sequelizer/connection_maker.rb,
lib/sequelizer/gemfile_modifier.rb

Overview

Include this module in any class where you’d like to quickly establish a Sequel connection to a database.

Defined Under Namespace

Classes: CLI, ConnectionMaker, EnvConfig, GemfileModifier, Options, OptionsHash, YamlConfig

Constant Summary collapse

VERSION =

Version for the gem

"0.1.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionsObject



10
11
12
# File 'lib/sequelizer.rb', line 10

def self.options
  Options.new.to_hash
end

Instance Method Details

#db(options = {}) ⇒ Object

Instantiates and memoizes a database connection. The db method instantiates the connection on the first call and then memoizes itself so only a single connection is used on repeated calls

options

an optional set of database connection options. If no options are provided, options are read from config/sequelizer.yml or from .env or from environment variables.



21
22
23
# File 'lib/sequelizer.rb', line 21

def db(options = {})
  @_sequelizer_db ||= new_db(options)
end

#find_cached(options) ⇒ Object



36
37
38
39
# File 'lib/sequelizer.rb', line 36

def find_cached(options)
  @cache ||= {}
  @cache[options]
end

#new_db(options = {}) ⇒ Object

Instantiates and returns a new database connection on each call.

options

an optional set of database connection options. If no options are provided, options are read from config/sequelizer.yml or from .env or from environment variables.



30
31
32
33
34
# File 'lib/sequelizer.rb', line 30

def new_db(options = {})
  cached = find_cached(options)
  return cached if cached && !options[:force_new]
  @cache[options] = ConnectionMaker.new(options).connection
end