module SqlMigrations::Config
Configuration module
Public Instance Methods
databases()
click to toggle source
# File lib/sql_migrations/config.rb, line 22 def databases get_config_required(:@databases) end
env()
click to toggle source
# File lib/sql_migrations/config.rb, line 18 def env @env end
load!(config_file, env = nil)
click to toggle source
# File lib/sql_migrations/config.rb, line 10 def load!(config_file, env = nil) @env = (env || ENV['ENV'] || ENV['RAKE_ENV'] || :development).to_sym config = get_config_for_env_from_file(config_file) @databases = config[:databases] @options = config[:options] { databases: @databases, options: @options } end
options()
click to toggle source
# File lib/sql_migrations/config.rb, line 26 def options get_config_optional(:@options) end
Private Instance Methods
get_config_for_env_from_file(file)
click to toggle source
# File lib/sql_migrations/config.rb, line 45 def get_config_for_env_from_file(file) yaml_hash = YAML.load(ERB.new(::File.new(file).read).result) config = symbolize_keys(yaml_hash)[@env] raise LoadError, "No configuration for `#{@env}` environment found !" unless config config end
get_config_optional(config_variable)
click to toggle source
# File lib/sql_migrations/config.rb, line 40 def get_config_optional(config_variable) config_value = instance_variable_get(config_variable) (config_value.nil? || config_value.empty?) ? {} : config_value end
get_config_required(config_variable)
click to toggle source
# File lib/sql_migrations/config.rb, line 32 def get_config_required(config_variable) config_value = instance_variable_get(config_variable) if config_value.nil? || config_value.empty? raise "No configuration for `#{config_variable.to_s[1..-1]}` !" end config_value end
symbolize_keys(hash)
click to toggle source
# File lib/sql_migrations/config.rb, line 52 def symbolize_keys(hash) hash.each_with_object({}) do |(key, value), new_hash| new_key = key.is_a?(String) ? key.to_sym : key new_value = value.is_a?(Hash) ? symbolize_keys(value) : value new_hash[new_key] = new_value end end