Class: Sequelizer::YamlConfig
- Inherits:
-
Object
- Object
- Sequelizer::YamlConfig
- Defined in:
- lib/sequelizer/yaml_config.rb
Instance Attribute Summary collapse
-
#config_file_path ⇒ Object
readonly
Returns the value of attribute config_file_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#environment ⇒ Object
The environment to load from database.yml.
-
#initialize(config_file_path = nil) ⇒ YamlConfig
constructor
A new instance of YamlConfig.
-
#options ⇒ Object
Returns a set of options pulled from config/database.yml or
nil
if config/database.yml doesn’t exist.
Constructor Details
#initialize(config_file_path = nil) ⇒ YamlConfig
Returns a new instance of YamlConfig.
24 25 26 |
# File 'lib/sequelizer/yaml_config.rb', line 24 def initialize(config_file_path = nil) @config_file_path = Pathname.new(config_file_path || Pathname.pwd + "config" + "sequelizer.yml"). end |
Instance Attribute Details
#config_file_path ⇒ Object (readonly)
Returns the value of attribute config_file_path.
7 8 9 |
# File 'lib/sequelizer/yaml_config.rb', line 7 def config_file_path @config_file_path end |
Class Method Details
.local_config ⇒ Object
10 11 12 |
# File 'lib/sequelizer/yaml_config.rb', line 10 def local_config new end |
.user_config ⇒ Object
14 15 16 |
# File 'lib/sequelizer/yaml_config.rb', line 14 def user_config new(user_config_path) end |
.user_config_path ⇒ Object
18 19 20 21 |
# File 'lib/sequelizer/yaml_config.rb', line 18 def user_config_path return nil unless ENV['HOME'] Pathname.new(ENV['HOME']) + ".config" + "sequelizer" + "database.yml" end |
Instance Method Details
#environment ⇒ Object
The environment to load from database.yml
Searches the following environment variables in this order:
-
SEQUELIZER_ENV
-
RAILS_ENV
-
RACK_ENV
Lastly, if none of those environment variables are specified, the environment defaults to ‘development’
44 45 46 |
# File 'lib/sequelizer/yaml_config.rb', line 44 def environment ENV['SEQUELIZER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |
#options ⇒ Object
Returns a set of options pulled from config/database.yml or nil
if config/database.yml doesn’t exist
30 31 32 33 |
# File 'lib/sequelizer/yaml_config.rb', line 30 def return {} unless config_file_path.exist? config[environment] || config end |