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
-
#db(options = {}) ⇒ Object
Instantiates and memoizes a database connection.
- #find_cached(options) ⇒ Object
-
#new_db(options = {}) ⇒ Object
Instantiates and returns a new database connection on each call.
Class Method Details
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( = {}) @_sequelizer_db ||= new_db() end |
#find_cached(options) ⇒ Object
36 37 38 39 |
# File 'lib/sequelizer.rb', line 36 def find_cached() @cache ||= {} @cache[] 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( = {}) cached = find_cached() return cached if cached && ![:force_new] @cache[] = ConnectionMaker.new().connection end |