blendris 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +0 -1
- data/README.markdown +3 -3
- data/Rakefile +1 -1
- data/blendris.gemspec +3 -3
- data/lib/blendris/accessor.rb +11 -14
- data/lib/blendris/integer.rb +4 -1
- data/lib/blendris/list.rb +10 -1
- data/lib/blendris/model.rb +79 -9
- data/lib/blendris/node.rb +15 -5
- data/lib/blendris/reference.rb +7 -1
- data/lib/blendris/reference_base.rb +5 -1
- data/lib/blendris/reference_set.rb +7 -0
- data/lib/blendris/set.rb +7 -0
- data/lib/blendris/string.rb +2 -0
- data/lib/blendris/types.rb +2 -0
- data/lib/blendris/utils.rb +2 -0
- data/spec/model_spec.rb +38 -0
- data/spec/redis-tools_spec.rb +1 -1
- data/spec/spec_helper.rb +22 -3
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
data/Manifest
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Blendris #
|
2
2
|
|
3
|
-
|
3
|
+
http://github.com/alexmchale/blendris
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -20,13 +20,13 @@ PLEASE DON'T USE IT FOR ANYTHING IMPORTANT YET!!!
|
|
20
20
|
|
21
21
|
# REQUIREMENTS #
|
22
22
|
|
23
|
-
|
23
|
+
Blendris uses the redis RubyGem.
|
24
24
|
|
25
25
|
|
26
26
|
|
27
27
|
# INSTALL #
|
28
28
|
|
29
|
-
|
29
|
+
gem install blendris
|
30
30
|
|
31
31
|
|
32
32
|
|
data/Rakefile
CHANGED
data/blendris.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{blendris}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Alex McHale"]
|
9
9
|
s.cert_chain = ["/Users/amchale/Dropbox/Security/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2010-02-
|
10
|
+
s.date = %q{2010-02-15}
|
11
11
|
s.description = %q{A redis library for Ruby}
|
12
12
|
s.email = %q{alexmchale@gmail.com}
|
13
13
|
s.extra_rdoc_files = ["README.markdown", "lib/blendris.rb", "lib/blendris/accessor.rb", "lib/blendris/errors.rb", "lib/blendris/integer.rb", "lib/blendris/list.rb", "lib/blendris/model.rb", "lib/blendris/node.rb", "lib/blendris/reference.rb", "lib/blendris/reference_base.rb", "lib/blendris/reference_set.rb", "lib/blendris/set.rb", "lib/blendris/string.rb", "lib/blendris/types.rb", "lib/blendris/utils.rb", "tasks/rspec.rake"]
|
14
|
-
s.files = ["History.txt", "Manifest", "PostInstall.txt", "README.markdown", "Rakefile", "autotest/discover.rb", "
|
14
|
+
s.files = ["History.txt", "Manifest", "PostInstall.txt", "README.markdown", "Rakefile", "autotest/discover.rb", "lib/blendris.rb", "lib/blendris/accessor.rb", "lib/blendris/errors.rb", "lib/blendris/integer.rb", "lib/blendris/list.rb", "lib/blendris/model.rb", "lib/blendris/node.rb", "lib/blendris/reference.rb", "lib/blendris/reference_base.rb", "lib/blendris/reference_set.rb", "lib/blendris/set.rb", "lib/blendris/string.rb", "lib/blendris/types.rb", "lib/blendris/utils.rb", "script/console", "script/destroy", "script/generate", "spec/list_spec.rb", "spec/model_spec.rb", "spec/redis-tools_spec.rb", "spec/ref_spec.rb", "spec/set_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "tasks/rspec.rake", "blendris.gemspec"]
|
15
15
|
s.homepage = %q{http://github.com/alexmchale/blendris}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Blendris", "--main", "README.markdown"]
|
17
17
|
s.require_paths = ["lib"]
|
data/lib/blendris/accessor.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# This module serves as a gateway to the Redis library. Any object
|
4
|
+
# that needs to access Redis directly should include it.
|
5
|
+
|
3
6
|
module RedisAccessor
|
4
7
|
|
5
8
|
include Utils
|
@@ -12,10 +15,8 @@ module Blendris
|
|
12
15
|
$_redis_connection ||= Redis.new
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
18
|
+
# Generate a key for the given model class with the given values list.
|
19
|
+
# This is used to determine a new object's key in the Model.create method.
|
19
20
|
def generate_key(klass, values)
|
20
21
|
value_index = 0
|
21
22
|
|
@@ -41,18 +42,14 @@ module Blendris
|
|
41
42
|
end.compact.join(":")
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def self.prefix=(prefix)
|
49
|
-
$_redis_prefix = prefix.to_s
|
45
|
+
# Change which database we're accessing in Redis.
|
46
|
+
def self.database=(index)
|
47
|
+
$_redis_connection = Redis.new(:db => index.to_i)
|
50
48
|
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
50
|
+
# This will delete all keys in the current database. Dangerous!
|
51
|
+
def self.flushdb
|
52
|
+
redis.flushdb
|
56
53
|
end
|
57
54
|
|
58
55
|
end
|
data/lib/blendris/integer.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# RedisInteger is a string-value in Redis wrapped up to make
|
4
|
+
# sure that it is used as an integer.
|
5
|
+
|
3
6
|
class RedisInteger
|
4
7
|
|
5
8
|
include RedisNode
|
@@ -7,7 +10,7 @@ module Blendris
|
|
7
10
|
def self.cast_to_redis(value, options = {})
|
8
11
|
raise TypeError.new("#{value.class.name} is not an integer") unless value.kind_of? Fixnum
|
9
12
|
|
10
|
-
value
|
13
|
+
value.to_s
|
11
14
|
end
|
12
15
|
|
13
16
|
def self.cast_from_redis(value, options = {})
|
data/lib/blendris/list.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# RedisList is a wrapper for the Redis LIST data type.
|
4
|
+
|
3
5
|
class RedisList
|
4
6
|
|
5
7
|
include RedisNode
|
@@ -8,6 +10,7 @@ module Blendris
|
|
8
10
|
def initialize(key, options = {})
|
9
11
|
@key = key.to_s
|
10
12
|
@options = options
|
13
|
+
@on_change = options[:on_change]
|
11
14
|
end
|
12
15
|
|
13
16
|
def each
|
@@ -17,10 +20,14 @@ module Blendris
|
|
17
20
|
end
|
18
21
|
|
19
22
|
def <<(value)
|
20
|
-
[ value ].flatten.compact
|
23
|
+
values = [ value ].flatten.compact
|
24
|
+
|
25
|
+
values.flatten.compact.each do |v|
|
21
26
|
redis.rpush key, v
|
22
27
|
end
|
23
28
|
|
29
|
+
notify_changed if values.count > 0
|
30
|
+
|
24
31
|
self
|
25
32
|
end
|
26
33
|
|
@@ -30,6 +37,8 @@ module Blendris
|
|
30
37
|
|
31
38
|
def delete(value)
|
32
39
|
redis.lrem key, 0, value
|
40
|
+
ensure
|
41
|
+
notify_changed
|
33
42
|
end
|
34
43
|
|
35
44
|
end
|
data/lib/blendris/model.rb
CHANGED
@@ -1,18 +1,29 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# Model is the main driver for Blendris. All Blendris objects
|
4
|
+
# will inherit from it to function as a database model.
|
5
|
+
|
3
6
|
class Model
|
4
7
|
|
5
8
|
include RedisAccessor
|
6
9
|
|
7
10
|
attr_reader :key
|
8
11
|
|
12
|
+
# Instantiate a new instance of this model. We do some basic
|
13
|
+
# checking to make sure that this object already exists in Redis
|
14
|
+
# as the requested type. This is to prevent keys being used in
|
15
|
+
# the wrong way.
|
16
|
+
|
17
|
+
# If the :verify option isn't set to false, then each field of
|
18
|
+
# this model is also verified.
|
19
|
+
|
9
20
|
def initialize(new_key, options = {})
|
10
21
|
@key = sanitize_key(new_key)
|
11
|
-
actual_type = constantize(redis.get(
|
22
|
+
actual_type = constantize(redis.get(key))
|
12
23
|
|
13
24
|
raise ArgumentError.new("#{self.class.name} second argument must be a hash") unless options.kind_of? Hash
|
14
|
-
raise TypeError.new("#{
|
15
|
-
raise TypeError.new("#{
|
25
|
+
raise TypeError.new("#{key} does not exist, not a #{self.class.name} - you may want create instead of new") if !actual_type
|
26
|
+
raise TypeError.new("#{key} is a #{actual_type}, not a #{self.class.name}") if actual_type != self.class
|
16
27
|
|
17
28
|
if options[:verify] != false
|
18
29
|
parameters = self.class.local_parameters.find_all {|s| s.kind_of? Symbol}
|
@@ -23,16 +34,21 @@ module Blendris
|
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
37
|
+
# An object's id is considered to be the SHA1 digest of its key. This is
|
38
|
+
# to ensure that all objects that represent the same key return the same id.
|
26
39
|
def id
|
27
40
|
Digest::SHA1.hexdigest key
|
28
41
|
end
|
29
42
|
|
43
|
+
# TODO: Create the methods in the initialize method instead of depending
|
44
|
+
# on method_missing to dispatch to the correct methods. This will make
|
45
|
+
# these objects better for mocking and stubbing.
|
30
46
|
def method_missing(method_sym, *arguments)
|
31
47
|
(name, setter) = method_sym.to_s.scan(/(.*[^=])(=)?/).first
|
32
48
|
|
33
49
|
if node = redis_symbol(name)
|
34
50
|
if setter
|
35
|
-
return node.set
|
51
|
+
return node.set(*arguments)
|
36
52
|
else
|
37
53
|
return node.get
|
38
54
|
end
|
@@ -41,6 +57,9 @@ module Blendris
|
|
41
57
|
super
|
42
58
|
end
|
43
59
|
|
60
|
+
# Look up the given symbol by its name. The list of symbols are defined
|
61
|
+
# when the model is declared.
|
62
|
+
# TODO: This can also probably go away when I remove the need for method_missing.
|
44
63
|
def redis_symbol(name)
|
45
64
|
subkey = self.subkey(name)
|
46
65
|
|
@@ -48,23 +67,44 @@ module Blendris
|
|
48
67
|
|
49
68
|
return unless options
|
50
69
|
|
51
|
-
|
70
|
+
on_change = lambda { self.fire_on_change_for name }
|
71
|
+
options = options.merge(:model => self, :on_change => on_change)
|
52
72
|
|
53
73
|
options[:type].new subkey, options
|
54
74
|
end
|
55
75
|
|
56
|
-
|
57
|
-
|
76
|
+
# Calculate the key to address the given child node.
|
77
|
+
def subkey(child)
|
78
|
+
sanitize_key "#{self.key}:#{child}"
|
58
79
|
end
|
59
80
|
|
81
|
+
# Compare two instances. If two instances have the same class and key, they are equal.
|
60
82
|
def ==(other)
|
61
83
|
return false unless self.class == other.class
|
62
84
|
return self.key == other.key
|
63
85
|
end
|
64
86
|
|
87
|
+
# Return a list of field names for this model.
|
88
|
+
def fields
|
89
|
+
self.class.redis_symbols.map {|name, field| name.to_s}
|
90
|
+
end
|
91
|
+
|
92
|
+
# Fire the list of blocks called when the given symbol changes.
|
93
|
+
def fire_on_change_for(symbol)
|
94
|
+
blocks = [ self.class.on_change_table[nil], self.class.on_change_table[symbol.to_s] ]
|
95
|
+
|
96
|
+
blocks.flatten!
|
97
|
+
blocks.compact!
|
98
|
+
|
99
|
+
blocks.each do |block|
|
100
|
+
self.instance_exec symbol.to_s, &block
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
65
104
|
class << self
|
66
105
|
|
67
106
|
include RedisAccessor
|
107
|
+
include Enumerable
|
68
108
|
|
69
109
|
# This method will instantiate a new object with the correct key
|
70
110
|
# and assign the values passed to it.
|
@@ -79,13 +119,14 @@ module Blendris
|
|
79
119
|
end
|
80
120
|
|
81
121
|
key = generate_key(self, args)
|
82
|
-
current_model = redis.get(
|
122
|
+
current_model = redis.get(key)
|
83
123
|
|
84
124
|
if current_model && current_model != self.name
|
85
125
|
raise ArgumentError.new("#{key} is a #{current_model}, not a #{self.name}")
|
86
126
|
end
|
87
127
|
|
88
|
-
redis.set
|
128
|
+
redis.set key, self.name
|
129
|
+
redis.sadd index_key, key
|
89
130
|
|
90
131
|
obj = new(key, :verify => false)
|
91
132
|
|
@@ -105,6 +146,14 @@ module Blendris
|
|
105
146
|
nil
|
106
147
|
end
|
107
148
|
|
149
|
+
def each
|
150
|
+
RedisSet.new(index_key).each {|k| yield new(k)}
|
151
|
+
end
|
152
|
+
|
153
|
+
def index_key
|
154
|
+
"index:model:#{self.name}"
|
155
|
+
end
|
156
|
+
|
108
157
|
# Defines a new data type for Blendris:Model construction.
|
109
158
|
def type(name, klass)
|
110
159
|
(class << self; self; end).instance_eval do
|
@@ -136,6 +185,27 @@ module Blendris
|
|
136
185
|
options[:type].cast_to_redis value, options
|
137
186
|
end
|
138
187
|
|
188
|
+
# Define a block to call when one of the given symbol values changes.
|
189
|
+
def on_change(*symbols, &block)
|
190
|
+
symbols.flatten!
|
191
|
+
symbols.compact!
|
192
|
+
|
193
|
+
if symbols.count == 0
|
194
|
+
on_change_table[nil] ||= []
|
195
|
+
on_change_table[nil] << block
|
196
|
+
else
|
197
|
+
symbols.each do |symbol|
|
198
|
+
on_change_table[symbol.to_s] ||= []
|
199
|
+
on_change_table[symbol.to_s] << block
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# The hash of blocks called when fields on this object change.
|
205
|
+
def on_change_table
|
206
|
+
@on_change_table ||= {}
|
207
|
+
end
|
208
|
+
|
139
209
|
end
|
140
210
|
|
141
211
|
end
|
data/lib/blendris/node.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
3
|
# RedisNode is used to compose all Redis value wrapper classes.
|
4
|
+
|
4
5
|
module RedisNode
|
5
6
|
|
6
7
|
include RedisAccessor
|
7
8
|
|
9
|
+
attr_reader :key
|
10
|
+
|
8
11
|
def initialize(key, options = {})
|
9
12
|
@key = sanitize_key(key)
|
10
13
|
@default = options[:default]
|
11
14
|
@options = options
|
15
|
+
@on_change = options[:on_change]
|
12
16
|
|
13
|
-
|
17
|
+
if @default && !redis.exists(self.key)
|
18
|
+
redis.set key, self.class.cast_to_redis(@default, @options)
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
def set(value)
|
@@ -19,18 +25,18 @@ module Blendris
|
|
19
25
|
else
|
20
26
|
redis.del key
|
21
27
|
end
|
28
|
+
ensure
|
29
|
+
notify_changed
|
22
30
|
end
|
23
31
|
|
24
32
|
def get
|
25
33
|
self.class.cast_from_redis redis.get(self.key), @options
|
26
34
|
end
|
27
35
|
|
28
|
-
def key
|
29
|
-
prefix + @key
|
30
|
-
end
|
31
|
-
|
32
36
|
def clear
|
33
37
|
redis.del key
|
38
|
+
ensure
|
39
|
+
notify_changed
|
34
40
|
end
|
35
41
|
|
36
42
|
def type
|
@@ -41,6 +47,10 @@ module Blendris
|
|
41
47
|
redis.exists key
|
42
48
|
end
|
43
49
|
|
50
|
+
def notify_changed
|
51
|
+
@on_change.call if @on_change
|
52
|
+
end
|
53
|
+
|
44
54
|
end
|
45
55
|
|
46
56
|
end
|
data/lib/blendris/reference.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# RedisReference is a wrapper to a Redis string value and serves
|
4
|
+
# as a pointer to another blendris object.
|
5
|
+
|
3
6
|
class RedisReference < RedisReferenceBase
|
4
7
|
|
5
8
|
include RedisNode
|
@@ -22,7 +25,10 @@ module Blendris
|
|
22
25
|
modified = true
|
23
26
|
end
|
24
27
|
|
25
|
-
|
28
|
+
if modified
|
29
|
+
apply_reverse_delete(old_obj)
|
30
|
+
notify_changed
|
31
|
+
end
|
26
32
|
|
27
33
|
obj
|
28
34
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# RedisReferenceBase holds the methods that are common to
|
4
|
+
# RedisReference objects and RedisReferenceSet objects.
|
5
|
+
|
3
6
|
class RedisReferenceBase
|
4
7
|
|
5
8
|
include RedisNode
|
@@ -10,6 +13,7 @@ module Blendris
|
|
10
13
|
@key = sanitize_key(key)
|
11
14
|
@reverse = options[:reverse]
|
12
15
|
@options = options
|
16
|
+
@on_change = options[:on_change]
|
13
17
|
|
14
18
|
@klass = options[:class] || Model
|
15
19
|
@klass = constantize(camelize @klass) if @klass.kind_of? String
|
@@ -52,7 +56,7 @@ module Blendris
|
|
52
56
|
expect = constantize(expect) if expect.kind_of? String
|
53
57
|
expect = Model unless expect.ancestors.include? Model
|
54
58
|
|
55
|
-
klass = constantize(redis.get(
|
59
|
+
klass = constantize(redis.get(refkey)) if refkey
|
56
60
|
|
57
61
|
if klass == nil
|
58
62
|
nil
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# RedisReferenceSet is a wrapper to a Redis set value and serves
|
4
|
+
# as a pointer to multiple other blendris objects.
|
5
|
+
|
3
6
|
class RedisReferenceSet < RedisReferenceBase
|
4
7
|
|
5
8
|
include RedisNode
|
@@ -9,6 +12,7 @@ module Blendris
|
|
9
12
|
@refs ||= RedisSet.new(@key)
|
10
13
|
end
|
11
14
|
|
15
|
+
# TODO set should be a real set, while << appends
|
12
16
|
def set(*objs)
|
13
17
|
objs.flatten!
|
14
18
|
objs.compact!
|
@@ -20,6 +24,8 @@ module Blendris
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
27
|
+
notify_changed if objs.count > 0
|
28
|
+
|
23
29
|
self
|
24
30
|
end
|
25
31
|
alias :<< :set
|
@@ -28,6 +34,7 @@ module Blendris
|
|
28
34
|
if refkey = self.class.cast_to_redis(obj, @options)
|
29
35
|
deleted = refs.delete(refkey)
|
30
36
|
apply_reverse_delete(obj) if deleted
|
37
|
+
notify_changed
|
31
38
|
deleted
|
32
39
|
end
|
33
40
|
end
|
data/lib/blendris/set.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Blendris
|
2
2
|
|
3
|
+
# RedisSet is a wrapper to the Redis SET data type.
|
4
|
+
|
3
5
|
class RedisSet
|
4
6
|
|
5
7
|
include RedisNode
|
@@ -8,6 +10,7 @@ module Blendris
|
|
8
10
|
def initialize(key, options = {})
|
9
11
|
@key = key.to_s
|
10
12
|
@options = options
|
13
|
+
@on_change = options[:on_change]
|
11
14
|
end
|
12
15
|
|
13
16
|
def each
|
@@ -24,6 +27,8 @@ module Blendris
|
|
24
27
|
end
|
25
28
|
|
26
29
|
self
|
30
|
+
ensure
|
31
|
+
notify_changed
|
27
32
|
end
|
28
33
|
|
29
34
|
def get
|
@@ -32,6 +37,8 @@ module Blendris
|
|
32
37
|
|
33
38
|
def delete(value)
|
34
39
|
redis.srem key, value
|
40
|
+
ensure
|
41
|
+
notify_changed
|
35
42
|
end
|
36
43
|
|
37
44
|
end
|
data/lib/blendris/string.rb
CHANGED
data/lib/blendris/types.rb
CHANGED
data/lib/blendris/utils.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -48,6 +48,21 @@ describe Model do
|
|
48
48
|
fav.food.should == @onion
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should have a valid list of fields" do
|
52
|
+
|
53
|
+
fields = %w( name foods )
|
54
|
+
|
55
|
+
@vegetable.fields.should == fields
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should use its on_change field correctly" do
|
60
|
+
@apple.calories.should == 0
|
61
|
+
@apple.description = "good"
|
62
|
+
@apple.description = "bad"
|
63
|
+
@apple.calories.should == 2
|
64
|
+
end
|
65
|
+
|
51
66
|
context "with single reference" do
|
52
67
|
|
53
68
|
it "should reverse to a single reference" do
|
@@ -177,4 +192,27 @@ describe Model do
|
|
177
192
|
|
178
193
|
end
|
179
194
|
|
195
|
+
it "should enumerable all foods" do
|
196
|
+
Food.count.should == 5
|
197
|
+
|
198
|
+
count = 0
|
199
|
+
|
200
|
+
Food.each do |food|
|
201
|
+
count += 1
|
202
|
+
food.should be_a(Food)
|
203
|
+
end
|
204
|
+
|
205
|
+
count.should == 5
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should call its on_change method for all fields" do
|
209
|
+
o = OnChangeTestModel.create
|
210
|
+
lambda { o.string = "test" }.should raise_exception TestEx
|
211
|
+
lambda { o.integer = 123 }.should raise_exception TestEx
|
212
|
+
lambda { o.set = [1,2,3] }.should raise_exception TestEx
|
213
|
+
lambda { o.list = [1,5,8] }.should raise_exception TestEx
|
214
|
+
lambda { o.ref = o }.should raise_exception TestEx
|
215
|
+
lambda { o.refs << o }.should raise_exception TestEx
|
216
|
+
end
|
217
|
+
|
180
218
|
end
|
data/spec/redis-tools_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -29,6 +29,10 @@ module TestFixtures
|
|
29
29
|
refs :friends, :class => Food, :reverse => :friends
|
30
30
|
ref :something
|
31
31
|
|
32
|
+
on_change :description do
|
33
|
+
self.calories += 1
|
34
|
+
end
|
35
|
+
|
32
36
|
end
|
33
37
|
|
34
38
|
class Category < Model
|
@@ -58,14 +62,29 @@ module TestFixtures
|
|
58
62
|
refs :sister_sites, :class => Website, :reverse => :sister_sites
|
59
63
|
end
|
60
64
|
|
65
|
+
class OnChangeTestModel < Blendris::Model
|
66
|
+
key "fixed"
|
67
|
+
|
68
|
+
string :string
|
69
|
+
integer :integer
|
70
|
+
set :set
|
71
|
+
list :list
|
72
|
+
ref :ref
|
73
|
+
refs :refs
|
74
|
+
|
75
|
+
on_change { raise TestEx.new }
|
76
|
+
end
|
77
|
+
|
78
|
+
class TestEx < Exception; end
|
79
|
+
|
61
80
|
end
|
62
81
|
|
63
82
|
Spec::Runner.configure do |config|
|
64
83
|
include TestFixtures
|
65
84
|
|
66
85
|
config.before(:each) do
|
67
|
-
RedisAccessor.
|
68
|
-
RedisAccessor.
|
86
|
+
RedisAccessor.database = 11
|
87
|
+
RedisAccessor.flushdb
|
69
88
|
|
70
89
|
@vegetable = Category.create("vegetable")
|
71
90
|
@onion = Food.create("onion")
|
@@ -80,7 +99,7 @@ Spec::Runner.configure do |config|
|
|
80
99
|
end
|
81
100
|
|
82
101
|
config.after(:each) do
|
83
|
-
RedisAccessor.
|
102
|
+
RedisAccessor.flushdb
|
84
103
|
end
|
85
104
|
end
|
86
105
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blendris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex McHale
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
V3OoCfxVK/4Dqg==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2010-02-
|
33
|
+
date: 2010-02-15 00:00:00 -06:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
@@ -64,7 +64,6 @@ files:
|
|
64
64
|
- README.markdown
|
65
65
|
- Rakefile
|
66
66
|
- autotest/discover.rb
|
67
|
-
- blendris.gemspec
|
68
67
|
- lib/blendris.rb
|
69
68
|
- lib/blendris/accessor.rb
|
70
69
|
- lib/blendris/errors.rb
|
@@ -91,6 +90,7 @@ files:
|
|
91
90
|
- spec/spec_helper.rb
|
92
91
|
- spec/string_spec.rb
|
93
92
|
- tasks/rspec.rake
|
93
|
+
- blendris.gemspec
|
94
94
|
has_rdoc: true
|
95
95
|
homepage: http://github.com/alexmchale/blendris
|
96
96
|
licenses: []
|
metadata.gz.sig
CHANGED
Binary file
|