remodel-h 0.2.6 → 0.2.7

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.6
1
+ 0.2.7
@@ -30,18 +30,22 @@ module Remodel
30
30
 
31
31
  def reload
32
32
  raise EntityNotSaved unless @key
33
- initialize(@context, self.class.parse(self.class.fetch(@context, @key)), @key)
34
- instance_variables.each do |var|
35
- remove_instance_variable(var) if var =~ /^@association_/
33
+ attributes = self.class.parse(self.class.fetch(@context, @key))
34
+ initialize(@context, attributes, @key)
35
+ self.class.associations.each do |name|
36
+ var = "@#{name}".to_sym
37
+ remove_instance_variable(var) if instance_variable_defined? var
36
38
  end
37
39
  self
38
40
  end
39
41
 
40
42
  def delete
41
43
  raise EntityNotSaved unless @key
42
- Remodel.redis.hdel(@context, @key)
43
- instance_variables.each do |var|
44
- Remodel.redis.hdel(@context, var.to_s.sub('@association', @key)) if var =~ /^@association_/
44
+ Remodel.redis.pipelined do
45
+ Remodel.redis.hdel(@context, @key)
46
+ self.class.associations.each do |name|
47
+ Remodel.redis.hdel(@context, "#{@key}_#{name}")
48
+ end
45
49
  end
46
50
  end
47
51
 
@@ -87,7 +91,8 @@ module Remodel
87
91
  end
88
92
 
89
93
  def self.has_many(name, options)
90
- var = "@association_#{name}".to_sym
94
+ associations.push(name)
95
+ var = "@#{name}".to_sym
91
96
 
92
97
  define_method(name) do
93
98
  if instance_variable_defined? var
@@ -100,7 +105,8 @@ module Remodel
100
105
  end
101
106
 
102
107
  def self.has_one(name, options)
103
- var = "@association_#{name}".to_sym
108
+ associations.push(name)
109
+ var = "@#{name}".to_sym
104
110
 
105
111
  define_method(name) do
106
112
  if instance_variable_defined? var
@@ -200,6 +206,10 @@ module Remodel
200
206
  @mapper ||= {}
201
207
  end
202
208
 
209
+ def self.associations
210
+ @associations ||= []
211
+ end
212
+
203
213
  end
204
214
 
205
215
  end
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.6"
8
+ s.version = "0.2.7"
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{2011-02-01}
12
+ s.date = %q{2011-02-11}
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
@@ -16,7 +16,7 @@ class TestEntity < Test::Unit::TestCase
16
16
  bar = Bar.new('cx')
17
17
  assert_equal 123, bar.d
18
18
  end
19
-
19
+
20
20
  should "be returned for properties that are nil" do
21
21
  bar = Bar.new('cx', :d => 'cool')
22
22
  bar.d = nil
@@ -27,12 +27,12 @@ class TestEntity < Test::Unit::TestCase
27
27
  bar = Bar.new('cx', :d => 'cool')
28
28
  assert_equal 'cool', bar.d
29
29
  end
30
-
30
+
31
31
  should "not be stored" do
32
32
  bar = Bar.create('cx')
33
33
  assert !(/123/ =~ redis.hget('cx', bar.key))
34
34
  end
35
-
35
+
36
36
  should "be returned by as_json" do
37
37
  bar = Bar.new('cx')
38
38
  assert_equal 123, bar.as_json[:d]
@@ -50,7 +50,7 @@ class TestEntity < Test::Unit::TestCase
50
50
  foo = Foo.new('cx', :z => 3)
51
51
  assert foo.instance_eval { !@attributes.key? :z }
52
52
  end
53
-
53
+
54
54
  should "not set the key" do
55
55
  foo = Foo.new('cx', :x => 23)
56
56
  assert_equal nil, foo.key
@@ -61,7 +61,7 @@ class TestEntity < Test::Unit::TestCase
61
61
  assert_equal nil, foo.id
62
62
  end
63
63
  end
64
-
64
+
65
65
  context "create" do
66
66
  setup do
67
67
  redis.flushdb
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 6
9
- version: 0.2.6
8
+ - 7
9
+ version: 0.2.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Lossen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-01 00:00:00 +01:00
17
+ date: 2011-02-11 00:00:00 +01:00
18
18
  default_executable: redis-monitor.rb
19
19
  dependencies: []
20
20