module WPDB
Constants
- VERSION
Attributes
db[RW]
initialized[RW]
prefix[RW]
user_prefix[RW]
Public Class Methods
camelize(string)
click to toggle source
Given a string, will convert it to a camel case suitable for use in a Ruby constant (which means no non-alphanumeric characters and no leading numbers).
# File lib/ruby-wpdb/gravityforms.rb, line 200 def self.camelize(string) string.gsub(/[^a-z0-9 ]/i, '') .gsub(/^[0-9]+/, '') .split(/\s+/) .map { |t| t.strip.capitalize } .join('') end
config_file(file = nil)
click to toggle source
# File lib/ruby-wpdb.rb, line 23 def config_file(file = nil) file = Config::AutoDiscover.new.file unless file raise ConfigFileError, "No config file specified, and none found" unless file file = Config::AutoFormat.new(file) raise ConfigFileError, "Unknown config file format for file #{file}" unless file.format file end
from_config(file = nil)
click to toggle source
Given the path to a YAML file, will initialise WPDB
using the config files found in that file.
# File lib/ruby-wpdb.rb, line 17 def from_config(file = nil) config_file = config_file(file) init(config_file.config[:uri], config_file.config[:prefix]) end
init(uri, prefix = nil, user_prefix = nil)
click to toggle source
Initialises Sequel, sets up some necessary variables (like WordPress’s table prefix), and then includes our models.
@param [String] A database connection uri, e.g.
mysql2://user:pass@host:port/dbname
@param [String] The database table prefix used by the install of
WordPress you'll be querying. Defaults to wp_
@param [String] The prefix of the users table; if not specified,
the general database table prefix will be used.
# File lib/ruby-wpdb.rb, line 42 def init(uri, prefix = nil, user_prefix = nil) WPDB.db = Sequel.connect(uri) WPDB.prefix = prefix || 'wp_' WPDB.user_prefix = user_prefix || WPDB.prefix require_relative 'ruby-wpdb/option' require_relative 'ruby-wpdb/user' require_relative 'ruby-wpdb/usermeta' require_relative 'ruby-wpdb/term' require_relative 'ruby-wpdb/term_relationship' require_relative 'ruby-wpdb/term_taxonomy' require_relative 'ruby-wpdb/post' require_relative 'ruby-wpdb/postmeta' require_relative 'ruby-wpdb/comment' require_relative 'ruby-wpdb/commentmeta' require_relative 'ruby-wpdb/link' require_relative 'ruby-wpdb/gravityforms' WPDB.initialized = true end
underscoreize(string)
click to toggle source
Given a string, will convert it an_underscored_value suitable for use in a Ruby variable name/symbol.
# File lib/ruby-wpdb/gravityforms.rb, line 210 def self.underscoreize(string) string.downcase .gsub(/ +/, ' ') .gsub(' ', '_') .gsub(/[^a-z0-9_]/, '') end