eyeballs 0.5.13 → 0.5.13.1
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/README.md +26 -12
- data/Rakefile +1 -1
- data/eyeballs.gemspec +1 -1
- data/src/drivers/jquery/adapters/o_O.rest.js +13 -13
- metadata +3 -2
data/README.md
CHANGED
@@ -115,7 +115,7 @@ You define a model by passing a name and function to the eyeballs ( o_O ) functi
|
|
115
115
|
You can now initialize an individual post:
|
116
116
|
|
117
117
|
var post = Post.initialize({title: 'My New Post'});
|
118
|
-
post.title
|
118
|
+
post.title //=> 'My New Post'
|
119
119
|
|
120
120
|
Not very exciting.
|
121
121
|
|
@@ -128,10 +128,11 @@ However, if you're familiar with Rails, you'll be familiar with the wonderful sy
|
|
128
128
|
Now, when you initialize a new Post, you can validate it, nice and easy:
|
129
129
|
|
130
130
|
var post = Post.initialize()
|
131
|
-
post.
|
132
|
-
|
133
|
-
|
134
|
-
|
131
|
+
post.valid()
|
132
|
+
post.errors // => [{
|
133
|
+
// field: 'title',
|
134
|
+
// message: 'title should be present',
|
135
|
+
// type: 'presence'}]
|
135
136
|
|
136
137
|
and so on, so forth. This will be very familiar to those who use Rails.
|
137
138
|
|
@@ -148,9 +149,18 @@ You can also add your own validations, again, similar to how Rails does things:
|
|
148
149
|
|
149
150
|
var post = Post.initialize()
|
150
151
|
post.save(function(saved_post){
|
151
|
-
post.errors
|
152
|
-
|
153
|
-
})
|
152
|
+
post.errors // => [{
|
153
|
+
// message: 'title should be present'}]
|
154
|
+
}) // yep, there's a save method too!
|
155
|
+
|
156
|
+
Even better, using the `invalid` callback:
|
157
|
+
|
158
|
+
post.save({
|
159
|
+
invalid: function(saved_post){
|
160
|
+
// you can assume:
|
161
|
+
saved_post.errors
|
162
|
+
}
|
163
|
+
})
|
154
164
|
|
155
165
|
When you want to find things:
|
156
166
|
|
@@ -172,7 +182,7 @@ And if you want to add your own methods:
|
|
172
182
|
})
|
173
183
|
|
174
184
|
var post = Post.initialize({title: "HUGE"})
|
175
|
-
post.title_downcased()
|
185
|
+
post.title_downcased() //=> 'huge'
|
176
186
|
|
177
187
|
Connecting to an adapter:
|
178
188
|
|
@@ -221,7 +231,7 @@ There are several ways to bind events to controller actions.
|
|
221
231
|
|
222
232
|
The simplest way to call controller actions is to bind them directly. From the above example, you can simply call:
|
223
233
|
|
224
|
-
PostsController.new()
|
234
|
+
o_O('PostsController').new()
|
225
235
|
|
226
236
|
...once you have initialized your controller.
|
227
237
|
|
@@ -261,7 +271,7 @@ and your controller:
|
|
261
271
|
|
262
272
|
o_O('PostsController', {
|
263
273
|
show: function(){
|
264
|
-
alert(o_O.params('id'))
|
274
|
+
alert(o_O.params('id')) //=> '1'
|
265
275
|
}
|
266
276
|
})
|
267
277
|
|
@@ -357,7 +367,11 @@ Running the tests
|
|
357
367
|
|
358
368
|
eyeballs.js uses QUnit for in-browser testing. Just load the files in the test directory in any browser to run them.
|
359
369
|
|
360
|
-
For the REST tests, you can use the included Sinatra app, `app.rb`. The tests expect it to be in a local virtual domain `http://
|
370
|
+
For the REST tests, you can use the included Sinatra app, `app.rb`. The tests expect it to be in a local virtual domain `http://localhost:4567`
|
371
|
+
|
372
|
+
Contributors
|
373
|
+
------------
|
374
|
+
- Anthony Eden ([aeden](/aeden))
|
361
375
|
|
362
376
|
About me
|
363
377
|
--------
|
data/Rakefile
CHANGED
data/eyeballs.gemspec
CHANGED
@@ -125,23 +125,23 @@ o_O.rest = {
|
|
125
125
|
var url = this.figure_url(options, model) + '/' + id;
|
126
126
|
var include_json_root = this.include_json_root(model)
|
127
127
|
$.get(url, function(response){
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
try{
|
129
|
+
if(typeof response === 'object')
|
130
|
+
{
|
131
|
+
var retrieved_object = response;
|
132
|
+
}
|
133
|
+
else
|
134
|
+
{
|
135
135
|
var retrieved_object = JSON.parse(response);
|
136
|
-
if(include_json_root)
|
137
|
-
{
|
138
|
-
retrieved_object = retrieved_object[model.model_name.underscore()]
|
139
|
-
}
|
140
136
|
}
|
141
|
-
|
142
|
-
|
137
|
+
if(include_json_root)
|
138
|
+
{
|
139
|
+
retrieved_object = retrieved_object[model.model_name.underscore()]
|
143
140
|
}
|
144
141
|
}
|
142
|
+
catch(e){
|
143
|
+
var retrieved_object = model.initialize({id: id});
|
144
|
+
}
|
145
145
|
if(typeof callback === 'function')
|
146
146
|
{
|
147
147
|
retrieved_object.new_record = false;
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eyeballs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 81
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
9
|
- 13
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 0.5.13.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Paul Campbell
|