Module: GdatastoreMapper::Base::ClassMethods

Defined in:
lib/gdatastore_mapper/base.rb

Instance Method Summary collapse

Instance Method Details

#attr_accessor(*vars) ⇒ Object



29
30
31
32
33
# File 'lib/gdatastore_mapper/base.rb', line 29

def attr_accessor(*vars)
  @attributes ||= []
  @attributes.concat vars
  super
end

#attributesObject



35
36
37
38
39
# File 'lib/gdatastore_mapper/base.rb', line 35

def attributes
  @attributes.reject do |attr|
    [:id, :created_at, :updated_at].include? attr
  end
end

#from_entity(entity) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/gdatastore_mapper/base.rb', line 41

def from_entity entity
  record = self.new
  record.id = entity.key.id
  entity.properties.to_hash.each do |name, value|
    record.send "#{name}=", value if record.respond_to? "#{name}="
  end
  record
end