Class: Gcloud::Datastore::Commit
- Inherits:
-
Object
- Object
- Gcloud::Datastore::Commit
- Defined in:
- lib/gcloud/datastore/commit.rb
Overview
# Commit
Object yielded from ‘commit` methods to allow multiple changes to be made in a single commit.
See Dataset#commit and Transaction#commit.
Instance Method Summary collapse
- #auto_id_entities ⇒ Object
-
#delete(*entities_or_keys) ⇒ Object
Remove entities from the Datastore.
- #entities ⇒ Object
-
#initialize ⇒ Commit
constructor
A new instance of Commit.
- #mutation ⇒ Object
-
#save(*entities) ⇒ Object
Saves entities to the Datastore.
Constructor Details
#initialize ⇒ Commit
Returns a new instance of Commit.
36 37 38 39 40 |
# File 'lib/gcloud/datastore/commit.rb', line 36 def initialize @shared_entities = [] @shared_auto_ids = [] @shared_deletes = [] end |
Instance Method Details
#auto_id_entities ⇒ Object
95 96 97 |
# File 'lib/gcloud/datastore/commit.rb', line 95 def auto_id_entities shared_auto_ids end |
#delete(*entities_or_keys) ⇒ Object
Remove entities from the Datastore.
76 77 78 79 80 81 82 83 |
# File 'lib/gcloud/datastore/commit.rb', line 76 def delete *entities_or_keys keys = entities_or_keys.map do |e_or_k| e_or_k.respond_to?(:key) ? e_or_k.key : e_or_k end keys.each { |k| shared_deletes << k } # Do not delete yet true end |
#entities ⇒ Object
100 101 102 |
# File 'lib/gcloud/datastore/commit.rb', line 100 def entities shared_entities end |
#mutation ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/gcloud/datastore/commit.rb', line 86 def mutation Proto.new_mutation.tap do |m| m.insert_auto_id = shared_auto_ids.map(&:to_proto) m.upsert = shared_upserts.map(&:to_proto) m.delete = shared_deletes.map(&:to_proto) end end |
#save(*entities) ⇒ Object
Saves entities to the Datastore.
54 55 56 57 58 59 60 61 |
# File 'lib/gcloud/datastore/commit.rb', line 54 def save *entities entities.each do |entity| shared_auto_ids << entity if entity.key.incomplete? shared_entities << entity end # Do not save yet entities end |