Class: Squongo::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/squongo/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: {}) ⇒ Document

Returns a new instance of Document.



4
5
6
# File 'lib/squongo/document.rb', line 4

def initialize(data: {})
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



2
3
4
# File 'lib/squongo/document.rb', line 2

def data
  @data
end

Class Method Details

.allObject



20
21
22
# File 'lib/squongo/document.rb', line 20

def self.all
  Squongo.connection.db.execute "SELECT * FROM #{table}"
end

.firstObject



12
13
14
# File 'lib/squongo/document.rb', line 12

def self.first
  Squongo.connection.db.execute "SELECT * FROM #{table} ORDER BY id LIMIT 1"
end

.lastObject



16
17
18
# File 'lib/squongo/document.rb', line 16

def self.last
  Squongo.connection.db.execute "SELECT * FROM #{table} ORDER BY id DESC LIMIT 1"
end

.tableObject



28
29
30
# File 'lib/squongo/document.rb', line 28

def self.table
  self.const_get :TABLE
end

Instance Method Details

#saveObject



8
9
10
# File 'lib/squongo/document.rb', line 8

def save
  Squongo.save({ table: table, data: data })
end

#tableObject



24
25
26
# File 'lib/squongo/document.rb', line 24

def table
  self.class.table
end