frivol 0.1.3 → 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.
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>redis_config= (Frivol::Config)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 121</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis_config=</span>(<span class="ruby-identifier">config</span>)
15
+ <span class="ruby-ivar">@@redis</span> = <span class="ruby-constant">Redis</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">config</span>)
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>redis (Frivol::Config)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 126</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis</span>
15
+ <span class="ruby-ivar">@@redis</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>include_in (Frivol::Config)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 136</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">include_in</span>(<span class="ruby-identifier">host_class</span>, <span class="ruby-identifier">storage_expires_in</span> = <span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-identifier">host_class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:include</span>, <span class="ruby-constant">Frivol</span>)
16
+ <span class="ruby-identifier">host_class</span>.<span class="ruby-identifier">storage_expires_in</span> <span class="ruby-identifier">storage_expires_in</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">storage_expires_in</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -0,0 +1,191 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Time</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Time</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/frivol_rb.html">
59
+ lib/frivol.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <h2><a href="Time.html">Time</a></h2>
83
+ <p>
84
+ An extension to the <a href="Time.html">Time</a> class which allows <a
85
+ href="Time.html">Time</a> instances to be serialized by <tt><a
86
+ href="Time.html#M000001">to_json</a></tt> and deserialized by
87
+ <tt>JSON#parse</tt>.
88
+ </p>
89
+
90
+ </div>
91
+
92
+
93
+ </div>
94
+
95
+ <div id="method-list">
96
+ <h3 class="section-bar">Methods</h3>
97
+
98
+ <div class="name-list">
99
+ <a href="#M000002">json_create</a>&nbsp;&nbsp;
100
+ <a href="#M000001">to_json</a>&nbsp;&nbsp;
101
+ </div>
102
+ </div>
103
+
104
+ </div>
105
+
106
+
107
+ <!-- if includes -->
108
+
109
+ <div id="section">
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ <!-- if method_list -->
119
+ <div id="methods">
120
+ <h3 class="section-bar">Public Class methods</h3>
121
+
122
+ <div id="method-M000002" class="method-detail">
123
+ <a name="M000002"></a>
124
+
125
+ <div class="method-heading">
126
+ <a href="#M000002" class="method-signature">
127
+ <span class="method-name">json_create</span><span class="method-args">(o)</span>
128
+ </a>
129
+ </div>
130
+
131
+ <div class="method-description">
132
+ <p>
133
+ Deserialize from JSON
134
+ </p>
135
+ <p><a class="source-toggle" href="#"
136
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
137
+ <div class="method-source-code" id="M000002-source">
138
+ <pre>
139
+ <span class="ruby-comment cmt"># File lib/frivol.rb, line 217</span>
140
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">json_create</span>(<span class="ruby-identifier">o</span>)
141
+ <span class="ruby-constant">Time</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">o</span>[<span class="ruby-value str">'data'</span>])
142
+ <span class="ruby-keyword kw">end</span>
143
+ </pre>
144
+ </div>
145
+ </div>
146
+ </div>
147
+
148
+ <h3 class="section-bar">Public Instance methods</h3>
149
+
150
+ <div id="method-M000001" class="method-detail">
151
+ <a name="M000001"></a>
152
+
153
+ <div class="method-heading">
154
+ <a href="#M000001" class="method-signature">
155
+ <span class="method-name">to_json</span><span class="method-args">(*a)</span>
156
+ </a>
157
+ </div>
158
+
159
+ <div class="method-description">
160
+ <p>
161
+ Serialize to JSON
162
+ </p>
163
+ <p><a class="source-toggle" href="#"
164
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
165
+ <div class="method-source-code" id="M000001-source">
166
+ <pre>
167
+ <span class="ruby-comment cmt"># File lib/frivol.rb, line 209</span>
168
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)
169
+ {
170
+ <span class="ruby-value str">'json_class'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>,
171
+ <span class="ruby-value str">'data'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>
172
+ }.<span class="ruby-identifier">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)
173
+ <span class="ruby-keyword kw">end</span>
174
+ </pre>
175
+ </div>
176
+ </div>
177
+ </div>
178
+
179
+
180
+ </div>
181
+
182
+
183
+ </div>
184
+
185
+
186
+ <div id="validator-badges">
187
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
188
+ </div>
189
+
190
+ </body>
191
+ </html>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>to_json (Time)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 188</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)
15
+ {
16
+ <span class="ruby-value str">'json_class'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>,
17
+ <span class="ruby-value str">'data'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>
18
+ }.<span class="ruby-identifier">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)
19
+ <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>json_create (Time)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 196</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">json_create</span>(<span class="ruby-identifier">o</span>)
15
+ <span class="ruby-constant">Time</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">o</span>[<span class="ruby-value str">'data'</span>])
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
data/doc/created.rid ADDED
@@ -0,0 +1 @@
1
+ Sun, 22 Aug 2010 15:20:50 +0200
@@ -0,0 +1,204 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: frivol.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>frivol.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/frivol.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Sun Aug 22 15:18:58 +0200 2010</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <h1><a href="../../classes/Frivol.html">Frivol</a> - Frivolously simple temporary storage backed by Redis</h1>
73
+ <p>
74
+ A really simple Redis-backed temporary storage mechanism intended to be
75
+ used with ActiveRecord, but will work with other ORM&#8216;s or any classes
76
+ really.
77
+ </p>
78
+ <p>
79
+ I developed <a href="../../classes/Frivol.html">Frivol</a> secifically for
80
+ use in Mad Mimi (<a href="http://madmimi.com">madmimi.com</a>) to help with
81
+ caching of data which requires fairly long running (multi-second) database
82
+ queries, and also to aid with communication of status from background tasks
83
+ running in Resque on workers to the front end web servers. Redis was chosen
84
+ because we already had Resque, which is Redis-backed. Also, unlike
85
+ memcached, Redis persists it&#8216;s data to disk, meaning there is far
86
+ less warmup required when a hot system is restarted. <a
87
+ href="../../classes/Frivol.html">Frivol</a>&#8216;s design is such that it
88
+ solves our problem, but I believe it is generic enough to be used in many
89
+ Rails web projects and even in other types of projects altogether.
90
+ </p>
91
+ <h2>Usage</h2>
92
+ <p>
93
+ Configure <a href="../../classes/Frivol.html">Frivol</a> in your
94
+ configuration, for example in an initializer or in environment.rb
95
+ </p>
96
+ <pre>
97
+ REDIS_CONFIG = {
98
+ :host =&gt; &quot;localhost&quot;,
99
+ :port =&gt; 6379
100
+ }
101
+ Frivol::Config.redis_config = REDIS_CONFIG
102
+ </pre>
103
+ <p>
104
+ Now include <a href="../../classes/Frivol.html">Frivol</a> in whichever
105
+ classes you&#8216;d like to make use of temporary storage. You can
106
+ optionally call the <tt>storage_expires_in(time)</tt> class method to set a
107
+ default expiry. In your methods you can now call the
108
+ <tt>store(keys_and_values)</tt> and <tt>retrieve(keys_and_defaults)</tt>
109
+ methods.
110
+ </p>
111
+ <p>
112
+ Defaults in the <tt>retrieve</tt> method can be symbols, in which case <a
113
+ href="../../classes/Frivol.html">Frivol</a> will check if the class
114
+ <tt>respond_to?</tt> a method by that name to get the default.
115
+ </p>
116
+ <p>
117
+ The <tt>expire_storage(time)</tt> method can be used to set the expiry time
118
+ in seconds of the temporary storage. The default is not to expire the
119
+ storage, in which case it will live for as long as Redis keeps it.
120
+ </p>
121
+ <p>
122
+ <a href="../../classes/Frivol.html">Frivol</a> uses the
123
+ <tt>storage_key</tt> method to create a base key for storage in Redis. The
124
+ current implementation uses <tt>&quot;#{self.class.name}-#{id}&quot;</tt>
125
+ so you&#8216;ll want to override that method if you have classes that
126
+ don&#8216;t respond to id.
127
+ </p>
128
+ <p>
129
+ <a href="../../classes/Frivol.html">Frivol</a> also extends <a
130
+ href="../../classes/Time.html">Time</a> to allow it to be (de)serialized to
131
+ JSON, which currently used to store data in Redis.
132
+ </p>
133
+ <h2>Example</h2>
134
+ <pre>
135
+ class BigComplexCalcer
136
+ include Frivol
137
+ storage_expires_in 600 # temporary storage expires in 10 minutes.
138
+
139
+ def initialize(key)
140
+ @key = key
141
+ end
142
+
143
+ def storage_key
144
+ &quot;frivol-test-#{key}&quot; # override the storage key because we don't respond_to? id
145
+ end
146
+
147
+ def big_complex_calc
148
+ retrieve :complex =&gt; :do_big_complex_calc # do_big_complex_calc is the method to get the default from
149
+ end
150
+
151
+ def last_calc_done
152
+ last = retrieve :last =&gt; nil # default is nil
153
+ return &quot;never&quot; if last.nil?
154
+ return &quot;#{Time.now - last} seconds ago&quot;
155
+ end
156
+
157
+ def do_big_complex_calc
158
+ # Wee! Do some really hard work here...
159
+ # ...still working...
160
+ store :complex =&gt; result, :last =&gt; Time.now # ...and let's keep the result for at least 10 minutes, as well as the last time we did it
161
+ end
162
+ end
163
+ </pre>
164
+
165
+ </div>
166
+
167
+ <div id="requires-list">
168
+ <h3 class="section-bar">Required files</h3>
169
+
170
+ <div class="name-list">
171
+ json&nbsp;&nbsp;
172
+ redis&nbsp;&nbsp;
173
+ </div>
174
+ </div>
175
+
176
+ </div>
177
+
178
+
179
+ </div>
180
+
181
+
182
+ <!-- if includes -->
183
+
184
+ <div id="section">
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+ <!-- if method_list -->
194
+
195
+
196
+ </div>
197
+
198
+
199
+ <div id="validator-badges">
200
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
201
+ </div>
202
+
203
+ </body>
204
+ </html>