rffdb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b46b42ee1876f919030207416134f7cf94b4250a
4
- data.tar.gz: 9c232c54e21b2939b651bfb8c758dff486fbe107
3
+ metadata.gz: 15e3dfa89e73ac4a581282ea7b7cbcc67f463786
4
+ data.tar.gz: 718a382be6454b1abcf2a000c506fefb88d7f834
5
5
  SHA512:
6
- metadata.gz: bbef6842d8e3b86a1317dca7e5a0a5f2ff4453a45abd382210511780ae2d349c1870045f1fae38c31779303572ab4cd7bb8f9e41488bbc567807e4a5fc02389c
7
- data.tar.gz: 6d326d41d2daade93ffe1da82d043fb18385bda30ac80e4605edf0c1377f970ef685fc0522d3ac690eead523e17f92bb8464fb34204242c2fff7c4fcfd548b8f
6
+ metadata.gz: b62bc3138cfb47330c901c8dc380e7f776c7ff7fb93bff8898832953b0a3951af12802b24f7b3b6dafec1f10d009ea14d0c0f323cc2c0d618a44e754ca4e17ba
7
+ data.tar.gz: e2e86990656d89f1eaf3db4596a79f5b732dac3d53be1b54ca5dbc2a03a662a55bc5ba22315d24ffd7b0fffd2d40c82f1a9a38253022f502146b7a13331cdca8
@@ -205,7 +205,7 @@ module RubyFFDB
205
205
  def self.where(attribute, value, comparison_method = '==')
206
206
  if comparison_method.to_s == '==' && indexed_column?(attribute)
207
207
  DocumentCollection.new(
208
- storage.index(self, attribute).get(value).collect { |did| load(did) },
208
+ storage.index_lookup(self, attribute, value).collect { |did| load(did) },
209
209
  self
210
210
  )
211
211
  else
@@ -260,9 +260,7 @@ module RubyFFDB
260
260
  @read_lock.synchronize do
261
261
  @write_lock.synchronize do
262
262
  if valid
263
- storage.index(self.class, key).delete(@data[key.to_s], id) if indexed_column?(key)
264
263
  @data[key.to_s] = args.last
265
- storage.index(self.class, key).put(args.last, id) if indexed_column?(key)
266
264
  end
267
265
  end
268
266
  end
data/lib/rffdb/index.rb CHANGED
@@ -31,6 +31,7 @@ module RubyFFDB
31
31
  end
32
32
  end
33
33
 
34
+ # Remove a specific Document association with a key
34
35
  def delete(key, value)
35
36
  previous = get(key)
36
37
  GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
@@ -38,16 +39,26 @@ module RubyFFDB
38
39
  end
39
40
  end
40
41
 
42
+ # Remove all associations with a specific key (column data)
41
43
  def truncate(key)
42
44
  GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
43
45
  index.delete(key.to_s)
44
46
  end
45
47
  end
46
48
 
49
+ # All keys (column data) in the index
50
+ # @return [Array] An array of object ids
47
51
  def keys
48
52
  GDBM.open(file_path, 0664, GDBM::READER) do |index|
49
53
  index.keys
50
54
  end
51
55
  end
56
+
57
+ # Evict keys (column data) with no associated Documents
58
+ def prune
59
+ GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
60
+ index.delete_if { |key, value| Marshal.load(value).empty? }
61
+ end
62
+ end
52
63
  end
53
64
  end
@@ -139,5 +139,31 @@ module RubyFFDB
139
139
  @indexes[type] ||= {}
140
140
  @indexes[type][column.to_sym] ||= Index.new(type, column.to_sym)
141
141
  end
142
+
143
+ # Update the index for a column
144
+ # @param type [Document] the document type
145
+ # @param column [String,Symbol] the column / attribute for the index
146
+ # @param object_id [Object] unique identifier for the document
147
+ # @param data [String] column data to be stored
148
+ def self.index_update(type, column, object_id, data)
149
+ i = index(type, column)
150
+ # Delete all previous entries in this index
151
+ oldkeys = i.keys.collect { |k| k if i.get(k).include?(object_id) }.compact
152
+ oldkeys.each do |k|
153
+ i.delete(k, object_id)
154
+ end
155
+
156
+ # Add the new indexed version
157
+ i.put(data, object_id)
158
+ end
159
+
160
+ # Query an index for column data
161
+ # @param type [Document] the document type
162
+ # @param column [String,Symbol] the column / attribute for the index
163
+ # @param data [String] column data to use for the lookup
164
+ def self.index_lookup(type, column, data)
165
+ i = index(type, column)
166
+ i.get(data)
167
+ end
142
168
  end
143
169
  end
@@ -11,6 +11,10 @@ module RubyFFDB
11
11
  File.open(path, 'w') do |file|
12
12
  file.puts JSON.dump(data)
13
13
  end
14
+ # Update all indexed columns
15
+ type.structure.collect {|k,v| k if v[:index] }.compact.each do |col|
16
+ index_update(type, col, object_id, data[col.to_s])
17
+ end
14
18
  cache_store(type, object_id, data)
15
19
  end
16
20
  true
@@ -11,6 +11,9 @@ module RubyFFDB
11
11
  File.open(path, 'w') do |file|
12
12
  file.puts YAML.dump(data)
13
13
  end
14
+ type.structure.collect {|k,v| k if v[:index] }.compact.each do |col|
15
+ index_update(type, col, object_id, data[col.to_s])
16
+ end
14
17
  cache_store(type, object_id, data)
15
18
  end
16
19
  true
data/lib/rffdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RubyFFDB
2
- VERSION = [0, 1, 0].join('.')
2
+ VERSION = [0, 1, 1].join('.')
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rffdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-11 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec