remodel-h 0.1.4
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/.gitignore +2 -0
- data/LICENSE +20 -0
- data/README.md +96 -0
- data/Rakefile +27 -0
- data/VERSION +1 -0
- data/bin/redis-monitor.rb +25 -0
- data/docs/docco.css +185 -0
- data/docs/remodel.html +269 -0
- data/example/book.rb +13 -0
- data/lib/remodel/entity.rb +198 -0
- data/lib/remodel/has_many.rb +71 -0
- data/lib/remodel/mapper.rb +29 -0
- data/lib/remodel.rb +77 -0
- data/remodel-h.gemspec +72 -0
- data/remodel.gemspec +72 -0
- data/test/helper.rb +19 -0
- data/test/test_entity.rb +313 -0
- data/test/test_many_to_many.rb +77 -0
- data/test/test_many_to_one.rb +107 -0
- data/test/test_mappers.rb +67 -0
- data/test/test_monkeypatches.rb +30 -0
- data/test/test_one_to_many.rb +96 -0
- data/test/test_one_to_one.rb +57 -0
- metadata +85 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Tim Lossen -- http://tim.lossen.de
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# remodel your storage layer
|
2
|
+
|
3
|
+
use [redis](http://github.com/antirez/redis) instead of mysql to store your application data.
|
4
|
+
|
5
|
+
remodel (= redis model) is an ActiveRecord-like mapping layer which offers familiar syntax
|
6
|
+
like `has_many`, `has_one` etc. to build your domain model in ruby.
|
7
|
+
|
8
|
+
|
9
|
+
## why redis?
|
10
|
+
|
11
|
+
redis offers in-memory read and write performance — on the order of 10K to 100K
|
12
|
+
operations per second, comparable to [memcached](http://memcached.org/) — plus asynchronous
|
13
|
+
persistence to disk. for example, on my macbook (2 ghz):
|
14
|
+
|
15
|
+
$ redis-benchmark -d 100 -r 10000 -q
|
16
|
+
SET: 13864.27 requests per second
|
17
|
+
GET: 18152.17 requests per second
|
18
|
+
INCR: 17006.80 requests per second
|
19
|
+
LPUSH: 17243.99 requests per second
|
20
|
+
LPOP: 18706.54 requests per second
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
## how to get started
|
25
|
+
|
26
|
+
1. install [redis](http://github.com/antirez/redis) and ezras excellent
|
27
|
+
[redis-rb](http://github.com/ezmobius/redis-rb) ruby client:
|
28
|
+
|
29
|
+
$ brew install redis
|
30
|
+
$ gem install redis
|
31
|
+
|
32
|
+
2. start redis:
|
33
|
+
|
34
|
+
$ ./redis-server
|
35
|
+
|
36
|
+
3. now the tests should run successfully:
|
37
|
+
|
38
|
+
$ rake
|
39
|
+
Started
|
40
|
+
.......................................................................................
|
41
|
+
Finished in 0.072304 seconds.
|
42
|
+
87 tests, 138 assertions, 0 failures, 0 errors
|
43
|
+
|
44
|
+
## example
|
45
|
+
|
46
|
+
define your domain model [like this](http://github.com/tlossen/remodel/blob/master/example/book.rb):
|
47
|
+
|
48
|
+
class Book < Remodel::Entity
|
49
|
+
has_many :chapters, :class => 'Chapter', :reverse => :book
|
50
|
+
property :title, :class => 'String'
|
51
|
+
property :year, :class => 'Integer'
|
52
|
+
end
|
53
|
+
|
54
|
+
class Chapter < Remodel::Entity
|
55
|
+
has_one :book, :class => Book, :reverse => :chapters
|
56
|
+
property :title, :class => String
|
57
|
+
end
|
58
|
+
|
59
|
+
now you can do:
|
60
|
+
|
61
|
+
>> require 'example/book'
|
62
|
+
=> true
|
63
|
+
>> book = Book.create :title => 'Moby Dick', :year => 1851
|
64
|
+
=> #<Book(b:3) title: "Moby Dick", year: 1851>
|
65
|
+
>> chapter = book.chapters.create :title => 'Ishmael'
|
66
|
+
=> #<Chapter(c:4) title: "Ishmael">
|
67
|
+
>> chapter.book
|
68
|
+
=> #<Book(b:3) title: "Moby Dick", year: 1851>
|
69
|
+
|
70
|
+
|
71
|
+
## inspired by
|
72
|
+
|
73
|
+
* [how to redis](http://www.paperplanes.de/2009/10/30/how_to_redis.html)
|
74
|
+
— good overview of different mapping options by [mattmatt](http://github.com/mattmatt).
|
75
|
+
* [hurl](http://github.com/defunkt/hurl) — basically
|
76
|
+
defunkts [Hurl::Model](http://github.com/defunkt/hurl/blob/master/models/model.rb) is what i started with.
|
77
|
+
* [ohm](http://github.com/soveran/ohm) — object-hash mapping for redis.
|
78
|
+
somewhat similar, but instead of serializing to json, stores each attribute under a separate key.
|
79
|
+
|
80
|
+
|
81
|
+
## todo
|
82
|
+
|
83
|
+
* better docs
|
84
|
+
* `find_by`
|
85
|
+
* make serializer (json, messagepack, marshal ...) configurable
|
86
|
+
* benchmarks
|
87
|
+
|
88
|
+
|
89
|
+
## status
|
90
|
+
|
91
|
+
still pretty alpha — play around at your own risk :)
|
92
|
+
|
93
|
+
|
94
|
+
## license
|
95
|
+
|
96
|
+
[MIT](http://github.com/tlossen/remodel/raw/master/LICENSE), baby!
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "remodel-h"
|
8
|
+
gem.summary = "remodel variant which uses hashes"
|
9
|
+
gem.description = "persist your objects to redis hashes."
|
10
|
+
gem.email = "tim@lossen.de"
|
11
|
+
gem.homepage = "http://github.com/tlossen/remodel"
|
12
|
+
gem.authors = ["Tim Lossen"]
|
13
|
+
gem.files.include('lib/**/*.rb')
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# http://gist.github.com/267149 (mathias meyer)
|
4
|
+
|
5
|
+
require 'socket'
|
6
|
+
host = ARGV[0] || 'localhost'
|
7
|
+
port = ARGV[1] || '6379'
|
8
|
+
|
9
|
+
trap(:INT) {
|
10
|
+
exit
|
11
|
+
}
|
12
|
+
|
13
|
+
puts "Connecting to #{host}:#{port}"
|
14
|
+
begin
|
15
|
+
sock = TCPSocket.new(host, port)
|
16
|
+
sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
17
|
+
|
18
|
+
sock.write("monitor\r\n")
|
19
|
+
|
20
|
+
while line = sock.gets
|
21
|
+
puts line
|
22
|
+
end
|
23
|
+
rescue Errno::ECONNREFUSED
|
24
|
+
puts "Connection refused"
|
25
|
+
end
|
data/docs/docco.css
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
/*--------------------- Layout and Typography ----------------------------*/
|
2
|
+
body {
|
3
|
+
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
|
4
|
+
font-size: 16px;
|
5
|
+
line-height: 24px;
|
6
|
+
color: #252519;
|
7
|
+
margin: 0; padding: 0;
|
8
|
+
}
|
9
|
+
a {
|
10
|
+
color: #261a3b;
|
11
|
+
}
|
12
|
+
a:visited {
|
13
|
+
color: #261a3b;
|
14
|
+
}
|
15
|
+
p {
|
16
|
+
margin: 0 0 15px 0;
|
17
|
+
}
|
18
|
+
h1, h2, h3, h4, h5, h6 {
|
19
|
+
margin: 40px 0 15px 0;
|
20
|
+
}
|
21
|
+
h3, h4, h5, h6 {
|
22
|
+
margin-top: 20px;
|
23
|
+
}
|
24
|
+
#container {
|
25
|
+
position: relative;
|
26
|
+
}
|
27
|
+
#background {
|
28
|
+
position: fixed;
|
29
|
+
top: 0; left: 580px; right: 0; bottom: 0;
|
30
|
+
background: #f5f5ff;
|
31
|
+
border-left: 1px solid #e5e5ee;
|
32
|
+
z-index: -1;
|
33
|
+
}
|
34
|
+
#jump_to, #jump_page {
|
35
|
+
background: white;
|
36
|
+
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
37
|
+
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
|
38
|
+
font: 10px Arial;
|
39
|
+
text-transform: uppercase;
|
40
|
+
cursor: pointer;
|
41
|
+
text-align: right;
|
42
|
+
}
|
43
|
+
#jump_to, #jump_wrapper {
|
44
|
+
position: fixed;
|
45
|
+
right: 0; top: 0;
|
46
|
+
padding: 5px 10px;
|
47
|
+
}
|
48
|
+
#jump_wrapper {
|
49
|
+
padding: 0;
|
50
|
+
display: none;
|
51
|
+
}
|
52
|
+
#jump_to:hover #jump_wrapper {
|
53
|
+
display: block;
|
54
|
+
}
|
55
|
+
#jump_page {
|
56
|
+
padding: 5px 0 3px;
|
57
|
+
margin: 0 0 25px 25px;
|
58
|
+
}
|
59
|
+
#jump_page .source {
|
60
|
+
display: block;
|
61
|
+
padding: 5px 10px;
|
62
|
+
text-decoration: none;
|
63
|
+
border-top: 1px solid #eee;
|
64
|
+
}
|
65
|
+
#jump_page .source:hover {
|
66
|
+
background: #f5f5ff;
|
67
|
+
}
|
68
|
+
#jump_page .source:first-child {
|
69
|
+
}
|
70
|
+
table td {
|
71
|
+
border: 0;
|
72
|
+
outline: 0;
|
73
|
+
}
|
74
|
+
td.docs, th.docs {
|
75
|
+
max-width: 500px;
|
76
|
+
min-width: 500px;
|
77
|
+
min-height: 5px;
|
78
|
+
padding: 10px 25px 1px 50px;
|
79
|
+
vertical-align: top;
|
80
|
+
text-align: left;
|
81
|
+
}
|
82
|
+
.docs pre {
|
83
|
+
margin: 15px 0 15px;
|
84
|
+
padding-left: 15px;
|
85
|
+
}
|
86
|
+
.docs p tt, .docs p code {
|
87
|
+
background: #f8f8ff;
|
88
|
+
border: 1px solid #dedede;
|
89
|
+
font-size: 12px;
|
90
|
+
padding: 0 0.2em;
|
91
|
+
}
|
92
|
+
.octowrap {
|
93
|
+
position: relative;
|
94
|
+
}
|
95
|
+
.octothorpe {
|
96
|
+
font: 12px Arial;
|
97
|
+
text-decoration: none;
|
98
|
+
color: #454545;
|
99
|
+
position: absolute;
|
100
|
+
top: 3px; left: -20px;
|
101
|
+
padding: 1px 2px;
|
102
|
+
opacity: 0;
|
103
|
+
-webkit-transition: opacity 0.2s linear;
|
104
|
+
}
|
105
|
+
td.docs:hover .octothorpe {
|
106
|
+
opacity: 1;
|
107
|
+
}
|
108
|
+
td.code, th.code {
|
109
|
+
padding: 14px 15px 16px 50px;
|
110
|
+
width: 100%;
|
111
|
+
vertical-align: top;
|
112
|
+
background: #f5f5ff;
|
113
|
+
border-left: 1px solid #e5e5ee;
|
114
|
+
}
|
115
|
+
pre, tt, code {
|
116
|
+
font-size: 12px; line-height: 18px;
|
117
|
+
font-family: Monaco, Consolas, "Lucida Console", monospace;
|
118
|
+
margin: 0; padding: 0;
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
/*---------------------- Syntax Highlighting -----------------------------*/
|
123
|
+
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
124
|
+
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
|
125
|
+
body .hll { background-color: #ffffcc }
|
126
|
+
body .c { color: #408080; font-style: italic } /* Comment */
|
127
|
+
/*body .err { border: 1px solid #FF0000 } /* Error */
|
128
|
+
body .k { color: #954121 } /* Keyword */
|
129
|
+
body .o { color: #666666 } /* Operator */
|
130
|
+
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
|
131
|
+
body .cp { color: #BC7A00 } /* Comment.Preproc */
|
132
|
+
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
133
|
+
body .cs { color: #408080; font-style: italic } /* Comment.Special */
|
134
|
+
body .gd { color: #A00000 } /* Generic.Deleted */
|
135
|
+
body .ge { font-style: italic } /* Generic.Emph */
|
136
|
+
body .gr { color: #FF0000 } /* Generic.Error */
|
137
|
+
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
138
|
+
body .gi { color: #00A000 } /* Generic.Inserted */
|
139
|
+
body .go { color: #808080 } /* Generic.Output */
|
140
|
+
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
141
|
+
body .gs { font-weight: bold } /* Generic.Strong */
|
142
|
+
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
143
|
+
body .gt { color: #0040D0 } /* Generic.Traceback */
|
144
|
+
body .kc { color: #954121 } /* Keyword.Constant */
|
145
|
+
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
|
146
|
+
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
|
147
|
+
body .kp { color: #954121 } /* Keyword.Pseudo */
|
148
|
+
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
|
149
|
+
body .kt { color: #B00040 } /* Keyword.Type */
|
150
|
+
body .m { color: #666666 } /* Literal.Number */
|
151
|
+
body .s { color: #219161 } /* Literal.String */
|
152
|
+
body .na { color: #7D9029 } /* Name.Attribute */
|
153
|
+
body .nb { color: #954121 } /* Name.Builtin */
|
154
|
+
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
155
|
+
body .no { color: #880000 } /* Name.Constant */
|
156
|
+
body .nd { color: #AA22FF } /* Name.Decorator */
|
157
|
+
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
158
|
+
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
159
|
+
body .nf { color: #0000FF } /* Name.Function */
|
160
|
+
body .nl { color: #A0A000 } /* Name.Label */
|
161
|
+
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
162
|
+
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
|
163
|
+
body .nv { color: #19469D } /* Name.Variable */
|
164
|
+
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
165
|
+
body .w { color: #bbbbbb } /* Text.Whitespace */
|
166
|
+
body .mf { color: #666666 } /* Literal.Number.Float */
|
167
|
+
body .mh { color: #666666 } /* Literal.Number.Hex */
|
168
|
+
body .mi { color: #666666 } /* Literal.Number.Integer */
|
169
|
+
body .mo { color: #666666 } /* Literal.Number.Oct */
|
170
|
+
body .sb { color: #219161 } /* Literal.String.Backtick */
|
171
|
+
body .sc { color: #219161 } /* Literal.String.Char */
|
172
|
+
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
|
173
|
+
body .s2 { color: #219161 } /* Literal.String.Double */
|
174
|
+
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
175
|
+
body .sh { color: #219161 } /* Literal.String.Heredoc */
|
176
|
+
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
177
|
+
body .sx { color: #954121 } /* Literal.String.Other */
|
178
|
+
body .sr { color: #BB6688 } /* Literal.String.Regex */
|
179
|
+
body .s1 { color: #219161 } /* Literal.String.Single */
|
180
|
+
body .ss { color: #19469D } /* Literal.String.Symbol */
|
181
|
+
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
|
182
|
+
body .vc { color: #19469D } /* Name.Variable.Class */
|
183
|
+
body .vg { color: #19469D } /* Name.Variable.Global */
|
184
|
+
body .vi { color: #19469D } /* Name.Variable.Instance */
|
185
|
+
body .il { color: #666666 } /* Literal.Number.Integer.Long */
|