wpdb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +14 -6
  2. data/README.md +13 -2
  3. data/lib/wpdb/version.rb +1 -1
  4. data/lib/wpdb.rb +13 -16
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c8bd628611a7c320a37ff9fe9cf520ab8e7ce7d0
4
- data.tar.gz: 83c63ae4d845aef8cbf211c664d54d338698b9f4
5
- SHA512:
6
- metadata.gz: 8bcfad9e5d0e7e6878ea0195dfca4b922e4561068666f1d6cc4c05144d144479328f76c33fcb31d58fd1379ebfa9b2df1995e9fc44ba8d65cbeb716896bf0236
7
- data.tar.gz: f9dad422c3faac31c7a751bade7cd156009c4176e180722e9cd6ae8ed08fd9e3732d4a06d443e752888ee77764455d595ac8be63310cd37a10244152e0c983bc
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2FlNmJhMzFjYmY2MGY3NGVhMGRmYWRiMGExZDU3MGFjZWViMzA0MQ==
5
+ data.tar.gz: !binary |-
6
+ ZjIwYjEwMzM4NjZjZjcyMWQ4MTNkYzMwOGY5Y2VlYzE4MGU5OTJmYQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MTFmYWQ0ZGUyOTUyZGI4YzkxN2Y5MDdjYmM2YjIzNjEwNjE3YjA3NmYwODkz
10
+ MmNlMjEyYjJjZGU4YzJjYTc3ZWJmOGQ0ODliYmQxMjc3NTRjMjkyNjRlMDkw
11
+ ZGIzNzk4NmMwZTU4OGFlYjJmZDA2NTViZTJlYmZjODMyNjFkNGU=
12
+ data.tar.gz: !binary |-
13
+ OTJmMWJlMmE5MjJkMjhmNWZmZTEwYmQ5OTJiZWYwYjgwOWIxNWYzM2EyZTQ3
14
+ ZjIzOWNmMTU1NzgxMjE2YTFjZWJjM2VhY2I0MjBjNWU5YzViNGJiODM3YjQx
15
+ ZjVkYWE2ZDI3OGFkZGU0MTU0ZmZkZGQ5OWY0YTcwYWYzZjYwYWE=
data/README.md CHANGED
@@ -3,9 +3,20 @@
3
3
  An Active Record wrapper for the Wordpress Database
4
4
 
5
5
  ```ruby
6
- wp_post = WpPost.posts.last
6
+ require 'active_record'
7
+ require 'wpdb'
8
+
9
+ ActiveRecord::Base.establish_connection(
10
+ :adapter => 'mysql',
11
+ :host => 'localhost',
12
+ :port => 3306,
13
+ :username => 'root',
14
+ :password => '',
15
+ :database => 'your_db_name'
16
+ )
17
+
18
+ wp_post = Wpdb::WpPost.posts.last
7
19
  puts wp_post.attributes
8
- puts wp_post.comments
9
20
  puts wp_post.wp_comments.map(&:attributes)
10
21
  puts wp_post.categories
11
22
  puts wp_post.tags
data/lib/wpdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wpdb
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/wpdb.rb CHANGED
@@ -1,11 +1,6 @@
1
1
  require "wpdb/version"
2
2
 
3
3
  module Wpdb
4
- # wp_post = WpPost.posts.last
5
- # puts wp_post.attributes
6
- # puts wp_post.wp_comments.map(&:attributes)
7
- # puts wp_post.categories
8
- # puts wp_post.tags
9
4
  class WpPost < ActiveRecord::Base
10
5
  has_many :wp_comments, foreign_key: :comment_post_ID
11
6
  has_many :wp_term_relationships, foreign_key: :object_id
@@ -14,12 +9,12 @@ module Wpdb
14
9
  scope :posts, -> { where(post_type: 'post') }
15
10
  scope :published, -> { where(post_status: 'publish')}
16
11
 
17
- def tags
18
- wp_term_taxonomies.tags.map { |wp_term_taxonomy| wp_term_taxonomy.list }.flatten
12
+ def wp_tags
13
+ wp_term_taxonomies.tags.map { |wp_term_taxonomy| wp_term_taxonomy.wp_terms.map(&:to_tag) }.flatten
19
14
  end
20
15
 
21
- def categories
22
- wp_term_taxonomies.categories.map { |wp_term_taxonomy| wp_term_taxonomy.list }.flatten
16
+ def wp_categories
17
+ wp_term_taxonomies.categories.map { |wp_term_taxonomy| wp_term_taxonomy.wp_terms.map(&:to_tag) }.flatten
23
18
  end
24
19
  end
25
20
 
@@ -34,19 +29,21 @@ module Wpdb
34
29
 
35
30
  class WpTermTaxonomy < ActiveRecord::Base
36
31
  self.table_name = 'wp_term_taxonomy'
37
- has_many :wp_terms, foreign_key: :term_id
32
+ self.primary_key = 'term_taxonomy_id'
38
33
  has_many :wp_term_relationships, foreign_key: :term_taxonomy_id
39
34
  has_many :wp_posts, through: :wp_term_relationships
35
+ has_many :wp_terms, foreign_key: :term_id, primary_key: :term_id
40
36
 
41
- scope :tags, -> { where(taxonomy: 'post_tag') }
42
- scope :categories, -> { where(taxonomy: 'category') }
37
+ scope :tags, -> { where(taxonomy: 'post_tag') }
38
+ scope :categories, -> { where(taxonomy: 'category') }
43
39
 
44
- def list
45
- wp_terms.map { |wp_term| { wp_term.slug => wp_term.name } }.flatten
46
- end
47
40
  end
48
41
 
49
42
  class WpTerm < ActiveRecord::Base
50
- belongs_to :wp_term_taxonomy
43
+ belongs_to :wp_term_taxonomy, foreign_key: :term_taxonomy_id
44
+
45
+ def to_tag
46
+ {slug => name}
47
+ end
51
48
  end
52
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wpdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Behan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-04 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
@@ -77,12 +77,12 @@ require_paths:
77
77
  - lib
78
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ! '>='
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []