vault-rails 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
data/lib/vault-rails/version.rb
CHANGED
@@ -38,10 +38,6 @@ class Vault
|
|
38
38
|
if @load()
|
39
39
|
if @dirty_object_count > 0
|
40
40
|
# Offline data loaded and modifications found; keep existing data.
|
41
|
-
|
42
|
-
# Extend the loaded objects with vault-specific variables and functions.
|
43
|
-
for object in @objects
|
44
|
-
@extend object
|
45
41
|
|
46
42
|
# Detach the callback to after_load so that the call to the
|
47
43
|
# vault constructor can complete/return, allowing any post-load code
|
@@ -363,9 +359,13 @@ class Vault
|
|
363
359
|
if localStorage.getItem(@name)
|
364
360
|
@objects = $.parseJSON(localStorage.getItem @name)
|
365
361
|
|
362
|
+
# Extend the loaded objects with vault-specific variables and functions.
|
363
|
+
for object in @objects
|
364
|
+
@extend object
|
365
|
+
|
366
366
|
# Calculate the number of dirty objects.
|
367
367
|
for object in @objects
|
368
|
-
unless object.status
|
368
|
+
unless object.status is "clean"
|
369
369
|
@dirty_object_count++
|
370
370
|
|
371
371
|
return true
|
@@ -383,10 +383,12 @@ class Vault
|
|
383
383
|
return true
|
384
384
|
|
385
385
|
# Extend an object with vault-specific variables and functions.
|
386
|
-
extend: (object, status
|
386
|
+
extend: (object, status) ->
|
387
|
+
# Validate the status argument.
|
388
|
+
if status?
|
389
|
+
throw "Invalid status specified: cannot extend object." unless status in ['clean', 'dirty', 'new']
|
387
390
|
|
388
391
|
# Add simple variables and methods.
|
389
|
-
object.status = status
|
390
392
|
object.update = (attributes) =>
|
391
393
|
@update(attributes, object.id)
|
392
394
|
object.delete = =>
|
@@ -396,6 +398,13 @@ class Vault
|
|
396
398
|
object.save = (after_save) =>
|
397
399
|
@save(object.id, after_save)
|
398
400
|
|
401
|
+
if status?
|
402
|
+
# Status has been explicitly defined; force it on the object.
|
403
|
+
object.status = status
|
404
|
+
else
|
405
|
+
# Default the object's status to clean if it doesn't exist.
|
406
|
+
object.status = "clean" unless object.status?
|
407
|
+
|
399
408
|
# Iterate through all of the sub-collections, and if present
|
400
409
|
# extend them with some basic functionality.
|
401
410
|
for sub_collection in @options.sub_collections
|