Class: Convergence::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/convergence/config.rb

Defined Under Namespace

Classes: MySQL

Constant Summary collapse

ATTRIBUTES =
%i[adapter database host port username password].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Config

Returns a new instance of Config.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/convergence/config.rb', line 35

def initialize(attributes)
  attributes.each do |k, v|
    next if v.nil?
    next if !ATTRIBUTES.include?(k.to_sym) && !ATTRIBUTES.include?(k.to_s)
    instance_variable_set("@#{k}", v)
  end
  case adapter
  when 'mysql', 'mysql2'
    @mysql = MySQL.new(attributes)
  end
end

Class Method Details

.load(yaml_path) ⇒ Object



47
48
49
50
# File 'lib/convergence/config.rb', line 47

def self.load(yaml_path)
  setting = YAML.safe_load(ERB.new(File.read(yaml_path)).result, aliases: true)
  new(setting)
end