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.



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')).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



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

def local_config
  new
end

.user_configObject



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

def user_config
  new(user_config_path)
end

.user_config_pathObject



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

#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’



48
49
50
# File 'lib/sequelizer/yaml_config.rb', line 48

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



33
34
35
36
37
# File 'lib/sequelizer/yaml_config.rb', line 33

def options
  return {} unless config_file_path.exist?

  config[environment] || config
end