compostr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a068dc7a5fb8ac1f42f3e552896ad405de2e562a
4
- data.tar.gz: 33a1dd0da6a37e6f75d4d9ac5ccb25a4dda5d672
3
+ metadata.gz: 31dc61ca4c978bbdc7ac6241dd34923dd42cd3c4
4
+ data.tar.gz: 32990bd5afbe8572a18fee1da267047d8bb380eb
5
5
  SHA512:
6
- metadata.gz: b17bb4f85195d2de339720f215e78d024da24ddc4cdedcbe9b698afd811f6805d2394987e5e8f28d4bec10bbe048bad34b0ab75cc05ea7a35abc5332c66c122d
7
- data.tar.gz: 9aeca1916373fa9d1df46535e50ecbe99a60eeb8dfc5b170551d8cc6ab3e6f0ef7798bcc75069fde194f6c390a222014a2f3354d3a83f565e1eee7a1657f81eb
6
+ metadata.gz: 2b6a2023871a90cb57a6a18a905b8cf4d401b65bb7885fb7583d147550d93a40c1491fa05e746fc37412338cfbd274f0937f2dec66c6c85433fd1e548819ade1
7
+ data.tar.gz: d7931358749cda25caadef2a5aae4ce12b81c327eb71dc3661d3c8ebe1da7e254970b8d5fbfcad5ec6e1476f76cdbee33c2b0e614ac7c53bc53715d335c7da17
data/README.md CHANGED
@@ -10,7 +10,7 @@ Compostr is a somewhat weirdly engineered wrapper to decorate ruby classes such
10
10
 
11
11
  It would be fun to discuss on `Compostr`s development history and design decisions, but unfortunately that is out of scope for the time being.
12
12
 
13
- Licensed under the GPLv3+, Copyright 2016, 2017 Felix Wolfsteller.
13
+ Licensed under the GPLv3+, Copyright 2016, 2017, 2018 Felix Wolfsteller.
14
14
 
15
15
  ## Installation
16
16
 
@@ -35,6 +35,8 @@ Or install it yourself as:
35
35
  Define a CPT class like this (you still need Wordpress PHP code!):
36
36
 
37
37
  ```ruby
38
+ require 'compostr'
39
+
38
40
  class ProgrammingLanguage < Compostr::CustomPostType
39
41
  wp_post_type 'programming_language' # `post_type` as known by WP
40
42
  wp_custom_field_single 'awesomeness' # 'meta' field in WP, just one value is queried and set
@@ -44,7 +46,20 @@ end
44
46
 
45
47
  Now `ProgrammingLanguage`s can be queried and posted to your Wordpress installation. Instances of this class will automatically respond to `content`, `id`, `title` and `featured_image_id` (corresponding to the Wordpress `post_content`, `id`, `post_title` and `featured_image_id`).
46
48
 
47
- Compostr comes prepared with `UUID` information of CPT instances, to e.g. distinctlive identify entities across different WP instances where entities might have different `post_id`s..
49
+ ```ruby
50
+ require 'compostr'
51
+
52
+ fooby = ProgrammingLanguage.new title: 'Fooby',
53
+ content: 'Easy to learn language',
54
+ awesomeness: '3',
55
+ further_links: ['foo://by', 'foo://byebye']
56
+ # Reading this I agree the API is awkward
57
+ Compostr::Syncer.new(nil).merge_push fooby, nil
58
+ ```
59
+
60
+ Compostr comes prepared with `UUID` information of CPT instances, to e.g. distinctively identify entities across different WP instances where entities might have different `post_id`s.
61
+
62
+ There are some tests implemented, which illustrate further usage.
48
63
 
49
64
  ### Configuration
50
65
 
@@ -61,15 +76,15 @@ Global configuration is given in `compostr.conf`, where connection information t
61
76
 
62
77
  Although logging should not be a main Compostr concern, it was helpful to include some handy helpers.
63
78
 
64
- Use Compostr::logger if you want to feed Compostrs logs into your main applications log or redirect them somewhere.
79
+ Use `Compostr::logger` if you want to feed Compostrs logs into your main applications log or redirect them somewhere.
65
80
 
66
81
  To mixin `info`, `warn` and other logging functions into your class/module do an `include Compostr::Logging`.
67
82
 
68
- To make Compostr-logs use your logger, set it like this: `Compostr::logger = <mylogger`.
83
+ To make Compostr-logs use your logger, set it like this: `Compostr::logger = mylogger`.
69
84
 
70
85
  ### EntityCache
71
86
 
72
- Until you provide some Wordpress PHP code to query custom post types via their Custom (meta) Fields, to query and work with CPTs, all data will be read into memory using `Compostr::EntityCache`.
87
+ Until you provide some Wordpress PHP code to query custom post types via their Custom ("meta") Fields, to query and work with CPTs, all data will be read into memory using `Compostr::EntityCache`.
73
88
 
74
89
  ### Syncer
75
90
 
@@ -89,6 +104,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
89
104
 
90
105
  ## Contributing
91
106
 
92
- Bug reports and pull requests are welcome on GitHub at https://github.com/ecovillage/compostr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ecovillage/compostr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.
93
108
 
94
109
  That said, just drop me a line.
data/compostr.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["felix.wolfsteller@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Ease interaction with Custom Post Types of a Wordpress installation.}
13
- spec.description = %q{One way to ask a wordpress installation about specific custom post type instances and tell it about them.}
13
+ spec.description = %q{Compostr provides one way to ask a wordpress installation about specific custom post type instances and tell it about them.}
14
14
  spec.homepage = 'https://github.com/ecovillage/compostr'
15
15
  spec.licenses = ['GPL-3.0+']
16
16
 
@@ -33,4 +33,11 @@ module Compostr
33
33
  def key; nil; end
34
34
  def value; nil; end
35
35
  end
36
+
37
+ # Shortcut to mark fields for deletion.
38
+ class DeleteCustomFieldValue < CustomFieldValue
39
+ def initialize(id)
40
+ super(id, nil, nil)
41
+ end
42
+ end
36
43
  end
@@ -4,7 +4,8 @@ module Compostr
4
4
  #
5
5
  # Besides the post_id, title, content and featured_image (id) that
6
6
  # define a post, the CustomPostType likely will own custom field
7
- # values. These are specified with wp_custom_field_single and wp_custom_field_multi (depending on their type).
7
+ # values. These are specified with wp_custom_field_single and
8
+ # wp_custom_field_multi (depending on their type).
8
9
  #
9
10
  # To loop over the fields, use @fields and @multi_fields.
10
11
  class CustomPostType
@@ -116,9 +117,9 @@ module Compostr
116
117
  # strip ?
117
118
  @title = v
118
119
  elsif k == :content
119
- @content = v
120
+ self.content= v
120
121
  elsif k == :post_id
121
- @post_id = v
122
+ self.post_id= v
122
123
  elsif k == :featured_image_id
123
124
  @featured_image_id = v
124
125
  # Better: has_custom_field?
@@ -354,7 +355,7 @@ module Compostr
354
355
  end
355
356
  # Multi-Fields exclusive to the other.
356
357
  (other_cpt_object.multi_fields.keys - @multi_fields.keys).each do |f|
357
- diff_fields[f] = [nil, other_cpt_object.multi_fields[f].value]
358
+ diff_fields[f] = [nil, other_cpt_object.multi_fields[f].map(&:value)]
358
359
  end
359
360
  # Mutual Multi-fields
360
361
  (@multi_fields.keys | other_cpt_object.multi_fields.keys).each do |f|
@@ -1,4 +1,10 @@
1
1
  module Compostr
2
+ # An EntityCache stores a wordpress response to the query of
3
+ # a Custom Post Type. All is done in memory, which is pretty nasty.
4
+ # The EntityCache creates two indexes (on name and uuid attribute/custom
5
+ # field) which are created on-the fly when accessed.
6
+ # Contrary to what its name suggests, the EntityCache does not store
7
+ # instances of the given CustomPostType subclass, but the wordpress response.
2
8
  class EntityCache
3
9
  attr_accessor :cpt_class, :name_id_map, :uuid_id_map
4
10
  attr_accessor :full_data
@@ -85,8 +91,11 @@ module Compostr
85
91
  private
86
92
 
87
93
  def get_all_posts
88
- Compostr::wp.getPosts blog_id: 0,
94
+ Compostr::logger.debug "Get all #{@cpt_class.post_type} posts"
95
+ all_posts = Compostr::wp.getPosts blog_id: 0,
89
96
  filter: { post_type: @cpt_class.post_type, number: 100_000 }
97
+ Compostr::logger.debug "Got all #{all_posts.count} #{@cpt_class.post_type} posts"
98
+ return all_posts
90
99
  end
91
100
 
92
101
  def uuid_pid_map
@@ -7,7 +7,7 @@ module Compostr
7
7
 
8
8
  def initialize image_store, media_cache
9
9
  if !image_store
10
- Compostr.logger.warn "ImageUploader will not uploading anything (no image store specified)."
10
+ Compostr.logger.warn "ImageUploader will not upload anything (no image store specified)."
11
11
  end
12
12
  @image_store = image_store
13
13
  @media_cache = media_cache
@@ -7,11 +7,13 @@ module Compostr
7
7
  attr_accessor :image_uploader
8
8
  attr_accessor :synced_uuids
9
9
  attr_accessor :updated_uuids
10
+ attr_accessor :force
10
11
 
11
- def initialize image_uploader
12
+ def initialize image_uploader, force=false
12
13
  @image_uploader = image_uploader
13
14
  @synced_uuids = []
14
15
  @updated_uuids = []
16
+ @force = force
15
17
  end
16
18
 
17
19
  # Updates or creates Custom Post Types Posts.
@@ -1,3 +1,3 @@
1
1
  module Compostr
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compostr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Wolfsteller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2018-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypress
@@ -108,8 +108,8 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: One way to ask a wordpress installation about specific custom post type
112
- instances and tell it about them.
111
+ description: Compostr provides one way to ask a wordpress installation about specific
112
+ custom post type instances and tell it about them.
113
113
  email:
114
114
  - felix.wolfsteller@gmail.com
115
115
  executables: []
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  requirements: []
161
161
  rubyforge_project:
162
- rubygems_version: 2.5.1
162
+ rubygems_version: 2.6.12
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: Ease interaction with Custom Post Types of a Wordpress installation.