ruby-wpdb 1.1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
1
+ <?php
2
+ /**
3
+ * The base configurations of the WordPress.
4
+ *
5
+ * This file has the following configurations: MySQL settings, Table Prefix,
6
+ * Secret Keys, WordPress Language, and ABSPATH. You can find more information
7
+ * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
8
+ * wp-config.php} Codex page. You can get the MySQL settings from your web host.
9
+ *
10
+ * This file is used by the wp-config.php creation script during the
11
+ * installation. You don't have to use the web site, you can just copy this file
12
+ * to "wp-config.php" and fill in the values.
13
+ *
14
+ * @package WordPress
15
+ */
16
+
17
+ // ** MySQL settings - You can get this info from your web host ** //
18
+ /** The name of the database for WordPress */
19
+ define('DB_NAME', 'database_name_here');
20
+
21
+ /** MySQL database username */
22
+ define('DB_USER', 'username_here');
23
+
24
+ /** MySQL database password */
25
+ define('DB_PASSWORD', 'password_here');
26
+
27
+ /** MySQL hostname */
28
+ define('DB_HOST', 'localhost');
29
+
30
+ /** Database Charset to use in creating database tables. */
31
+ define('DB_CHARSET', 'utf8');
32
+
33
+ /** The Database Collate type. Don't change this if in doubt. */
34
+ define('DB_COLLATE', '');
35
+
36
+ /**#@+
37
+ * Authentication Unique Keys and Salts.
38
+ *
39
+ * Change these to different unique phrases!
40
+ * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
41
+ * 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.
42
+ *
43
+ * @since 2.6.0
44
+ */
45
+ define('AUTH_KEY', 'put your unique phrase here');
46
+ define('SECURE_AUTH_KEY', 'put your unique phrase here');
47
+ define('LOGGED_IN_KEY', 'put your unique phrase here');
48
+ define('NONCE_KEY', 'put your unique phrase here');
49
+ define('AUTH_SALT', 'put your unique phrase here');
50
+ define('SECURE_AUTH_SALT', 'put your unique phrase here');
51
+ define('LOGGED_IN_SALT', 'put your unique phrase here');
52
+ define('NONCE_SALT', 'put your unique phrase here');
53
+
54
+ /**#@-*/
55
+
56
+ /**
57
+ * WordPress Database Table prefix.
58
+ *
59
+ * You can have multiple installations in one database if you give each a unique
60
+ * prefix. Only numbers, letters, and underscores please!
61
+ */
62
+ $table_prefix = 'wp_';
63
+
64
+ /**
65
+ * WordPress Localized Language, defaults to English.
66
+ *
67
+ * Change this to localize WordPress. A corresponding MO file for the chosen
68
+ * language must be installed to wp-content/languages. For example, install
69
+ * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German
70
+ * language support.
71
+ */
72
+ define('WPLANG', '');
73
+
74
+ /**
75
+ * For developers: WordPress debugging mode.
76
+ *
77
+ * Change this to true to enable the display of notices during development.
78
+ * It is strongly recommended that plugin and theme developers use WP_DEBUG
79
+ * in their development environments.
80
+ */
81
+ define('WP_DEBUG', false);
82
+
83
+ /* That's all, stop editing! Happy blogging. */
84
+
85
+ /** Absolute path to the WordPress directory. */
86
+ if ( !defined('ABSPATH') )
87
+ define('ABSPATH', dirname(__FILE__) . '/');
88
+
89
+ /** Sets up WordPress vars and included files. */
90
+ require_once(ABSPATH . 'wp-settings.php');
@@ -0,0 +1,55 @@
1
+ module WPDB
2
+ module Config
3
+ class YAML
4
+ def initialize(file)
5
+ if file.respond_to? :read
6
+ @contents = file.read
7
+ else
8
+ @contents = File.read(file)
9
+ end
10
+
11
+ parse
12
+ end
13
+
14
+ def parse
15
+ @config = ::YAML::load(@contents)
16
+ end
17
+
18
+ def config
19
+ uri = 'mysql2://'
20
+ uri += "#{@config['username']}:#{@config['password']}"
21
+ uri += "@#{@config['hostname']}"
22
+ uri += ":#{@config['port']}" if @config['port']
23
+ uri += "/#{@config['database']}"
24
+
25
+ { uri: uri, prefix: @config['prefix'] }
26
+ end
27
+ end
28
+
29
+ class WPConfig
30
+ def initialize(file)
31
+ if file.respond_to? :read
32
+ @contents = file.read
33
+ else
34
+ @contents = File.read(file)
35
+ end
36
+
37
+ parse
38
+ end
39
+
40
+ def parse
41
+ @config = Hash[@contents.scan(/define\((?:'|")(.+)(?:'|"), *(?:'|")(.+)(?:'|")\)/)]
42
+ @config['DB_PREFIX'] ||= 'wp_'
43
+ end
44
+
45
+ def config
46
+ uri = 'mysql2://'
47
+ uri += "#{@config['DB_USER']}:#{@config['DB_PASSWORD']}"
48
+ uri += "@#{@config['DB_HOST']}"
49
+ uri += "/#{@config['DB_NAME']}"
50
+
51
+ { uri: uri, prefix: @config['DB_PREFIX'] }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module WPDB
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2"
3
3
  end
data/lib/ruby-wpdb.rb CHANGED
@@ -2,6 +2,9 @@ require 'bundler/setup'
2
2
 
3
3
  require 'sequel'
4
4
  require 'pry'
5
+ require 'pathname'
6
+
7
+ require_relative 'ruby-wpdb/config'
5
8
 
6
9
  module WPDB
7
10
  class << self
@@ -11,15 +14,16 @@ module WPDB
11
14
  # config files found in that file.
12
15
  def from_config(file = nil)
13
16
  file ||= File.dirname(__FILE__) + '/../config.yml'
14
- config = YAML::load_file(file)
17
+ file = Pathname(file)
15
18
 
16
- uri = 'mysql2://'
17
- uri += "#{config['username']}:#{config['password']}"
18
- uri += "@#{config['hostname']}"
19
- uri += ":#{config['port']}" if config['port']
20
- uri += "/#{config['database']}"
19
+ case file.extname
20
+ when ".yml"
21
+ config_file = Config::YAML.new(file)
22
+ when ".php"
23
+ config_file = Config::WPConfig.new(file)
24
+ end
21
25
 
22
- init(uri, config['prefix'])
26
+ init(config_file.config[:uri], config_file.config[:prefix])
23
27
  end
24
28
 
25
29
  # Initialises Sequel, sets up some necessary variables (like
@@ -0,0 +1,20 @@
1
+ require_relative 'test_helper'
2
+
3
+ require "open-uri"
4
+
5
+ describe "Config" do
6
+ it "correctly parses the sample wp-config" do
7
+ sample_config = Pathname(__FILE__) + ".." + ".." + "data" + "wp-config-sample.php"
8
+ live_url = "https://raw.githubusercontent.com/WordPress/WordPress/master/wp-config-sample.php"
9
+ open(live_url) do |live|
10
+ File.open(sample_config, "w") do |f|
11
+ f.write live.read
12
+ end
13
+ end
14
+
15
+ config = WPDB::Config::WPConfig.new(sample_config).config
16
+
17
+ assert_equal "mysql2://username_here:password_here@localhost/database_name_here", config[:uri]
18
+ assert_equal "wp_", config[:prefix]
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-wpdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Miller
@@ -150,8 +150,10 @@ files:
150
150
  - README.md
151
151
  - bin/ruby-wpdb
152
152
  - data/query.log
153
+ - data/wp-config-sample.php
153
154
  - lib/ruby-wpdb.rb
154
155
  - lib/ruby-wpdb/comments.rb
156
+ - lib/ruby-wpdb/config.rb
155
157
  - lib/ruby-wpdb/gravityforms.rb
156
158
  - lib/ruby-wpdb/links.rb
157
159
  - lib/ruby-wpdb/options.rb
@@ -160,6 +162,7 @@ files:
160
162
  - lib/ruby-wpdb/users.rb
161
163
  - lib/ruby-wpdb/version.rb
162
164
  - test/comments_test.rb
165
+ - test/config_test.rb
163
166
  - test/gravityforms_test.rb
164
167
  - test/links_test.rb
165
168
  - test/options_test.rb