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.0"
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.
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/database.yml or from .env or from environment variables.
14 15 16 |
# File 'lib/sequelizer.rb', line 14 def db( = {}) @_sequelizer_db ||= new_db() end |
#find_cached(options) ⇒ Object
29 30 31 32 |
# File 'lib/sequelizer.rb', line 29 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/database.yml or from .env or from environment variables.
23 24 25 26 27 |
# File 'lib/sequelizer.rb', line 23 def new_db( = {}) cached = find_cached() return cached if cached && ![:force_new] @cache[] = ConnectionMaker.new().connection end |