vault-rails 0.0.6 → 0.0.7

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.
@@ -1,5 +1,5 @@
1
1
  module Vault
2
2
  module Rails
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -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 == "clean"
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="clean") ->
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: