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
nilif config/database.yml doesn’t exist.
Constructor Details
#initialize(config_file_path = nil) ⇒ YamlConfig
Returns a new instance of YamlConfig.
27 28 29 |
# File 'lib/sequelizer/yaml_config.rb', line 27 def initialize(config_file_path = nil) @config_file_path = Pathname.new(config_file_path || Pathname.pwd.join('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
11 12 13 |
# File 'lib/sequelizer/yaml_config.rb', line 11 def local_config new end |
.user_config ⇒ Object
15 16 17 |
# File 'lib/sequelizer/yaml_config.rb', line 15 def user_config new(user_config_path) end |
.user_config_path ⇒ Object
19 20 21 22 23 |
# File 'lib/sequelizer/yaml_config.rb', line 19 def user_config_path return nil unless Dir.home Pathname.new(Dir.home).join('.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’
48 49 50 |
# File 'lib/sequelizer/yaml_config.rb', line 48 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
33 34 35 36 37 |
# File 'lib/sequelizer/yaml_config.rb', line 33 def return {} unless config_file_path.exist? config[environment] || config end |