Module: WPDB
- Defined in:
- lib/ruby-wpdb.rb,
lib/ruby-wpdb/links.rb,
lib/ruby-wpdb/posts.rb,
lib/ruby-wpdb/terms.rb,
lib/ruby-wpdb/users.rb,
lib/ruby-wpdb/options.rb,
lib/ruby-wpdb/version.rb,
lib/ruby-wpdb/comments.rb,
lib/ruby-wpdb/gravityforms.rb
Defined Under Namespace
Modules: GravityForms, Termable Classes: Comment, CommentMeta, Link, Option, Post, PostMeta, Term, TermRelationship, TermTaxonomy, User, UserMeta
Constant Summary collapse
- VERSION =
"1.1.1"
Class Attribute Summary collapse
-
.db ⇒ Object
Returns the value of attribute db.
-
.initialized ⇒ Object
Returns the value of attribute initialized.
-
.prefix ⇒ Object
Returns the value of attribute prefix.
-
.user_prefix ⇒ Object
Returns the value of attribute user_prefix.
Class Method Summary collapse
-
.camelize(string) ⇒ Object
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).
-
.from_config(file = nil) ⇒ Object
Given the path to a YAML file, will initialise WPDB using the config files found in that file.
-
.init(uri, prefix = nil, user_prefix = nil) ⇒ Object
Initialises Sequel, sets up some necessary variables (like WordPress’s table prefix), and then includes our models.
-
.underscoreize(string) ⇒ Object
Given a string, will convert it an_underscored_value suitable for use in a Ruby variable name/symbol.
Class Attribute Details
.db ⇒ Object
Returns the value of attribute db.
8 9 10 |
# File 'lib/ruby-wpdb.rb', line 8 def db @db end |
.initialized ⇒ Object
Returns the value of attribute initialized.
8 9 10 |
# File 'lib/ruby-wpdb.rb', line 8 def initialized @initialized end |
.prefix ⇒ Object
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/ruby-wpdb.rb', line 8 def prefix @prefix end |
.user_prefix ⇒ Object
Returns the value of attribute user_prefix.
8 9 10 |
# File 'lib/ruby-wpdb.rb', line 8 def user_prefix @user_prefix end |
Class Method Details
.camelize(string) ⇒ Object
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).
193 194 195 196 197 198 199 |
# File 'lib/ruby-wpdb/gravityforms.rb', line 193 def self.camelize(string) string.gsub(/[^a-z0-9 ]/i, '') .gsub(/^[0-9]+/, '') .split(/\s+/) .map { |t| t.strip.capitalize } .join('') end |
.from_config(file = nil) ⇒ Object
Given the path to a YAML file, will initialise WPDB using the config files found in that file.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby-wpdb.rb', line 12 def from_config(file = nil) file ||= File.dirname(__FILE__) + '/../config.yml' config = YAML::load_file(file) uri = 'mysql2://' uri += "#{config['username']}:#{config['password']}" uri += "@#{config['hostname']}" uri += ":#{config['port']}" if config['port'] uri += "/#{config['database']}" init(uri, config['prefix']) end |
.init(uri, prefix = nil, user_prefix = nil) ⇒ Object
Initialises Sequel, sets up some necessary variables (like WordPress’s table prefix), and then includes our models.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby-wpdb.rb', line 34 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/options' require_relative 'ruby-wpdb/users' require_relative 'ruby-wpdb/terms' require_relative 'ruby-wpdb/posts' require_relative 'ruby-wpdb/comments' require_relative 'ruby-wpdb/links' require_relative 'ruby-wpdb/gravityforms' WPDB.initialized = true end |
.underscoreize(string) ⇒ Object
Given a string, will convert it an_underscored_value suitable for use in a Ruby variable name/symbol.
203 204 205 206 207 |
# File 'lib/ruby-wpdb/gravityforms.rb', line 203 def self.underscoreize(string) string.downcase .gsub(' ', '_') .gsub(/[^a-z0-9_]/, '') end |