Class: Sequelizer::YamlConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/sequelizer/yaml_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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").expand_path
end

Instance Attribute Details

#config_file_pathObject (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_configObject



10
11
12
# File 'lib/sequelizer/yaml_config.rb', line 10

def local_config
  new
end

.user_configObject



14
15
16
# File 'lib/sequelizer/yaml_config.rb', line 14

def user_config
  new(user_config_path)
end

.user_config_pathObject



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

#environmentObject

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

#optionsObject

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 options
  return {} unless config_file_path.exist?
  config[environment] || config
end