ampere 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/ampere.gemspec +2 -2
- data/lib/ampere/model.rb +20 -0
- data/spec/models/indices_spec.rb +1 -2
- metadata +19 -19
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/ampere.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ampere"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Max Thom Stahl"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-19"
|
13
13
|
s.description = "An ActiveRecord/Mongoid-esque object model for the Redis key/value data store."
|
14
14
|
s.email = "max@villainousindustri.es"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/ampere/model.rb
CHANGED
@@ -80,6 +80,15 @@ module Ampere
|
|
80
80
|
|
81
81
|
# Saves this record to the database.
|
82
82
|
def save
|
83
|
+
self.class.unique_indices.each do |idx|
|
84
|
+
# For each uniquely-indexed field, look up the index for that field,
|
85
|
+
# and throw an exception if this record's value for that field is in
|
86
|
+
# the index already.
|
87
|
+
if Ampere.connection.hexists("ampere.index.#{self.class.to_s.downcase}.#{idx}", instance_variable_get("@#{idx}")) then
|
88
|
+
raise "Cannot save non-unique value for #{idx}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
83
92
|
# Grab a fresh GUID from Redis by incrementing the "__guid" key
|
84
93
|
if @id.nil? then
|
85
94
|
@id = "#{self.class.to_s.downcase}.#{Ampere.connection.incr('__guid')}"
|
@@ -164,6 +173,7 @@ module Ampere
|
|
164
173
|
@fields ||= []
|
165
174
|
@field_defaults ||= {}
|
166
175
|
@indices ||= []
|
176
|
+
@unique_indices ||= []
|
167
177
|
@field_types ||= {}
|
168
178
|
|
169
179
|
@fields << name
|
@@ -260,13 +270,18 @@ module Ampere
|
|
260
270
|
|
261
271
|
# Defines an index. See the README for more details.
|
262
272
|
def self.index(field_name, options = {})
|
273
|
+
# TODO There has just got to be a better way to handle this.
|
263
274
|
@fields ||= []
|
264
275
|
@field_defaults ||= {}
|
265
276
|
@indices ||= []
|
277
|
+
@unique_indices ||= []
|
266
278
|
@field_types ||= {}
|
279
|
+
|
267
280
|
if field_name.class == String or field_name.class == Symbol then
|
281
|
+
# Singular index
|
268
282
|
raise "Can't index a nonexistent field!" unless @fields.include?(field_name)
|
269
283
|
elsif field_name.class == Array then
|
284
|
+
# Compound index
|
270
285
|
field_name.each{|f| raise "Can't index a nonexistent field!" unless @fields.include?(f)}
|
271
286
|
field_name.sort!
|
272
287
|
else
|
@@ -274,12 +289,17 @@ module Ampere
|
|
274
289
|
end
|
275
290
|
|
276
291
|
@indices << field_name
|
292
|
+
@unique_indices << field_name if options[:unique]
|
277
293
|
end
|
278
294
|
|
279
295
|
def self.indices
|
280
296
|
@indices
|
281
297
|
end
|
282
298
|
|
299
|
+
def self.unique_indices
|
300
|
+
@unique_indices
|
301
|
+
end
|
302
|
+
|
283
303
|
# Finds an array of records which match the given conditions. This method is
|
284
304
|
# much faster when all the fields given are indexed.
|
285
305
|
def self.where(options = {})
|
data/spec/models/indices_spec.rb
CHANGED
@@ -68,8 +68,7 @@ describe "Model indices", :indices => true do
|
|
68
68
|
}).should raise_error
|
69
69
|
end
|
70
70
|
|
71
|
-
it 'should enforce the uniqueness of unique single-field indices' do
|
72
|
-
pending
|
71
|
+
it 'should enforce the uniqueness of unique single-field indices', wip:true do
|
73
72
|
# The student_id_num field of Student is unique. If two Students
|
74
73
|
# with the same student_id_num are stored, the second should not
|
75
74
|
# save successfully, throwing an exception instead.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ampere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70296343880340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70296343880340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &70296343658140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70296343658140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &70296343657240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70296343657240
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70296343656200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70296343656200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70296343655220 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.6.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70296343655220
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70296343654580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70296343654580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70296343653980 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70296343653980
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rdoc
|
93
|
-
requirement: &
|
93
|
+
requirement: &70296343653400 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70296343653400
|
102
102
|
description: An ActiveRecord/Mongoid-esque object model for the Redis key/value data
|
103
103
|
store.
|
104
104
|
email: max@villainousindustri.es
|
@@ -151,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: '0'
|
152
152
|
segments:
|
153
153
|
- 0
|
154
|
-
hash:
|
154
|
+
hash: -723934337440945373
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
none: false
|
157
157
|
requirements:
|