Class: Pressy::LocalChangeset
- Inherits:
-
Object
- Object
- Pressy::LocalChangeset
- Defined in:
- lib/pressy/changeset/local.rb
Overview
A LocalChangeset holds set of changes to apply to a local Store.
Defined Under Namespace
Classes: AddedPost, DeletedPost, UpdatedPost
Building the Changeset collapse
-
#add_local_post(id, post) ⇒ self
Adds a rendered post from the local store to the changeset.
-
#add_server_post(id, post) ⇒ self
Adds a rendered post from the server to the changeset.
Querying the Changes collapse
-
#changes ⇒ Array<AddedPost, UpdatedPost, DeletedPost>
A list of changes to apply to the store.
-
#has_changes? ⇒ Boolean
Checks if there are differences present in the changeset.
Instance Method Summary collapse
-
#initialize ⇒ LocalChangeset
constructor
Creates a new, empty changeset.
Constructor Details
#initialize ⇒ LocalChangeset
Creates a new, empty changeset.
4 5 6 7 |
# File 'lib/pressy/changeset/local.rb', line 4 def initialize @server_posts = {} @local_posts = {} end |
Instance Method Details
#add_local_post(id, post) ⇒ self
Adds a rendered post from the local store to the changeset.
If the id is nil, the post is a local-only draft and will be ignored.
If no server post is added with the same id, this post will be present in #deleted_posts.
If a server post is added with the same id, the post may be present in #updated_posts if it was changed on the server.
37 38 39 40 41 42 43 |
# File 'lib/pressy/changeset/local.rb', line 37 def add_local_post(id, post) return self unless id @local_posts[id] = post @changes = nil self end |
#add_server_post(id, post) ⇒ self
Adds a rendered post from the server to the changeset.
If no local post is added with the same id, the post will be present in #added_posts.
If a local post is added with the same id, the post may be present in #updated_posts if it was changed on the server.
20 21 22 23 24 |
# File 'lib/pressy/changeset/local.rb', line 20 def add_server_post(id, post) @server_posts[id] = post @changes = nil self end |
#changes ⇒ Array<AddedPost, UpdatedPost, DeletedPost>
Returns a list of changes to apply to the store
56 57 58 |
# File 'lib/pressy/changeset/local.rb', line 56 def changes @changes ||= build_changes end |
#has_changes? ⇒ Boolean
Checks if there are differences present in the changeset.
50 51 52 |
# File 'lib/pressy/changeset/local.rb', line 50 def has_changes? !changes.empty? end |