Class: Pressy::Site
- Inherits:
-
Object
- Object
- Pressy::Site
- Defined in:
- lib/pressy/site.rb
Overview
Site is a high-level interface for working with a WordPress site using Pressy.
Instance Attribute Summary collapse
-
#store ⇒ Store
readonly
The Store that is managing the local storage for this site.
Actions collapse
- #create(params = {}) ⇒ Object
- #create_post(post) ⇒ Object
-
#pull ⇒ Object
Checks for changes on the server and updates the files on disk to match.
-
#push ⇒ Object
Checks for local changes and sends them to the server.
Class Method Summary collapse
Instance Method Summary collapse
-
#client ⇒ Pressy::Client
The client that is being used to interact with the remote WordPress site.
-
#initialize(store) ⇒ Site
constructor
Creates a new Site backed by
store. - #root ⇒ Object
Constructor Details
#initialize(store) ⇒ Site
Creates a new Site backed by store. Uses the configuration
provided by store to create a WordPress client when needed.
12 13 14 |
# File 'lib/pressy/site.rb', line 12 def initialize(store) @store = store end |
Instance Attribute Details
#store ⇒ Store (readonly)
The Store that is managing the local storage for this site.
7 8 9 |
# File 'lib/pressy/site.rb', line 7 def store @store end |
Class Method Details
Instance Method Details
#client ⇒ Pressy::Client
The client that is being used to interact with the remote WordPress site.
18 19 20 |
# File 'lib/pressy/site.rb', line 18 def client @client ||= create_client end |
#create(params = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pressy/site.rb', line 62 def create(params = {}) uri = URI.parse(params.fetch(:url)) site_config = { "host" => uri.host, "username" => params.fetch(:username), "password" => params.fetch(:password) } if uri.path != "" && uri.path != "/" # using File.join for this is sketchy but URI is very bad at joining site_config["path"] = File.join(uri.path, "xmlrpc.php") end new_store = store.create(params[:path] || uri.host, { "site" => site_config }) Pressy::Site.new(new_store) end |
#create_post(post) ⇒ Object
56 57 58 59 60 |
# File 'lib/pressy/site.rb', line 56 def create_post(post) saved_post = client.create_post(post) rendered_post = Pressy::PostRenderer.render(saved_post) store.write(saved_post.id, rendered_post) end |
#pull ⇒ Object
Checks for changes on the server and updates the files on disk to match.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pressy/site.rb', line 29 def pull pull = Pressy::Action::Pull.new( local: fetch_local_posts, server: fetch_server_posts ) pull.changeset.changes.each do |change| change.execute(store) end pull end |
#push ⇒ Object
Checks for local changes and sends them to the server.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pressy/site.rb', line 43 def push push = Pressy::Action::Push.new( local: fetch_local_posts, server: fetch_server_posts ) push.changeset.changes.each do |change| change.execute(store, client) end push end |
#root ⇒ Object
22 23 24 |
# File 'lib/pressy/site.rb', line 22 def root store.root end |