remodel-h 0.2.5 → 0.2.6
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 +1 -1
- data/example/book.rb +1 -0
- data/lib/remodel/entity.rb +12 -9
- data/remodel-h.gemspec +36 -38
- data/test/test_entity.rb +30 -22
- data/test/test_entity_delete.rb +1 -0
- metadata +16 -8
- data/.gitignore +0 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
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
|
data/lib/remodel/entity.rb
CHANGED
|
@@ -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(
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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.
|
|
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{
|
|
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
|
-
|
|
19
|
+
"README.md"
|
|
20
20
|
]
|
|
21
21
|
s.files = [
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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.
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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::
|
|
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', '
|
|
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
|
data/test/test_entity_delete.rb
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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
|
-
|
|
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.
|
|
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