hashy_db 2.0.0.pre.3 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hashy_db/interface.rb +20 -13
- data/lib/hashy_db/version.rb +1 -1
- metadata +9 -22
data/lib/hashy_db/interface.rb
CHANGED
@@ -26,11 +26,11 @@ module Mince
|
|
26
26
|
# @param [#to_s] salt any object that responds to #to_s
|
27
27
|
# @return [String] A unique id based on the salt and the current time
|
28
28
|
def self.generate_unique_id(salt)
|
29
|
-
|
29
|
+
PrimaryKey.generate(salt)
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.primary_key
|
33
|
-
|
33
|
+
PrimaryKey.name
|
34
34
|
end
|
35
35
|
|
36
36
|
# Deletes a field from all records in the given collection
|
@@ -78,7 +78,7 @@ module Mince
|
|
78
78
|
# @param [String] field_value the value to update the field to
|
79
79
|
# @return [void] no specific return value
|
80
80
|
def self.update_field_with_value(collection_name, primary_key_value, field_name, new_value)
|
81
|
-
find(collection_name,
|
81
|
+
find(collection_name, primary_key_value)[field_name] = new_value
|
82
82
|
end
|
83
83
|
|
84
84
|
# Increments or decrements the field by the given amount for the record for the given id.
|
@@ -89,7 +89,7 @@ module Mince
|
|
89
89
|
# @param [String] amount the amount to increment or decrement the field by
|
90
90
|
# @return [void] no specific return value
|
91
91
|
def self.increment_field_by_amount(collection_name, primary_key_value, field_name, amount)
|
92
|
-
find(collection_name,
|
92
|
+
find(collection_name, primary_key_value)[field_name] += amount
|
93
93
|
end
|
94
94
|
|
95
95
|
# Gets all records that have the value for a given key.
|
@@ -134,22 +134,20 @@ module Mince
|
|
134
134
|
# Gets a record matching a key and value
|
135
135
|
#
|
136
136
|
# @param [Symbol] collection_name the name of the collection
|
137
|
-
# @param [String] key the key to find a record by
|
138
137
|
# @param [*] value a value the find a record by
|
139
138
|
# @return [Hash] a record that matches the given key and value
|
140
|
-
def self.find(collection_name,
|
141
|
-
find_all(collection_name).find { |x| x[
|
139
|
+
def self.find(collection_name, value)
|
140
|
+
find_all(collection_name).find { |x| x[primary_key] == value }
|
142
141
|
end
|
143
142
|
|
144
143
|
# Pushes a value to a record's key that is an array
|
145
144
|
#
|
146
145
|
# @param [Symbol] collection_name the name of the collection
|
147
|
-
# @param [String] identifying_key the field used to find the record
|
148
146
|
# @param [*] identifying_value the value used to find the record
|
149
147
|
# @param [String] array_key the field to push an array to
|
150
148
|
# @param [*] value_to_push the value to push to the array
|
151
|
-
def self.push_to_array(collection_name,
|
152
|
-
record = find(collection_name,
|
149
|
+
def self.push_to_array(collection_name, identifying_value, array_key, value_to_push)
|
150
|
+
record = find(collection_name, identifying_value)
|
153
151
|
if (record[array_key])
|
154
152
|
record[array_key] << value_to_push
|
155
153
|
else
|
@@ -161,12 +159,11 @@ module Mince
|
|
161
159
|
# Removes a value from a record's key that is an array
|
162
160
|
#
|
163
161
|
# @param [Symbol] collection_name the name of the collection
|
164
|
-
# @param [String] identifying_key the field used to find the record
|
165
162
|
# @param [*] identifying_value the value used to find the record
|
166
163
|
# @param [String] array_key the field to push an array from
|
167
164
|
# @param [*] value_to_remove the value to remove from the array
|
168
|
-
def self.remove_from_array(collection_name,
|
169
|
-
record = find(collection_name,
|
165
|
+
def self.remove_from_array(collection_name, identifying_value, array_key, value_to_pop)
|
166
|
+
record = find(collection_name, identifying_value)
|
170
167
|
record[array_key].reject! { |x| x == value_to_pop }
|
171
168
|
end
|
172
169
|
|
@@ -233,5 +230,15 @@ module Mince
|
|
233
230
|
DataStore.data
|
234
231
|
end
|
235
232
|
end
|
233
|
+
|
234
|
+
module PrimaryKey
|
235
|
+
def self.name
|
236
|
+
Config.primary_key
|
237
|
+
end
|
238
|
+
|
239
|
+
def self.generate(salt)
|
240
|
+
Digest::SHA256.hexdigest("#{Time.now}#{salt}")[0..6]
|
241
|
+
end
|
242
|
+
end
|
236
243
|
end
|
237
244
|
end
|
data/lib/hashy_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashy_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matt Simpson
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
@@ -109,22 +109,6 @@ dependencies:
|
|
109
109
|
- - ~>
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '1.2'
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: mince
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
|
-
requirements:
|
117
|
-
- - '='
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: 2.0.0.pre.2
|
120
|
-
type: :development
|
121
|
-
prerelease: false
|
122
|
-
version_requirements: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
|
-
requirements:
|
125
|
-
- - '='
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: 2.0.0.pre.2
|
128
112
|
- !ruby/object:Gem::Dependency
|
129
113
|
name: rb-fsevent
|
130
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,12 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
161
|
none: false
|
178
162
|
requirements:
|
179
|
-
- - ! '
|
163
|
+
- - ! '>='
|
180
164
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
165
|
+
version: '0'
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
hash: -4209518431244443781
|
182
169
|
requirements: []
|
183
170
|
rubyforge_project: hashy_db
|
184
|
-
rubygems_version: 1.8.
|
171
|
+
rubygems_version: 1.8.25
|
185
172
|
signing_key:
|
186
173
|
specification_version: 3
|
187
174
|
summary: Ruby library to interact with in-memory hash database collections
|