hashy_db 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hashy_db/data_store.rb +6 -0
- data/lib/hashy_db/version.rb +1 -1
- data/spec/lib/data_store_spec.rb +8 -0
- metadata +1 -1
data/lib/hashy_db/data_store.rb
CHANGED
@@ -31,6 +31,12 @@ module HashyDb
|
|
31
31
|
collection[index] = hash
|
32
32
|
end
|
33
33
|
|
34
|
+
def delete_by_params(collection_name, params)
|
35
|
+
find_all(collection_name).reject! do |record|
|
36
|
+
params.all?{|k,v| record[k] == v }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
34
40
|
def update_field_with_value(collection_name, primary_key_value, field_name, new_value)
|
35
41
|
find(collection_name, :id, primary_key_value)[field_name] = new_value
|
36
42
|
end
|
data/lib/hashy_db/version.rb
CHANGED
data/spec/lib/data_store_spec.rb
CHANGED
@@ -44,6 +44,14 @@ describe HashyDb::DataStore do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'can delete records that match a given set of fields' do
|
48
|
+
params = { id: 1, field_1: 'value 1' }
|
49
|
+
|
50
|
+
subject.delete_by_params(:some_collection, params)
|
51
|
+
|
52
|
+
subject.find_all(:some_collection).should == [data2, data3]
|
53
|
+
end
|
54
|
+
|
47
55
|
it 'can write and read data to and from a collection' do
|
48
56
|
data4 = {id: 3, field_1: 'value 3', field_2: 9, shared_between_1_and_2: 'not the same as 1 and 2', :some_array => [1, 7]}
|
49
57
|
|