Class: Wpify::Parser
- Inherits:
-
Object
- Object
- Wpify::Parser
- Defined in:
- lib/wpify/parser.rb
Overview
Parses the contents of a wp-config.php file into a Hash reasonably well.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#wpconfig ⇒ Object
readonly
Returns the value of attribute wpconfig.
Class Method Summary collapse
-
.load(*args) ⇒ Object
Loader.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Parser
constructor
Provide a comma separated list or files and a hash of options at the end (not yet used).
-
#parse ⇒ Object
Parse all the files in @files and add the configuration hash to @wpconfig.
Constructor Details
#initialize(*args) ⇒ Parser
Provide a comma separated list or files and a hash of options at the end (not yet used)
15 16 17 18 19 |
# File 'lib/wpify/parser.rb', line 15 def initialize(*args) @options = args.last.kind_of?(Hash) ? args.pop : Hash.new @files = args parse end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
11 12 13 |
# File 'lib/wpify/parser.rb', line 11 def files @files end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/wpify/parser.rb', line 11 def @options end |
#wpconfig ⇒ Object (readonly)
Returns the value of attribute wpconfig.
11 12 13 |
# File 'lib/wpify/parser.rb', line 11 def wpconfig @wpconfig end |
Class Method Details
.load(*args) ⇒ Object
Loader
6 7 8 9 |
# File 'lib/wpify/parser.rb', line 6 def self.load(*args) load = self.new(*args) load.wpconfig end |
Instance Method Details
#parse ⇒ Object
Parse all the files in @files and add the configuration hash to @wpconfig
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wpify/parser.rb', line 23 def parse @wpconfig = Hash.new @files.each do |f| f = File.(f) next if not File.exist?(f) raw = File.open(f).read raw.scan(constant_pattern).each {|c| @wpconfig[c[0].downcase.to_sym] = c[1] } raw.scan(var_pattern).each {|v| @wpconfig[v[0].downcase.to_sym] = v[1] } end @wpconfig end |