Class: WPDB::Config::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-wpdb/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ YAML



4
5
6
7
8
9
10
11
12
# File 'lib/ruby-wpdb/config.rb', line 4

def initialize(file)
  if file.respond_to? :read
    @contents = file.read
  else
    @contents = File.read(file)
  end

  parse
end

Instance Method Details

#configObject



18
19
20
21
22
23
24
25
26
# File 'lib/ruby-wpdb/config.rb', line 18

def config
  uri  = 'mysql2://'
  uri += "#{@config['username']}:#{@config['password']}"
  uri += "@#{@config['hostname']}"
  uri += ":#{@config['port']}" if @config['port']
  uri += "/#{@config['database']}"

  { uri: uri, prefix: @config['prefix'] }
end

#parseObject



14
15
16
# File 'lib/ruby-wpdb/config.rb', line 14

def parse
  @config = ::YAML::load(@contents)
end