Class: WPDB::Config::WPConfig
- Inherits:
-
Object
- Object
- WPDB::Config::WPConfig
- Defined in:
- lib/ruby-wpdb/config.rb
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(file) ⇒ WPConfig
constructor
A new instance of WPConfig.
- #parse ⇒ Object
Constructor Details
#initialize(file) ⇒ WPConfig
Returns a new instance of WPConfig.
30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby-wpdb/config.rb', line 30 def initialize(file) if file.respond_to? :read @contents = file.read else @contents = File.read(file) end parse end |
Instance Method Details
#config ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/ruby-wpdb/config.rb', line 45 def config uri = 'mysql2://' uri += "#{@config['DB_USER']}:#{@config['DB_PASSWORD']}" uri += "@#{@config['DB_HOST']}" uri += "/#{@config['DB_NAME']}" { uri: uri, prefix: @config['DB_PREFIX'] } end |
#parse ⇒ Object
40 41 42 43 |
# File 'lib/ruby-wpdb/config.rb', line 40 def parse @config = Hash[@contents.scan(/define\((?:'|")(.+)(?:'|"), *(?:'|")(.+)(?:'|")\)/)] @config['DB_PREFIX'] ||= 'wp_' end |