Class: NSFNanoStore

Inherits:
Object
  • Object
show all
Defined in:
lib/nano_store/store_extension.rb

Instance Method Summary collapse

Instance Method Details

#+(object) ⇒ Object



47
48
49
50
51
52
# File 'lib/nano_store/store_extension.rb', line 47

def +(object)
  error_ptr = Pointer.new(:id)
  self.addObject(object, error:error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  self
end

#<<(objects) ⇒ Object

Adding and Removing Objects



36
37
38
39
40
41
42
43
44
45
# File 'lib/nano_store/store_extension.rb', line 36

def <<(objects)
  error_ptr = Pointer.new(:id)
  if objects.is_a?(Array)
    self.addObjectsFromArray(objects, error:error_ptr)
  else
    self.addObject(objects, error:error_ptr)
  end
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  self
end

#changed?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/nano_store/store_extension.rb', line 6

def changed?
  self.hasUnsavedChanges
end

#clearObject

delete all objects from store



76
77
78
79
80
81
# File 'lib/nano_store/store_extension.rb', line 76

def clear
  error_ptr = Pointer.new(:id)
  result = self.removeAllObjectsFromStoreAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#clear_indexObject

Remove all indexes from the document store.



114
115
116
117
118
119
# File 'lib/nano_store/store_extension.rb', line 114

def clear_index
  error_ptr = Pointer.new(:id)
  result = self.clearIndexesAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#closeObject

Open and Close store



16
17
18
19
20
21
# File 'lib/nano_store/store_extension.rb', line 16

def close
  error_ptr = Pointer.new(:id)
  closed = self.closeWithError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  closed
end

#closed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/nano_store/store_extension.rb', line 30

def closed?
  self.isClosed
end

#compactObject

Compact the database file size.



106
107
108
109
110
111
# File 'lib/nano_store/store_extension.rb', line 106

def compact
  error_ptr = Pointer.new(:id)
  result = self.compactStoreAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#count(clazz) ⇒ Object

Count number of this class objects in store



138
139
140
# File 'lib/nano_store/store_extension.rb', line 138

def count(clazz)
  self.countOfObjectsOfClassNamed(clazz.bare_class_name)
end

#delete(objects) ⇒ Object

delete a object or array of objects from the array



55
56
57
58
59
60
61
62
63
64
# File 'lib/nano_store/store_extension.rb', line 55

def delete(objects)
  error_ptr = Pointer.new(:id)
  if objects.is_a?(Array)
    result = self.removeObjectsInArray(objects, error:error_ptr)
  else
    result = self.removeObject(objects, error:error_ptr)
  end
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#delete_keys(keys) ⇒ Object

delete object with keys param: keys - array of key



67
68
69
70
71
72
# File 'lib/nano_store/store_extension.rb', line 67

def delete_keys(keys)
  error_ptr = Pointer.new(:id)
  success = self.store.removeObjectsWithKeysInArray(keys, error: error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#engineObject



2
3
4
# File 'lib/nano_store/store_extension.rb', line 2

def engine
  self.nanoStoreEngine
end

#openObject



23
24
25
26
27
28
# File 'lib/nano_store/store_extension.rb', line 23

def open
  error_ptr = Pointer.new(:id)
  opened = self.openWithError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  opened
end

#rebuild_indexObject

Recreate all indexes from the document store.



122
123
124
125
126
127
# File 'lib/nano_store/store_extension.rb', line 122

def rebuild_index
  error_ptr = Pointer.new(:id)
  result = self.rebuildIndexesAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#saveObject

Saves the uncommitted changes to the document store.



95
96
97
98
99
100
# File 'lib/nano_store/store_extension.rb', line 95

def save
  error_ptr = Pointer.new(:id)
  result = saveStoreAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#save_interval=(interval) ⇒ Object



10
11
12
# File 'lib/nano_store/store_extension.rb', line 10

def save_interval=(interval)
  self.setSaveInterval(interval)
end

#save_store(path, compact = true) ⇒ Object

Makes a copy of the document store to a different location and optionally compacts it to its minimum size.



130
131
132
133
134
135
# File 'lib/nano_store/store_extension.rb', line 130

def save_store(path, compact=true)
  error_ptr = Pointer.new(:id)
  result = self.saveStoreToDirectoryAtPath(path, compactDatabase:compact, error:error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  result
end

#transactionObject

Create a transaction



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/nano_store/store_extension.rb', line 143

def transaction
  error_ptr = Pointer.new(:id)
  beginTransactionAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]

  begin
    yield self
  rescue StandardError => e
    rollbackTransactionAndReturnError(error_ptr)
    raise e
  end
  success = commitTransactionAndReturnError(error_ptr)
  raise NanoStore::NanoStoreError, error_ptr[0].description if error_ptr[0]
  success
end