Module: GdatastoreMapper::Base::ClassMethods
- Defined in:
- lib/gdatastore_mapper/base.rb
Instance Method Summary collapse
- #attr_accessor(*vars) ⇒ Object
- #attributes ⇒ Object
- #create(params) ⇒ Object
- #from_entity(entity) ⇒ Object
Instance Method Details
#attr_accessor(*vars) ⇒ Object
23 24 25 26 27 |
# File 'lib/gdatastore_mapper/base.rb', line 23 def attr_accessor(*vars) @attributes ||= [] @attributes.concat vars super end |
#attributes ⇒ Object
29 30 31 32 33 |
# File 'lib/gdatastore_mapper/base.rb', line 29 def attributes @attributes.reject do |attr| [:id, :created_at, :updated_at].include? attr end end |
#create(params) ⇒ Object
44 45 46 47 48 |
# File 'lib/gdatastore_mapper/base.rb', line 44 def create params record = self.new params record.save record end |
#from_entity(entity) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/gdatastore_mapper/base.rb', line 35 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 |