rffdb 0.1.1 → 0.1.2

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: 15e3dfa89e73ac4a581282ea7b7cbcc67f463786
4
- data.tar.gz: 718a382be6454b1abcf2a000c506fefb88d7f834
3
+ metadata.gz: bc4467ccd374f36f1a5793286254b9e0f5e0d7ca
4
+ data.tar.gz: ecd7ed58e3635b2f9ca2494b6dfb69f32f772db8
5
5
  SHA512:
6
- metadata.gz: b62bc3138cfb47330c901c8dc380e7f776c7ff7fb93bff8898832953b0a3951af12802b24f7b3b6dafec1f10d009ea14d0c0f323cc2c0d618a44e754ca4e17ba
7
- data.tar.gz: e2e86990656d89f1eaf3db4596a79f5b732dac3d53be1b54ca5dbc2a03a662a55bc5ba22315d24ffd7b0fffd2d40c82f1a9a38253022f502146b7a13331cdca8
6
+ metadata.gz: d35ee19ff25eefb271ff21df71882056e8a989be0024ab261f63b094cc0943c9e68f0671e09bb6410fb668e0ceecb38f1b2a73492a097ad770b1821a3a72dc83
7
+ data.tar.gz: f8dc378ee8c4e67a9ae4bfb80c4a30db378d65af261e00a96cfdb20006cdfebc1c865dd291a3a15bef2bf87d5a4d253011321d972fd3759c6534de193f1fee42
@@ -202,14 +202,16 @@ module RubyFFDB
202
202
 
203
203
  # Query for Documents based on an attribute
204
204
  # @see DocumentCollection#where
205
- def self.where(attribute, value, comparison_method = '==')
206
- if comparison_method.to_s == '==' && indexed_column?(attribute)
205
+ def self.where(attribute, value, comp_op = '==')
206
+ if indexed_column?(attribute)
207
207
  DocumentCollection.new(
208
- storage.index_lookup(self, attribute, value).collect { |did| load(did) },
208
+ storage.index_lookup(self, attribute, value, comp_op).collect do |did|
209
+ load(did)
210
+ end,
209
211
  self
210
212
  )
211
213
  else
212
- all.where(attribute, value, comparison_method)
214
+ all.where(attribute, value, comp_op)
213
215
  end
214
216
  end
215
217
 
@@ -133,7 +133,11 @@ module RubyFFDB
133
133
  end
134
134
  self.class.new(
135
135
  @list.collect do |item|
136
- item if item.send(attribute).send(comparison_method.to_sym, value)
136
+ if item.send(attribute).nil?
137
+ nil
138
+ else
139
+ item if item.send(attribute).send(comparison_method.to_sym, value)
140
+ end
137
141
  end.compact,
138
142
  @type
139
143
  )
data/lib/rffdb/index.rb CHANGED
@@ -54,10 +54,23 @@ module RubyFFDB
54
54
  end
55
55
  end
56
56
 
57
+ # Complex queries of the index can be done with this method
58
+ # @return [Array] An array of object ids matching the query
59
+ def query(q, operator = '==')
60
+ datum = []
61
+ GDBM.open(file_path, 0664, GDBM::READER) do |index|
62
+ index.each_pair do |key, value|
63
+ datum += Marshal.load(value) if key.send(operator.to_sym, q)
64
+ end
65
+ end
66
+ datum.uniq.compact
67
+ end
68
+
57
69
  # Evict keys (column data) with no associated Documents
58
70
  def prune
59
71
  GDBM.open(file_path, 0664, GDBM::WRCREAT) do |index|
60
72
  index.delete_if { |key, value| Marshal.load(value).empty? }
73
+ index.reorganize # clear up wasted disk space
61
74
  end
62
75
  end
63
76
  end
@@ -161,9 +161,9 @@ module RubyFFDB
161
161
  # @param type [Document] the document type
162
162
  # @param column [String,Symbol] the column / attribute for the index
163
163
  # @param data [String] column data to use for the lookup
164
- def self.index_lookup(type, column, data)
164
+ def self.index_lookup(type, column, data, operator = '==')
165
165
  i = index(type, column)
166
- i.get(data)
166
+ i.query(data, operator)
167
167
  end
168
168
  end
169
169
  end
data/lib/rffdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RubyFFDB
2
- VERSION = [0, 1, 1].join('.')
2
+ VERSION = [0, 1, 2].join('.')
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rffdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy