remodel-h 0.2.0 → 0.2.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -15,7 +15,7 @@ module Remodel
15
15
  end
16
16
 
17
17
  def id
18
- key && key.split(':').last.to_i
18
+ key && key.match(/\d+/)[0].to_i
19
19
  end
20
20
 
21
21
  def save
@@ -61,7 +61,7 @@ module Remodel
61
61
  end
62
62
 
63
63
  def self.find(context, key)
64
- key = "#{key_prefix}:#{key}" if key.kind_of? Integer
64
+ key = "#{key_prefix}#{key}" if key.kind_of? Integer
65
65
  restore(context, key, fetch(context, key))
66
66
  end
67
67
 
@@ -92,7 +92,7 @@ module Remodel
92
92
  instance_variable_get(var)
93
93
  else
94
94
  clazz = Class[options[:class]]
95
- instance_variable_set(var, HasMany.new(self, clazz, "#{key}:#{name}", options[:reverse]))
95
+ instance_variable_set(var, HasMany.new(self, clazz, "#{key}_#{name}", options[:reverse]))
96
96
  end
97
97
  end
98
98
  end
@@ -105,7 +105,7 @@ module Remodel
105
105
  instance_variable_get(var)
106
106
  else
107
107
  clazz = Class[options[:class]]
108
- value_key = Remodel.redis.hget(self.context, "#{key}:#{name}")
108
+ value_key = Remodel.redis.hget(self.context, "#{key}_#{name}")
109
109
  instance_variable_set(var, clazz.find(self.context, value_key)) if value_key
110
110
  end
111
111
  end
@@ -118,10 +118,10 @@ module Remodel
118
118
  define_method("_#{name}=") do |value|
119
119
  if value
120
120
  instance_variable_set(var, value)
121
- Remodel.redis.hset(self.context, "#{key}:#{name}", value.key)
121
+ Remodel.redis.hset(self.context, "#{key}_#{name}", value.key)
122
122
  else
123
123
  remove_instance_variable(var) if instance_variable_defined? var
124
- Remodel.redis.hdel(self.context, "#{key}:#{name}")
124
+ Remodel.redis.hdel(self.context, "#{key}_#{name}")
125
125
  end
126
126
  end; private "_#{name}="
127
127
 
@@ -155,8 +155,8 @@ module Remodel
155
155
 
156
156
  # Each entity has its own sequence to generate unique ids.
157
157
  def next_key
158
- id = Remodel.redis.hincrby(@context, "#{self.class.key_prefix}:seq", 1)
159
- "#{self.class.key_prefix}:#{id}"
158
+ id = Remodel.redis.hincrby(@context, "#{self.class.key_prefix}", 1)
159
+ "#{self.class.key_prefix}#{id}"
160
160
  end
161
161
 
162
162
  # Default key prefix is the first letter of the class name, in lowercase.
data/remodel-h.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{remodel-h}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Lossen"]
12
- s.date = %q{2010-07-20}
12
+ s.date = %q{2010-07-21}
13
13
  s.default_executable = %q{redis-monitor.rb}
14
14
  s.description = %q{persist your objects to redis hashes.}
15
15
  s.email = %q{tim@lossen.de}
data/test/test_entity.rb CHANGED
@@ -55,9 +55,9 @@ class TestEntity < Test::Unit::TestCase
55
55
  end
56
56
 
57
57
  should "give the entity a key based on the class name" do
58
- assert_equal 'f:1', Foo.create('cx').key
59
- assert_equal 'b:1', Bar.create('cx').key
60
- assert_equal 'b:2', Bar.create('cx').key
58
+ assert_equal 'f1', Foo.create('cx').key
59
+ assert_equal 'b1', Bar.create('cx').key
60
+ assert_equal 'b2', Bar.create('cx').key
61
61
  end
62
62
 
63
63
  should "give the entity an id which is unique per entity class" do
@@ -208,7 +208,7 @@ class TestEntity < Test::Unit::TestCase
208
208
  context "#set_key_prefix" do
209
209
  should "use the given key prefix" do
210
210
  class Custom < Remodel::Entity; set_key_prefix 'my'; end
211
- assert_match /^my:\d+$/, Custom.create('cx').key
211
+ assert_match /^my\d+$/, Custom.create('cx').key
212
212
  end
213
213
 
214
214
  should "ensure that the prefix is letters only" do
@@ -28,7 +28,7 @@ class TestManyToOne < Test::Unit::TestCase
28
28
  red_piece = Piece.create('cx', :color => 'red')
29
29
  blue_piece = Piece.create('cx', :color => 'blue')
30
30
  value = JSON.generate([red_piece.key, blue_piece.key])
31
- redis.hset 'cx', "#{puzzle.key}:pieces", value
31
+ redis.hset 'cx', "#{puzzle.key}_pieces", value
32
32
  assert_equal 2, puzzle.pieces.size
33
33
  assert_equal Piece, puzzle.pieces[0].class
34
34
  assert_equal 'red', puzzle.pieces[0].color
@@ -98,7 +98,7 @@ class TestManyToOne < Test::Unit::TestCase
98
98
  should "reset has_many associations" do
99
99
  puzzle = Puzzle.create('cx')
100
100
  piece = puzzle.pieces.create :color => 'black'
101
- redis.hdel 'cx', "#{puzzle.key}:pieces"
101
+ redis.hdel 'cx', "#{puzzle.key}_pieces"
102
102
  puzzle.reload
103
103
  assert_equal [], puzzle.pieces
104
104
  end
@@ -26,7 +26,7 @@ class TestOneToMany < Test::Unit::TestCase
26
26
  should "return the associated entity" do
27
27
  puzzle = Puzzle.create('cx', :topic => 'animals')
28
28
  piece = Piece.create('cx')
29
- redis.hset('cx', "#{piece.key}:puzzle", puzzle.key)
29
+ redis.hset('cx', "#{piece.key}_puzzle", puzzle.key)
30
30
  assert_equal 'animals', piece.puzzle.topic
31
31
  end
32
32
  end
@@ -40,7 +40,7 @@ class TestOneToMany < Test::Unit::TestCase
40
40
  puzzle = Puzzle.create('cx')
41
41
  piece = Piece.create('cx')
42
42
  piece.puzzle = puzzle
43
- assert_equal puzzle.key, redis.hget(puzzle.context, "#{piece.key}:puzzle")
43
+ assert_equal puzzle.key, redis.hget(puzzle.context, "#{piece.key}_puzzle")
44
44
  end
45
45
 
46
46
  should "add the entity to the reverse association" do
@@ -69,7 +69,7 @@ class TestOneToMany < Test::Unit::TestCase
69
69
  piece = Piece.create('cx')
70
70
  piece.puzzle = Puzzle.create('cx')
71
71
  piece.puzzle = nil
72
- assert_nil redis.hget(piece.context, "#{piece.key}:puzzle")
72
+ assert_nil redis.hget(piece.context, "#{piece.key}_puzzle")
73
73
  end
74
74
 
75
75
  should "remove the entity from the reverse association if set to nil" do
@@ -87,7 +87,7 @@ class TestOneToMany < Test::Unit::TestCase
87
87
  should "reset has_one associations" do
88
88
  piece = Piece.create('cx', :color => 'black')
89
89
  piece.puzzle = Puzzle.create('cx')
90
- redis.hdel 'cx', "#{piece.key}:puzzle"
90
+ redis.hdel 'cx', "#{piece.key}_puzzle"
91
91
  piece.reload
92
92
  assert_nil piece.puzzle
93
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remodel-h
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Lossen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-07-20 00:00:00 +02:00
12
+ date: 2010-07-21 00:00:00 +02:00
13
13
  default_executable: redis-monitor.rb
14
14
  dependencies: []
15
15