Class: AsciiPress::WordPressSyncer
- Inherits:
-
Object
- Object
- AsciiPress::WordPressSyncer
- Defined in:
- lib/ascii_press.rb
Instance Method Summary collapse
-
#initialize(hostname, username, password, post_type, renderer, options = {}) ⇒ WordPressSyncer
constructor
Creates a synchronizer object which can be used to synchronize a set of asciidoc files to WordPress posts.
- #sync(adoc_file_paths, custom_fields = {}) ⇒ Object
Constructor Details
#initialize(hostname, username, password, post_type, renderer, options = {}) ⇒ WordPressSyncer
Creates a synchronizer object which can be used to synchronize a set of asciidoc files to WordPress posts
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ascii_press.rb', line 137 def initialize(hostname, username, password, post_type, renderer, = {}) @hostname = hostname @wp_client = Rubypress::Client.new(host: @hostname, username: username, password: password) @post_type = post_type @logger = [:logger] || AsciiPress.logger @renderer = renderer || Renderer.new @filter_proc = [:filter_proc] || Proc.new { true } @delete_not_found = [:delete_not_found] @generate_tags = [:generate_tags] @options = all_pages = @wp_client.getPosts(filter: {post_type: @post_type, number: 1000}) @all_pages_by_post_name = all_pages.index_by {|post| post['post_name'] } log :info, "Got #{@all_pages_by_post_name.size} pages from the database" end |
Instance Method Details
#sync(adoc_file_paths, custom_fields = {}) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ascii_press.rb', line 155 def sync(adoc_file_paths, custom_fields = {}) synced_post_names = [] adoc_file_paths.each do |adoc_file_path| synced_post_names << sync_file_path(adoc_file_path, custom_fields) end if @delete_not_found (@all_pages_by_post_name.keys - synced_post_names).each do |post_name_to_delete| post_id = @all_pages_by_post_name[post_name_to_delete]['post_id'] log :info, "Deleting missing post_name: #{post_name_to_delete} (post ##{post_id})" (:deletePost, blog_id: @hostname, post_id: post_id) end end end |