remodel-h 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
data/example/book.rb CHANGED
@@ -4,6 +4,7 @@ class Book < Remodel::Entity
4
4
  has_many :chapters, :class => 'Chapter', :reverse => :book
5
5
  property :title, :class => 'String'
6
6
  property :year, :class => 'Integer'
7
+ property :author, :class => 'String', :default => '(anonymous)'
7
8
  end
8
9
 
9
10
  class Chapter < Remodel::Entity
@@ -8,7 +8,6 @@ module Remodel
8
8
  @context = context
9
9
  @attributes = {}
10
10
  @key = key
11
- attributes = self.class.default_values.merge(attributes) if key.nil?
12
11
  attributes.each do |name, value|
13
12
  send("#{name}=", value) if respond_to? "#{name}="
14
13
  end
@@ -47,7 +46,7 @@ module Remodel
47
46
  end
48
47
 
49
48
  def as_json
50
- { :id => id }.merge(@attributes)
49
+ { :id => id }.merge(attributes)
51
50
  end
52
51
 
53
52
  def to_json
@@ -55,7 +54,7 @@ module Remodel
55
54
  end
56
55
 
57
56
  def inspect
58
- properties = @attributes.map { |name, value| "#{name}: #{value.inspect}" }.join(', ')
57
+ properties = attributes.map { |name, value| "#{name}: #{value.inspect}" }.join(', ')
59
58
  "\#<#{self.class.name}(#{context}, #{id}) #{properties}>"
60
59
  end
61
60
 
@@ -82,8 +81,8 @@ module Remodel
82
81
  def self.property(name, options = {})
83
82
  name = name.to_sym
84
83
  mapper[name] = Remodel.mapper_for(options[:class])
85
- default_values[name] = options[:default] if options.has_key?(:default)
86
- define_method(name) { @attributes[name] }
84
+ default_value = options[:default]
85
+ define_method(name) { @attributes[name].nil? ? default_value : @attributes[name] }
87
86
  define_method("#{name}=") { |value| @attributes[name] = value }
88
87
  end
89
88
 
@@ -152,6 +151,14 @@ module Remodel
152
151
 
153
152
  private # --- Helper methods ---
154
153
 
154
+ def attributes
155
+ result = {}
156
+ self.class.mapper.keys.each do |name|
157
+ result[name] = send(name)
158
+ end
159
+ result
160
+ end
161
+
155
162
  def self.fetch(context, key)
156
163
  Remodel.redis.hget(context, key) || raise(EntityNotFound, "no #{name} with key #{key} in context #{context}")
157
164
  end
@@ -193,10 +200,6 @@ module Remodel
193
200
  @mapper ||= {}
194
201
  end
195
202
 
196
- def self.default_values
197
- @default_values ||= {}
198
- end
199
-
200
203
  end
201
204
 
202
205
  end
data/remodel-h.gemspec CHANGED
@@ -1,70 +1,68 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{remodel-h}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
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-12-08}
12
+ s.date = %q{2011-02-01}
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}
16
16
  s.executables = ["redis-monitor.rb"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.md"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
- ".gitignore",
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "bin/redis-monitor.rb",
28
- "docs/docco.css",
29
- "docs/remodel.html",
30
- "example/book.rb",
31
- "lib/remodel-h.rb",
32
- "lib/remodel/entity.rb",
33
- "lib/remodel/has_many.rb",
34
- "lib/remodel/mapper.rb",
35
- "remodel-h.gemspec",
36
- "test/helper.rb",
37
- "test/test_entity.rb",
38
- "test/test_entity_delete.rb",
39
- "test/test_many_to_many.rb",
40
- "test/test_many_to_one.rb",
41
- "test/test_mappers.rb",
42
- "test/test_monkeypatches.rb",
43
- "test/test_one_to_many.rb",
44
- "test/test_one_to_one.rb"
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/redis-monitor.rb",
27
+ "docs/docco.css",
28
+ "docs/remodel.html",
29
+ "example/book.rb",
30
+ "lib/remodel-h.rb",
31
+ "lib/remodel/entity.rb",
32
+ "lib/remodel/has_many.rb",
33
+ "lib/remodel/mapper.rb",
34
+ "remodel-h.gemspec",
35
+ "test/helper.rb",
36
+ "test/test_entity.rb",
37
+ "test/test_entity_delete.rb",
38
+ "test/test_many_to_many.rb",
39
+ "test/test_many_to_one.rb",
40
+ "test/test_mappers.rb",
41
+ "test/test_monkeypatches.rb",
42
+ "test/test_one_to_many.rb",
43
+ "test/test_one_to_one.rb"
45
44
  ]
46
45
  s.homepage = %q{http://github.com/tlossen/remodel}
47
- s.rdoc_options = ["--charset=UTF-8"]
48
46
  s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.3.5}
47
+ s.rubygems_version = %q{1.3.7}
50
48
  s.summary = %q{remodel variant which uses hashes}
51
49
  s.test_files = [
52
50
  "test/helper.rb",
53
- "test/test_entity.rb",
54
- "test/test_entity_delete.rb",
55
- "test/test_many_to_many.rb",
56
- "test/test_many_to_one.rb",
57
- "test/test_mappers.rb",
58
- "test/test_monkeypatches.rb",
59
- "test/test_one_to_many.rb",
60
- "test/test_one_to_one.rb"
51
+ "test/test_entity.rb",
52
+ "test/test_entity_delete.rb",
53
+ "test/test_many_to_many.rb",
54
+ "test/test_many_to_one.rb",
55
+ "test/test_mappers.rb",
56
+ "test/test_monkeypatches.rb",
57
+ "test/test_one_to_many.rb",
58
+ "test/test_one_to_one.rb"
61
59
  ]
62
60
 
63
61
  if s.respond_to? :specification_version then
64
62
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
63
  s.specification_version = 3
66
64
 
67
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
65
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
66
  else
69
67
  end
70
68
  else
data/test/test_entity.rb CHANGED
@@ -11,6 +11,34 @@ end
11
11
 
12
12
  class TestEntity < Test::Unit::TestCase
13
13
 
14
+ context "[default values]" do
15
+ should "be returned for missing properties" do
16
+ bar = Bar.new('cx')
17
+ assert_equal 123, bar.d
18
+ end
19
+
20
+ should "be returned for properties that are nil" do
21
+ bar = Bar.new('cx', :d => 'cool')
22
+ bar.d = nil
23
+ assert_equal 123, bar.d
24
+ end
25
+
26
+ should "not be returned for given properties" do
27
+ bar = Bar.new('cx', :d => 'cool')
28
+ assert_equal 'cool', bar.d
29
+ end
30
+
31
+ should "not be stored" do
32
+ bar = Bar.create('cx')
33
+ assert !(/123/ =~ redis.hget('cx', bar.key))
34
+ end
35
+
36
+ should "be returned by as_json" do
37
+ bar = Bar.new('cx')
38
+ assert_equal 123, bar.as_json[:d]
39
+ end
40
+ end
41
+
14
42
  context "new" do
15
43
  should "set properties" do
16
44
  foo = Foo.new('cx', :x => 1, :y => 2)
@@ -32,18 +60,8 @@ class TestEntity < Test::Unit::TestCase
32
60
  foo = Foo.new('cx', :x => 23)
33
61
  assert_equal nil, foo.id
34
62
  end
35
-
36
- should "use default values for missing properties" do
37
- bar = Bar.new('cx')
38
- assert_equal 123, bar.d
39
- end
40
-
41
- should "not use default values for given properties" do
42
- bar = Bar.new('cx', :d => 'cool')
43
- assert_equal 'cool', bar.d
44
- end
45
63
  end
46
-
64
+
47
65
  context "create" do
48
66
  setup do
49
67
  redis.flushdb
@@ -82,16 +100,6 @@ class TestEntity < Test::Unit::TestCase
82
100
  foo = Foo.create('cx', :x => 'hello', :y => false)
83
101
  assert !(/f:1/ =~ redis.hget('cx', foo.key))
84
102
  end
85
-
86
- should "use default values for missing properties" do
87
- bar = Bar.create('cx')
88
- assert_equal 123, bar.d
89
- end
90
-
91
- should "not use default values for given properties" do
92
- bar = Bar.create('cx', :d => 'cool')
93
- assert_equal 'cool', bar.d
94
- end
95
103
  end
96
104
 
97
105
  context "save" do
@@ -222,7 +230,7 @@ class TestEntity < Test::Unit::TestCase
222
230
  end
223
231
 
224
232
  should "reject a key which does not exist" do
225
- assert_raise(Remodel::EntityNotFound) { Foo.find('cx', 'x:66') }
233
+ assert_raise(Remodel::EntityNotFound) { Foo.find('cx', 'x66') }
226
234
  end
227
235
 
228
236
  should "reject an id which does not exist" do
@@ -23,6 +23,7 @@ class TestEntityDelete < Test::Unit::TestCase
23
23
  @group.members.create(:name => 'Tim')
24
24
  @group.members.create(:name => 'Ben')
25
25
  @group.room = Room.create(:name => 'some office')
26
+ # TODO: @group.reload
26
27
  end
27
28
 
28
29
  should "ensure that the entity is persistent" do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remodel-h
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 6
9
+ version: 0.2.6
5
10
  platform: ruby
6
11
  authors:
7
12
  - Tim Lossen
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-12-08 00:00:00 +01:00
17
+ date: 2011-02-01 00:00:00 +01:00
13
18
  default_executable: redis-monitor.rb
14
19
  dependencies: []
15
20
 
@@ -23,7 +28,6 @@ extra_rdoc_files:
23
28
  - LICENSE
24
29
  - README.md
25
30
  files:
26
- - .gitignore
27
31
  - LICENSE
28
32
  - README.md
29
33
  - Rakefile
@@ -51,26 +55,30 @@ homepage: http://github.com/tlossen/remodel
51
55
  licenses: []
52
56
 
53
57
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
58
+ rdoc_options: []
59
+
56
60
  require_paths:
57
61
  - lib
58
62
  required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
59
64
  requirements:
60
65
  - - ">="
61
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
62
69
  version: "0"
63
- version:
64
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
65
72
  requirements:
66
73
  - - ">="
67
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
68
77
  version: "0"
69
- version:
70
78
  requirements: []
71
79
 
72
80
  rubyforge_project:
73
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.3.7
74
82
  signing_key:
75
83
  specification_version: 3
76
84
  summary: remodel variant which uses hashes
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- dump.rdb
2
- pkg/*