wordpress_config_parser 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +136 -0
- data/Rakefile +2 -0
- data/lib/wordpress_config_parser/version.rb +3 -0
- data/lib/wordpress_config_parser/wc_parser.rb +95 -0
- data/lib/wordpress_config_parser.rb +9 -0
- data/make-gem.sh +7 -0
- data/sample_scripts/backup-wordpress-db.rb +64 -0
- data/spec/resources/wp-config.php +94 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/wordpress_config_reader/wc_reader_spec.rb +82 -0
- data/wordpress_config_parser.gemspec +17 -0
- metadata +62 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Keith Bennett
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# WordpressConfigParser
|
2
|
+
|
3
|
+
Reads a Wordpress configuration file (wp-config.php) and
|
4
|
+
makes its define() data values easily accessible.
|
5
|
+
|
6
|
+
This is useful, for example, in the creation of a mysqldump command
|
7
|
+
without having to store config information (especially passwords) in a second place, to avoid
|
8
|
+
wasted effort, risk of stale data, and password compromise.
|
9
|
+
|
10
|
+
The parsing algorithm is extremely primitive, but "works for me".
|
11
|
+
|
12
|
+
The WCParser constructor will handle any of the following as its argument:
|
13
|
+
|
14
|
+
* an array of lines
|
15
|
+
* a filespec of a Wordpress config file
|
16
|
+
* a filespec of a directory containing a Wordpress config file
|
17
|
+
('wp-config.php' is assumed to be the file's name).
|
18
|
+
|
19
|
+
After instantiating a parser, you can access the variables defined
|
20
|
+
in the config file in the following ways:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
|
24
|
+
parser = WCParser.new('/Users/me/public_html/blog')
|
25
|
+
|
26
|
+
db_name = parser.db_name
|
27
|
+
# or
|
28
|
+
db_name = parser['DB_NAME']
|
29
|
+
# or
|
30
|
+
db_name = parser[:db_name]
|
31
|
+
# or
|
32
|
+
db_name = parser.get(:db_name)
|
33
|
+
# or
|
34
|
+
db_name = parser.get('DB_NAME')
|
35
|
+
```
|
36
|
+
|
37
|
+
Here's an example of a possibly useful script that creates a sql backup
|
38
|
+
of multiple blogs on a shared host, adds them to the git repo (of the
|
39
|
+
entire shell account), and pushes them to the origin repo:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
#!/usr/bin/env ruby
|
43
|
+
|
44
|
+
require 'wordpress_config_parser'
|
45
|
+
require 'shellwords'
|
46
|
+
|
47
|
+
|
48
|
+
def run_command(command)
|
49
|
+
puts(command)
|
50
|
+
puts(`#{command}`)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
home = ENV['HOME']
|
55
|
+
output_dir = File.join(home, 'sql-backups')
|
56
|
+
blognames = %w(blog1 blog2)
|
57
|
+
|
58
|
+
|
59
|
+
blognames.each do |blogname|
|
60
|
+
|
61
|
+
blog_dir = File.join(home, 'public_html', blogname)
|
62
|
+
parser = WCParser.new(blog_dir)
|
63
|
+
time_str = Time.now.strftime("%Y_%m_%d__%H%M%S")
|
64
|
+
outfilespec = File.join(output_dir, "#{blogname}-db-backup-#{time_str}.sql")
|
65
|
+
|
66
|
+
user = Shellwords.escape(parser.db_user)
|
67
|
+
password = Shellwords.escape(parser.db_password)
|
68
|
+
host = Shellwords.escape(parser.db_host)
|
69
|
+
name = Shellwords.escape(parser.db_name)
|
70
|
+
|
71
|
+
|
72
|
+
Dir.chdir(home) do # in case you have another .git dir where you are
|
73
|
+
run_command("mysqldump -u#{user} -p#{password} -h#{host} #{name} 2>&1 | tee #{outfilespec}")
|
74
|
+
run_command("git add #{outfilespec} 2>&1")
|
75
|
+
run_command("git commit -m \"Added #{outfilespec}.\"")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
run_command("git push -u origin master")
|
80
|
+
```
|
81
|
+
|
82
|
+
CAUTION:
|
83
|
+
|
84
|
+
It is assumed that the key in the config file is always, and all, upper case.
|
85
|
+
Any key passed to the get and [] methods, or as a method name, will be
|
86
|
+
converted to an upper case string for which to search in the config file.
|
87
|
+
|
88
|
+
If you use the method name approach of reading the value for a key,
|
89
|
+
then a NoMethodError will be raised if the key did not exist in the file.
|
90
|
+
If you don't want that to happen, you can use the get or [] methods instead,
|
91
|
+
as they return nil rather than raising an error. For example:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
value = parser[:db_xyz]
|
95
|
+
# instead of
|
96
|
+
value = parser.db_xyz
|
97
|
+
```
|
98
|
+
|
99
|
+
You can also call has_key? (with either string or symbol) to see if it's there
|
100
|
+
before trying to get it. This function is very fast, and pulls the value into
|
101
|
+
the cache if it wasn't already there, so the subsequent access to get the
|
102
|
+
actual value is very fast.
|
103
|
+
|
104
|
+
It is highly recommended to use Shellwords.escape on any values found
|
105
|
+
in the config file before passing those values to a command line.
|
106
|
+
You wouldn't want someone modifying a value to include "; rm -rf ~"!
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
## Installation
|
113
|
+
|
114
|
+
Add this line to your application's Gemfile:
|
115
|
+
|
116
|
+
gem 'wordpress_config_parser'
|
117
|
+
|
118
|
+
And then execute:
|
119
|
+
|
120
|
+
$ bundle
|
121
|
+
|
122
|
+
Or install it yourself as:
|
123
|
+
|
124
|
+
$ gem install wordpress_config_parser
|
125
|
+
|
126
|
+
## Usage
|
127
|
+
|
128
|
+
TODO: Write usage instructions here
|
129
|
+
|
130
|
+
## Contributing
|
131
|
+
|
132
|
+
1. Fork it
|
133
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
134
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
135
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
136
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
class WCParser
|
2
|
+
|
3
|
+
attr_accessor :lines
|
4
|
+
|
5
|
+
def initialize(filespec_or_array)
|
6
|
+
|
7
|
+
error_message = "WCParser constructor must be passed an array of lines, " +
|
8
|
+
"a config filespec, or a directory name that contains a wp-config.php file."
|
9
|
+
|
10
|
+
case filespec_or_array
|
11
|
+
|
12
|
+
when Array
|
13
|
+
@lines = filespec_or_array
|
14
|
+
|
15
|
+
when String
|
16
|
+
filespec = filespec_or_array
|
17
|
+
unless File.exists?(filespec)
|
18
|
+
raise ArgumentError.new("File/directory '#{filespec}' does not exist. #{error_message}")
|
19
|
+
end
|
20
|
+
|
21
|
+
if File.directory?(filespec)
|
22
|
+
filespec = File.join(filespec, 'wp-config.php')
|
23
|
+
unless File.exists?(filespec)
|
24
|
+
raise ArgumentError.new("File '#{filespec}' does not exist. #{error_message}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@lines = File.readlines(filespec).map(&:chomp)
|
29
|
+
|
30
|
+
else
|
31
|
+
raise ArgumentError.new(error_message)
|
32
|
+
end
|
33
|
+
|
34
|
+
@cache = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
# Ex: define('DB_NAME', 'abcdefgh_0001');
|
38
|
+
def find_def_line(token)
|
39
|
+
search_string = "define('#{token}'"
|
40
|
+
matches = lines.select { |line| line[0...search_string.size] == search_string }
|
41
|
+
matches.empty? ? nil : matches.last # last one wins
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def extract_value_from_line(line)
|
46
|
+
# Ex: define('DB_NAME', 'abcdefgh_0001');
|
47
|
+
# Splitting by ' will leave value as array[3]
|
48
|
+
line.split("'")[3]
|
49
|
+
end
|
50
|
+
|
51
|
+
def get(token)
|
52
|
+
|
53
|
+
hash_key = token.to_s.downcase.to_sym
|
54
|
+
|
55
|
+
if @cache.has_key?(hash_key)
|
56
|
+
value = @cache[hash_key]
|
57
|
+
else
|
58
|
+
config_file_key = token.to_s.upcase
|
59
|
+
line = find_def_line(config_file_key)
|
60
|
+
value = (line.nil? ? nil : extract_value_from_line(line))
|
61
|
+
@cache[hash_key] = value # Note: cache will contain any invalid keys requested
|
62
|
+
end
|
63
|
+
value
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def has_key?(key)
|
68
|
+
!! get(key)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
alias [] get
|
73
|
+
|
74
|
+
# For missing methods, assume the method_name is the name or symbol
|
75
|
+
# of a defined value's key. If the key exists in the config file,
|
76
|
+
# a method is created and that value returned. Otherwise, super's
|
77
|
+
# method_missing will be called.
|
78
|
+
def method_missing(method_name, *method_args)
|
79
|
+
|
80
|
+
value = get(method_name)
|
81
|
+
|
82
|
+
if value.nil?
|
83
|
+
super.method_missing(method_name, *method_args)
|
84
|
+
else
|
85
|
+
instance_eval("""
|
86
|
+
def #{method_name.to_s.downcase}
|
87
|
+
get('#{method_name.to_s.upcase}')
|
88
|
+
end
|
89
|
+
""")
|
90
|
+
end
|
91
|
+
|
92
|
+
value
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/make-gem.sh
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
gem uninstall wordpress_config_parser
|
2
|
+
rm wordpress_config_parser*gem
|
3
|
+
gem build wordpress_config_parser.gemspec
|
4
|
+
gem install wordpress_config_parser*gem
|
5
|
+
|
6
|
+
ruby -e "require 'wordpress_config_parser'; parser = WCParser.new('spec/resources'); puts parser.db_name; puts parser.db_name"
|
7
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# backup-wordpress-db.rb
|
4
|
+
#
|
5
|
+
# Calls mysqldump to create a backup of a MySQL data base
|
6
|
+
# in the form of a .sql file containing the SQL commands
|
7
|
+
# required to reconstruct it.
|
8
|
+
#
|
9
|
+
# Assumptions:
|
10
|
+
#
|
11
|
+
# 1) The directory containing the output (backup) files is in a git repo.
|
12
|
+
#
|
13
|
+
# 2) Either you have .ssh keys set up, or you're willing to
|
14
|
+
# type in your password for the git push.
|
15
|
+
#
|
16
|
+
# 3) You're storing your SQL backup files in ~/sql-backups, and
|
17
|
+
# that directory already exists.
|
18
|
+
#
|
19
|
+
# 4) The blogs are all under the $HOME/public_html directory.
|
20
|
+
#
|
21
|
+
# 5) There are no changes git added when you run this script.
|
22
|
+
# Otherwise, those changes will be included in the commit,
|
23
|
+
# without any commit message to describe them.
|
24
|
+
|
25
|
+
require 'wordpress_config_reader'
|
26
|
+
require 'shellwords'
|
27
|
+
|
28
|
+
if ARGV.empty?
|
29
|
+
puts "Syntax is backup-wordpress.rb blog_dir_name_1 [...blog_dir_name_n]."
|
30
|
+
exit -1
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def run_command(command)
|
35
|
+
puts(command)
|
36
|
+
puts(`#{command}`)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
home = ENV['HOME']
|
41
|
+
output_dir = File.join(home, 'sql-backups')
|
42
|
+
blognames = ARGV
|
43
|
+
|
44
|
+
blognames.each do |blogname|
|
45
|
+
|
46
|
+
blog_dir = File.join(home, 'public_html', blogname)
|
47
|
+
reader = WCReader.new(blog_dir)
|
48
|
+
outfilespec = File.join(output_dir, "#{blogname}-db-backup.sql")
|
49
|
+
|
50
|
+
user = Shellwords.escape(reader.db_user)
|
51
|
+
password = Shellwords.escape(reader.db_password)
|
52
|
+
host = Shellwords.escape(reader.db_host)
|
53
|
+
name = Shellwords.escape(reader.db_name)
|
54
|
+
|
55
|
+
|
56
|
+
Dir.chdir(output_dir) do # make sure we're in the right repo
|
57
|
+
run_command("mysqldump -u#{user} -p#{password} -h#{host} #{name} 2>&1 | tee #{outfilespec}")
|
58
|
+
run_command("git add #{outfilespec} 2>&1")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
run_command("git commit -m \"Updated SQL backups for blogs: #{blognames.join(', ')}.\"")
|
64
|
+
run_command("git push -u origin master")
|
@@ -0,0 +1,94 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
!!! DO NOT MODIFY THIS FILE!!!!
|
4
|
+
!!! FILE CONTENT IS ASSUMED BY UNIT TESTS !!!
|
5
|
+
|
6
|
+
* The base configurations of the WordPress.
|
7
|
+
*
|
8
|
+
* This file has the following configurations: MySQL settings, Table Prefix,
|
9
|
+
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
|
10
|
+
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
|
11
|
+
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
|
12
|
+
*
|
13
|
+
* This file is used by the wp-config.php creation script during the
|
14
|
+
* installation. You don't have to use the web site, you can just copy this file
|
15
|
+
* to "wp-config.php" and fill in the values.
|
16
|
+
*
|
17
|
+
* @package WordPress
|
18
|
+
*/
|
19
|
+
|
20
|
+
// ** MySQL settings - You can get this info from your web host ** //
|
21
|
+
/** The name of the database for WordPress */
|
22
|
+
define('DB_NAME', 'mysite_wrd1');
|
23
|
+
define('DB_NAME', 'mysite_wrd2');
|
24
|
+
|
25
|
+
/** MySQL database username */
|
26
|
+
define('DB_USER', 'mysite_user');
|
27
|
+
|
28
|
+
/** MySQL database password */
|
29
|
+
define('DB_PASSWORD', 'gobbledygook');
|
30
|
+
|
31
|
+
/** MySQL hostname */
|
32
|
+
define('DB_HOST', 'localhost');
|
33
|
+
|
34
|
+
/** Database Charset to use in creating database tables. */
|
35
|
+
define('DB_CHARSET', 'utf8');
|
36
|
+
|
37
|
+
/** The Database Collate type. Don't change this if in doubt. */
|
38
|
+
define('DB_COLLATE', '');
|
39
|
+
|
40
|
+
/**#@+
|
41
|
+
* Authentication Unique Keys and Salts.
|
42
|
+
*
|
43
|
+
* Change these to different unique phrases!
|
44
|
+
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
|
45
|
+
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
|
46
|
+
*
|
47
|
+
* @since 2.6.0
|
48
|
+
*/
|
49
|
+
define('AUTH_KEY', '1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
50
|
+
define('SECURE_AUTH_KEY', '2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
51
|
+
define('LOGGED_IN_KEY', '3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
52
|
+
define('NONCE_KEY', '4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
53
|
+
define('AUTH_SALT', '5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
54
|
+
define('SECURE_AUTH_SALT', '6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
55
|
+
define('LOGGED_IN_SALT', '7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
56
|
+
define('NONCE_SALT', '8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
57
|
+
|
58
|
+
/**#@-*/
|
59
|
+
|
60
|
+
/**
|
61
|
+
* WordPress Database Table prefix.
|
62
|
+
*
|
63
|
+
* You can have multiple installations in one database if you give each a unique
|
64
|
+
* prefix. Only numbers, letters, and underscores please!
|
65
|
+
*/
|
66
|
+
$table_prefix = 'wp_';
|
67
|
+
|
68
|
+
/**
|
69
|
+
* WordPress Localized Language, defaults to English.
|
70
|
+
*
|
71
|
+
* Change this to localize WordPress. A corresponding MO file for the chosen
|
72
|
+
* language must be installed to wp-content/languages. For example, install
|
73
|
+
* de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
|
74
|
+
* language support.
|
75
|
+
*/
|
76
|
+
define('WPLANG', '');
|
77
|
+
|
78
|
+
/**
|
79
|
+
* For developers: WordPress debugging mode.
|
80
|
+
*
|
81
|
+
* Change this to true to enable the display of notices during development.
|
82
|
+
* It is strongly recommended that plugin and theme developers use WP_DEBUG
|
83
|
+
* in their development environments.
|
84
|
+
*/
|
85
|
+
define('WP_DEBUG', false);
|
86
|
+
|
87
|
+
/* That's all, stop editing! Happy blogging. */
|
88
|
+
|
89
|
+
/** Absolute path to the WordPress directory. */
|
90
|
+
if ( !defined('ABSPATH') )
|
91
|
+
define('ABSPATH', dirname(__FILE__) . '/');
|
92
|
+
|
93
|
+
/** Sets up WordPress vars and included files. */
|
94
|
+
require_once(ABSPATH . 'wp-settings.php');
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'wc_parser'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe WCParser do
|
6
|
+
|
7
|
+
|
8
|
+
let(:sample_lines) { %w(abc 789) }
|
9
|
+
let(:sample_dirspec) { File.expand_path(File.join(File.dirname(__FILE__), '..', 'resources')) }
|
10
|
+
let(:sample_filespec) { File.join(sample_dirspec, 'wp-config.php') }
|
11
|
+
let(:sample_parser) { WCParser.new(sample_filespec) }
|
12
|
+
|
13
|
+
it "should initialize correctly when calling create_with_lines" do
|
14
|
+
parser = WCParser.new(sample_lines)
|
15
|
+
parser.lines.should == sample_lines
|
16
|
+
end
|
17
|
+
|
18
|
+
it "parser.lines should be an array when instantiating with a filespec" do
|
19
|
+
sample_parser.lines.should be_a Array
|
20
|
+
end
|
21
|
+
|
22
|
+
it "parser.lines should equal the initial array when calling create_with_filespec" do
|
23
|
+
parser = WCParser.new(sample_filespec)
|
24
|
+
parser.lines.should == File.readlines(sample_filespec).map(&:chomp)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should correctly extract the value from a config line" do
|
28
|
+
config_line = "define('DB_NAME', 'abcdefgh_0001');"
|
29
|
+
sample_parser.extract_value_from_line(config_line).should == 'abcdefgh_0001'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should extract the correct line when > 1 matches are present" do
|
33
|
+
line = sample_parser.find_def_line('DB_NAME')
|
34
|
+
value = sample_parser.extract_value_from_line(line)
|
35
|
+
value.should == 'mysite_wrd2'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "(get) should get the correct value" do
|
39
|
+
sample_parser.get('DB_NAME').should == 'mysite_wrd2'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "[] operator should get the correct value" do
|
43
|
+
sample_parser['DB_NAME'].should == 'mysite_wrd2'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should correctly generate a new method when receiving a property in lower case" do
|
47
|
+
sample_parser.db_name.should == 'mysite_wrd2'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should correctly create a mysqladmin dump command with parameters from the file" do
|
51
|
+
db_name = sample_parser.db_name
|
52
|
+
db_password = sample_parser.db_password
|
53
|
+
db_hostname = sample_parser.db_host
|
54
|
+
db_user = sample_parser.db_user
|
55
|
+
|
56
|
+
# mysqldump -u#{userid} -p#{password} -h#{hostname} #{database_name} 2>&1 > #{outfilespec}`
|
57
|
+
command = "mysqldump -u#{db_user} -p#{db_password} -h#{db_hostname} #{db_name}"
|
58
|
+
expected = "mysqldump -umysite_user -pgobbledygook -hlocalhost mysite_wrd2"
|
59
|
+
command.should == expected
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should correctly return true for has_key?(:db_name) and has_key?('DB_NAME')" do
|
63
|
+
(sample_parser.has_key?(:db_name) && sample_parser.has_key?('DB_NAME')).should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should correctly return false for has_key?(:zyx) and has_key?('ZYX')" do
|
67
|
+
(sample_parser.has_key?(:zyx) || sample_parser.has_key?('ZYX')).should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should throw an ArgumentError if a bad file is provided" do
|
71
|
+
lambda { WCParser.new('/:!@#$%^&') }.should raise_error(ArgumentError)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should throw an ArgumentError if a something other than a string or array is provided" do
|
75
|
+
lambda { WCParser.new(123) }.should raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should throw a NoMethodError if a method is called for which there is no key" do
|
79
|
+
lambda { sample_parser.foo }.should raise_error(NoMethodError)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/wordpress_config_parser/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Keith Bennett"]
|
6
|
+
gem.email = ["keithrbennett@gmail.com"]
|
7
|
+
gem.description = %q{Gets values defined in Wordpress wp-config.php file.}
|
8
|
+
gem.summary = %q{Gets values defined in Wordpress wp-config.php file.}
|
9
|
+
gem.homepage = "https://github.com/keithrbennett/wordpress_config_parser"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "wordpress_config_parser"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = WordpressConfigParser::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordpress_config_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keith Bennett
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Gets values defined in Wordpress wp-config.php file.
|
15
|
+
email:
|
16
|
+
- keithrbennett@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/wordpress_config_parser.rb
|
27
|
+
- lib/wordpress_config_parser/version.rb
|
28
|
+
- lib/wordpress_config_parser/wc_parser.rb
|
29
|
+
- make-gem.sh
|
30
|
+
- sample_scripts/backup-wordpress-db.rb
|
31
|
+
- spec/resources/wp-config.php
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
- spec/wordpress_config_reader/wc_reader_spec.rb
|
34
|
+
- wordpress_config_parser.gemspec
|
35
|
+
homepage: https://github.com/keithrbennett/wordpress_config_parser
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.21
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Gets values defined in Wordpress wp-config.php file.
|
59
|
+
test_files:
|
60
|
+
- spec/resources/wp-config.php
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/wordpress_config_reader/wc_reader_spec.rb
|