Sha256: 5b031ef0ae760dc33553b71d77610c8e931e2b0a5078c78ccea8bba9844b6258

Contents?: true

Size: 719 Bytes

Versions: 3

Compression:

Stored size: 719 Bytes

Contents

require "google/cloud"

module GdatastoreMapper
  module Persistence

    def save
      return false if !valid?
      entity = to_entity
      GdatastoreMapper::Session.dataset.save(entity)
      self.id = entity.key.id
      true
    end

    def update attributes
      attributes.each do |name, value|
        send "#{name}=", value if respond_to? "#{name}="
      end
      save
    end

    def destroy
      GdatastoreMapper::Session.dataset.delete \
        Google::Cloud::Datastore::Key.new self.class.to_s, id
    end

    def delete
      GdatastoreMapper::Session.dataset.delete \
        Google::Cloud::Datastore::Key.new self.class.to_s, id
    end

    def persisted?
      id.present?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gdatastore_mapper-0.1.2 lib/gdatastore_mapper/persistence.rb
gdatastore_mapper-0.1.2bata lib/gdatastore_mapper/persistence.rb
gdatastore_mapper-0.1.1 lib/gdatastore_mapper/persistence.rb