class Sequelizer::YamlConfig

Attributes

config_file_path[R]

Public Class Methods

local_config() click to toggle source
# File lib/sequelizer/yaml_config.rb, line 10
def local_config
  new
end
new(config_file_path = nil) click to toggle source
# 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").expand_path
end
user_config() click to toggle source
# File lib/sequelizer/yaml_config.rb, line 14
def user_config
  new(user_config_path)
end
user_config_path() click to toggle source
# 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

Public Instance Methods

environment() click to toggle source

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'

# File lib/sequelizer/yaml_config.rb, line 44
def environment
  ENV['SEQUELIZER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
end
options() click to toggle source

Returns a set of options pulled from config/database.yml or nil if config/database.yml doesn't exist

# File lib/sequelizer/yaml_config.rb, line 30
def options
  return {} unless config_file_path.exist?
  config[environment] || config
end

Private Instance Methods

config() click to toggle source

The config as read from config/database.yml

# File lib/sequelizer/yaml_config.rb, line 51
def config
  @config ||= Psych.load(ERB.new(File.read(config_file_path)).result)
end