ihoka-friendly 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -0
- data/.gitignore +27 -0
- data/.ruby-version +1 -0
- data/APACHE-LICENSE +202 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +38 -0
- data/README.md +13 -22
- data/Rakefile +25 -0
- data/TODO.md +5 -0
- data/VERSION +1 -0
- data/examples/friendly.yml +7 -0
- data/ihoka-friendly.gemspec +31 -0
- data/lib/friendly/document/mixin.rb +2 -2
- data/lib/friendly/indexer.rb +1 -1
- data/lib/tasks/friendly.rake +7 -0
- data/spec/config.yml.example +7 -0
- data/spec/fakes/data_store_fake.rb +29 -0
- data/spec/fakes/database_fake.rb +12 -0
- data/spec/fakes/dataset_fake.rb +28 -0
- data/spec/fakes/document.rb +18 -0
- data/spec/fakes/serializer_fake.rb +12 -0
- data/spec/fakes/time_fake.rb +12 -0
- data/spec/integration/ad_hoc_scopes_spec.rb +42 -0
- data/spec/integration/basic_object_lifecycle_spec.rb +115 -0
- data/spec/integration/batch_insertion_spec.rb +29 -0
- data/spec/integration/convenience_api_spec.rb +25 -0
- data/spec/integration/count_spec.rb +12 -0
- data/spec/integration/default_value_spec.rb +30 -0
- data/spec/integration/dirty_tracking_spec.rb +43 -0
- data/spec/integration/find_via_cache_spec.rb +101 -0
- data/spec/integration/finder_spec.rb +71 -0
- data/spec/integration/has_many_spec.rb +18 -0
- data/spec/integration/index_spec.rb +57 -0
- data/spec/integration/named_scope_spec.rb +34 -0
- data/spec/integration/offline_indexing_spec.rb +53 -0
- data/spec/integration/pagination_spec.rb +63 -0
- data/spec/integration/scope_chaining_spec.rb +22 -0
- data/spec/integration/table_creator_spec.rb +64 -0
- data/spec/integration/write_through_cache_spec.rb +53 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/unit/associations/association_spec.rb +57 -0
- data/spec/unit/associations/set_spec.rb +43 -0
- data/spec/unit/attribute_spec.rb +125 -0
- data/spec/unit/cache_by_id_spec.rb +102 -0
- data/spec/unit/cache_spec.rb +21 -0
- data/spec/unit/data_store_spec.rb +201 -0
- data/spec/unit/document/attributes_spec.rb +130 -0
- data/spec/unit/document_spec.rb +318 -0
- data/spec/unit/document_table_spec.rb +126 -0
- data/spec/unit/friendly_spec.rb +25 -0
- data/spec/unit/index_spec.rb +196 -0
- data/spec/unit/memcached_spec.rb +114 -0
- data/spec/unit/query_spec.rb +104 -0
- data/spec/unit/scope_proxy_spec.rb +44 -0
- data/spec/unit/scope_spec.rb +113 -0
- data/spec/unit/storage_factory_spec.rb +59 -0
- data/spec/unit/storage_proxy_spec.rb +244 -0
- data/spec/unit/translator_spec.rb +91 -0
- data/website/index.html +210 -0
- data/website/scripts/clipboard.swf +0 -0
- data/website/scripts/shBrushAS3.js +61 -0
- data/website/scripts/shBrushBash.js +66 -0
- data/website/scripts/shBrushCSharp.js +67 -0
- data/website/scripts/shBrushColdFusion.js +102 -0
- data/website/scripts/shBrushCpp.js +99 -0
- data/website/scripts/shBrushCss.js +93 -0
- data/website/scripts/shBrushDelphi.js +57 -0
- data/website/scripts/shBrushDiff.js +43 -0
- data/website/scripts/shBrushErlang.js +54 -0
- data/website/scripts/shBrushGroovy.js +69 -0
- data/website/scripts/shBrushJScript.js +52 -0
- data/website/scripts/shBrushJava.js +59 -0
- data/website/scripts/shBrushJavaFX.js +60 -0
- data/website/scripts/shBrushPerl.js +74 -0
- data/website/scripts/shBrushPhp.js +91 -0
- data/website/scripts/shBrushPlain.js +35 -0
- data/website/scripts/shBrushPowerShell.js +76 -0
- data/website/scripts/shBrushPython.js +66 -0
- data/website/scripts/shBrushRuby.js +57 -0
- data/website/scripts/shBrushScala.js +53 -0
- data/website/scripts/shBrushSql.js +68 -0
- data/website/scripts/shBrushVb.js +58 -0
- data/website/scripts/shBrushXml.js +71 -0
- data/website/scripts/shCore.js +30 -0
- data/website/scripts/shLegacy.js +30 -0
- data/website/styles/friendly.css +103 -0
- data/website/styles/help.png +0 -0
- data/website/styles/ie.css +35 -0
- data/website/styles/magnifier.png +0 -0
- data/website/styles/page_white_code.png +0 -0
- data/website/styles/page_white_copy.png +0 -0
- data/website/styles/print.css +29 -0
- data/website/styles/printer.png +0 -0
- data/website/styles/screen.css +257 -0
- data/website/styles/shCore.css +330 -0
- data/website/styles/shThemeDefault.css +173 -0
- data/website/styles/shThemeDjango.css +176 -0
- data/website/styles/shThemeEclipse.css +190 -0
- data/website/styles/shThemeEmacs.css +175 -0
- data/website/styles/shThemeFadeToGrey.css +177 -0
- data/website/styles/shThemeMidnight.css +175 -0
- data/website/styles/shThemeRDark.css +175 -0
- metadata +302 -383
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
test.rb
|
23
|
+
test_active_record.rb
|
24
|
+
spec/config.yml
|
25
|
+
.yardoc
|
26
|
+
doc
|
27
|
+
.bundle
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3
|
data/APACHE-LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/CHANGELOG.md
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ihoka-friendly (0.7.0)
|
5
|
+
activesupport (~> 2.3.18)
|
6
|
+
rufus-json (~> 0.2.3)
|
7
|
+
sequel (~> 3.16.0)
|
8
|
+
will_paginate (~> 2.3.15)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (2.3.18)
|
14
|
+
jferris-mocha (0.9.8.20100526112143)
|
15
|
+
rake
|
16
|
+
memcached (0.20.1)
|
17
|
+
mysql (2.8.1)
|
18
|
+
rake (10.1.0)
|
19
|
+
rspec (1.3.2)
|
20
|
+
rufus-json (0.2.7)
|
21
|
+
sequel (3.16.0)
|
22
|
+
will_paginate (2.3.16)
|
23
|
+
yajl-ruby (0.7.9)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
activesupport (~> 2.3.18)
|
30
|
+
ihoka-friendly!
|
31
|
+
jferris-mocha (~> 0.9.8.20100526112143)
|
32
|
+
memcached (~> 0.20.1)
|
33
|
+
mysql (~> 2.8.1)
|
34
|
+
rspec (~> 1.3.1)
|
35
|
+
rufus-json (~> 0.2.3)
|
36
|
+
sequel (~> 3.16.0)
|
37
|
+
will_paginate (~> 2.3.15)
|
38
|
+
yajl-ruby (~> 0.7.7)
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
Friendly
|
2
|
-
========
|
1
|
+
# Friendly
|
3
2
|
|
4
3
|
### Short Version
|
5
4
|
|
@@ -57,8 +56,7 @@ As is, our user model only supports queries by id.
|
|
57
56
|
|
58
57
|
Not great. We'd probably want to be able to query by name, at the very least.
|
59
58
|
|
60
|
-
Indexes
|
61
|
-
=======
|
59
|
+
## Indexes
|
62
60
|
|
63
61
|
To support richer queries, Friendly maintains its own indexes in separate tables. To index our user model on name, we'd create a table like this:
|
64
62
|
|
@@ -84,8 +82,7 @@ Any time friendly saves a user object, it will update the index as well. That wa
|
|
84
82
|
|
85
83
|
One of the big advantages to this approach is that indexes can be built offline. If you need a new index, you can write a script to generate it in the background without affecting the running application. Then, once it's ready, you can start querying it.
|
86
84
|
|
87
|
-
Caching
|
88
|
-
=======
|
85
|
+
## Caching
|
89
86
|
|
90
87
|
Friendly has built-in support for write-through caching.
|
91
88
|
|
@@ -112,8 +109,7 @@ Currently, only caching by id is supported, but caching of arbitrary indexes is
|
|
112
109
|
|
113
110
|
__We're seeing a 99.8% cache hit rate in production with this code.__
|
114
111
|
|
115
|
-
Scopes
|
116
|
-
======
|
112
|
+
## Scopes
|
117
113
|
|
118
114
|
### Named Scopes
|
119
115
|
|
@@ -167,8 +163,7 @@ You can also create a scope object on the fly:
|
|
167
163
|
|
168
164
|
The object you get is identical to the one you get from a named_scope. So, see above for the API.
|
169
165
|
|
170
|
-
Associations
|
171
|
-
============
|
166
|
+
## Associations
|
172
167
|
|
173
168
|
Friendly currently only supports has\_many associations.
|
174
169
|
|
@@ -204,8 +199,7 @@ You can also use any other Friendly::Scope method like scope chaining.
|
|
204
199
|
|
205
200
|
See the section above or the Friendly::Scope docs for more details.
|
206
201
|
|
207
|
-
Offline Indexing
|
208
|
-
================
|
202
|
+
## Offline Indexing
|
209
203
|
|
210
204
|
Friendly includes support for building an index in the background, without taking your app offline.
|
211
205
|
|
@@ -227,15 +221,13 @@ Now that the the new table has been created, you need to copy the .rake file inc
|
|
227
221
|
|
228
222
|
If you're running this in production, you'll probably want to fire up GNU screen so that it'll keep running even if you lose your SSH connection. When this task completes, the index is populated and ready to go!
|
229
223
|
|
230
|
-
Installation
|
231
|
-
============
|
224
|
+
## Installation
|
232
225
|
|
233
226
|
Friendly is available as a gem. Get it with:
|
234
227
|
|
235
|
-
|
228
|
+
gem install ihoka-friendly
|
236
229
|
|
237
|
-
Setup
|
238
|
-
=====
|
230
|
+
## Setup
|
239
231
|
|
240
232
|
All you have to do is supply Friendly with some information about your database:
|
241
233
|
|
@@ -268,8 +260,7 @@ Then, create some models, and run:
|
|
268
260
|
|
269
261
|
That'll create all the necessary tables as best it can. This has worked well enough for me, but it's possible that certain table configurations will fail. It won't attempt to create any tables that already exist, so it's safe to run in an initializer or something.
|
270
262
|
|
271
|
-
TODO
|
272
|
-
====
|
263
|
+
## TODO
|
273
264
|
|
274
265
|
- Online migrations. Add a version column to each model and a DSL to update schema from one version to another on read. This facilitates data transformations on the fly. If you want to transform the whole table at once, just iterate over all the objects, and save.
|
275
266
|
- Associations
|
@@ -277,10 +268,10 @@ TODO
|
|
277
268
|
- Caching of arbitrary indexes
|
278
269
|
- A lot more documentation
|
279
270
|
|
280
|
-
Credits
|
281
|
-
=======
|
271
|
+
## Credits
|
282
272
|
|
283
|
-
Friendly was developed by James Golick & Jonathan Palardy at FetLife (nsfw).
|
273
|
+
* Friendly was intially developed by James Golick & Jonathan Palardy at FetLife (nsfw).
|
274
|
+
* Rubygems, Bundler, Ruby and dependency upgrades by Istvan Hoka.
|
284
275
|
|
285
276
|
Copyright (c) 2009 James Golick. See LICENSE for details.
|
286
277
|
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
5
|
+
spec.libs << 'lib' << 'spec'
|
6
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
require 'rdoc/task'
|
12
|
+
Rake::RDocTask.new do |rdoc|
|
13
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
14
|
+
|
15
|
+
rdoc.rdoc_dir = 'rdoc'
|
16
|
+
rdoc.title = "friendly #{version}"
|
17
|
+
rdoc.rdoc_files.include('README*')
|
18
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Sync website."
|
22
|
+
task :website do
|
23
|
+
`rsync -avz website/* friendlyorm.com:/var/www/friendlyorm.com`
|
24
|
+
end
|
25
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.7.0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ihoka-friendly"
|
7
|
+
s.summary = %Q{NoSQL with MySQL in Ruby}
|
8
|
+
s.description = %Q{}
|
9
|
+
s.version = File.read(File.dirname(__FILE__) + '/VERSION')
|
10
|
+
s.email = "istvan.hoka@gmail.com"
|
11
|
+
s.homepage = "http://friendlyorm.com"
|
12
|
+
s.authors = ["James Golick", "Istvan Hoka"]
|
13
|
+
|
14
|
+
s.add_development_dependency 'mysql', '~> 2.8.1'
|
15
|
+
s.add_development_dependency 'activesupport', '~> 2.3.18'
|
16
|
+
s.add_development_dependency 'sequel', '~> 3.16.0'
|
17
|
+
s.add_development_dependency 'rufus-json', '~> 0.2.3'
|
18
|
+
s.add_development_dependency 'memcached', '~> 0.20.1'
|
19
|
+
s.add_development_dependency 'will_paginate', '~> 2.3.15'
|
20
|
+
s.add_development_dependency 'yajl-ruby', '~> 0.7.7'
|
21
|
+
s.add_development_dependency 'rspec', '~> 1.3.1'
|
22
|
+
s.add_development_dependency 'jferris-mocha', '~> 0.9.8.20100526112143'
|
23
|
+
s.add_dependency "sequel", "~> 3.16.0"
|
24
|
+
s.add_dependency "activesupport", "~> 2.3.18"
|
25
|
+
s.add_dependency "will_paginate", "~> 2.3.15"
|
26
|
+
s.add_dependency "rufus-json", "~> 0.2.3"
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
end
|
@@ -4,8 +4,8 @@ module Friendly
|
|
4
4
|
# FIXME: I'm not in love with this. But, I also don't think it's the
|
5
5
|
# end of the world.
|
6
6
|
def included(klass)
|
7
|
-
if klass.const_defined?(:ClassMethods)
|
8
|
-
klass.const_get(:ClassMethods).send(:include, const_get(:ClassMethods))
|
7
|
+
if klass.const_defined?(:ClassMethods, false)
|
8
|
+
klass.const_get(:ClassMethods, false).send(:include, const_get(:ClassMethods))
|
9
9
|
else
|
10
10
|
klass.send(:extend, const_get(:ClassMethods))
|
11
11
|
end
|
data/lib/friendly/indexer.rb
CHANGED
@@ -26,7 +26,7 @@ module Friendly
|
|
26
26
|
loop do
|
27
27
|
rows = datastore.all(klass, Query.new(:offset! => count,
|
28
28
|
:limit! => objects_per_iteration,
|
29
|
-
:order! => :added_id.asc))
|
29
|
+
:order! => :added_id.asc)).to_a
|
30
30
|
rows.each do |attrs|
|
31
31
|
begin
|
32
32
|
index.create(translator.to_object(klass, attrs))
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class DataStoreFake
|
2
|
+
attr_writer :insert, :all, :first
|
3
|
+
attr_reader :inserts, :updates
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
opts.each { |k,v| send("#{k}=", v) }
|
7
|
+
@inserts = []
|
8
|
+
@updates = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert(*args)
|
12
|
+
@inserts << args
|
13
|
+
@insert
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(*args)
|
17
|
+
@updates << args
|
18
|
+
@update
|
19
|
+
end
|
20
|
+
|
21
|
+
def all(*args)
|
22
|
+
@all[args]
|
23
|
+
end
|
24
|
+
|
25
|
+
def first(*args)
|
26
|
+
@first[args]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class DatasetFake
|
2
|
+
attr_accessor :where, :insert, :inserts, :update, :updates, :first
|
3
|
+
|
4
|
+
def initialize(opts = {})
|
5
|
+
opts.each { |k,v| send("#{k}=", v) }
|
6
|
+
@inserts ||= []
|
7
|
+
@updates ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
def where(conditions)
|
11
|
+
@where.detect { |k,v| k == conditions }.last
|
12
|
+
end
|
13
|
+
|
14
|
+
def insert(attributes)
|
15
|
+
inserts << attributes
|
16
|
+
@insert
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(attributes)
|
20
|
+
updates << attributes
|
21
|
+
@update
|
22
|
+
end
|
23
|
+
|
24
|
+
def first(conditions)
|
25
|
+
@first.detect { |k,v| k == conditions }.last
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FakeDocument
|
2
|
+
attr_accessor :id, :created_at, :to_hash, :new_record, :table_name,
|
3
|
+
:indexes, :name, :updated_at, :where_clause
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
opts.each { |k,v| send("#{k}=", v) }
|
7
|
+
new_record = true if new_record.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def new_record?
|
11
|
+
new_record
|
12
|
+
end
|
13
|
+
|
14
|
+
def attributes=(attrs)
|
15
|
+
attrs.each { |k,v| send("#{k}=", v) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Querying with an ad-hoc scope" do
|
4
|
+
before do
|
5
|
+
User.all(:name => "Fred").each { |u| u.destroy }
|
6
|
+
@users = (1..10).map { User.create(:name => "Fred") }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can return all the objects matching the scope" do
|
10
|
+
User.scope(:name => "Fred").all.should == @users
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can return the first object matching the scope" do
|
14
|
+
User.scope(:name => "Fred").first.should == User.first(:name => "Fred")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can paginate over the matching objects" do
|
18
|
+
found = User.scope(:name => "Fred").paginate(:per_page! => 5)
|
19
|
+
found.should == User.paginate(:name => "Fred", :per_page! => 5)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can build an object at scope" do
|
23
|
+
User.scope(:name => "Fred", :limit! => 5).build.name.should == "Fred"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "supports overriding parameters when building" do
|
27
|
+
scope = User.scope(:name => "Fred", :limit! => 5)
|
28
|
+
scope.build(:name => "Joe").name.should == "Joe"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can create an object at scope" do
|
32
|
+
user = User.scope(:name => "Joe").create
|
33
|
+
user.should_not be_new_record
|
34
|
+
user.name.should == "Joe"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "supports overriding parameters when creating" do
|
38
|
+
user = User.scope(:name => "Joe").create(:name => "Fred")
|
39
|
+
user.should_not be_new_record
|
40
|
+
user.name.should == "Fred"
|
41
|
+
end
|
42
|
+
end
|