module GdatastoreMapper::Base

Attributes

created_at[RW]
id[RW]
updated_at[RW]

Public Instance Methods

attributes() click to toggle source
# File lib/gdatastore_mapper/base.rb, line 52
def attributes
  self.class.attributes
end
to_entity() click to toggle source
# File lib/gdatastore_mapper/base.rb, line 56
def to_entity
  entity_timestamp
  attributes.each do |attribute|
    @entity[attribute] = self.send attribute if self.send attribute
  end
  @entity
end

Private Instance Methods

entity_timestamp() click to toggle source
# File lib/gdatastore_mapper/base.rb, line 66
def entity_timestamp
  @entity = Google::Cloud::Datastore::Entity.new
  @entity.key = Google::Cloud::Datastore::Key.new self.class.to_s, id
  @entity['created_at'] = id ? self.created_at : Time.zone.now
  @entity['updated_at'] = Time.zone.now
end
id_(model) click to toggle source
# File lib/gdatastore_mapper/base.rb, line 73
def id_ model
  (model.to_s + '_id').to_sym
end