vault-rails 0.0.9 → 0.0.10
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/lib/vault-rails/version.rb
CHANGED
@@ -12,10 +12,6 @@ class Vault
|
|
12
12
|
# This property is used to temporarily lock the vault during mutation methods.
|
13
13
|
@locked = false
|
14
14
|
|
15
|
-
# Create a date object which will be used to
|
16
|
-
# generate unique IDs for new records.
|
17
|
-
@date = new Date
|
18
|
-
|
19
15
|
# Declare default options.
|
20
16
|
@options =
|
21
17
|
autoload: true
|
@@ -23,6 +19,10 @@ class Vault
|
|
23
19
|
id_attribute: "id"
|
24
20
|
offline: false
|
25
21
|
sub_collections: []
|
22
|
+
|
23
|
+
# Declare an array used to track ids that are in use,
|
24
|
+
# so as to prevent duplicates when generating new ones.
|
25
|
+
@ids_in_use = []
|
26
26
|
|
27
27
|
# Merge default options with user-defined ones.
|
28
28
|
for option, value of options
|
@@ -128,7 +128,7 @@ class Vault
|
|
128
128
|
|
129
129
|
# If the object has no id, generate a temporary one and add it to the object.
|
130
130
|
unless object[@options.id_attribute]? and object[@options.id_attribute] isnt ''
|
131
|
-
object[@options.id_attribute] = @
|
131
|
+
object[@options.id_attribute] = @generate_id()
|
132
132
|
|
133
133
|
# Extend the object with vault-specific variables and functions.
|
134
134
|
@extend object,"new"
|
@@ -477,7 +477,7 @@ class Vault
|
|
477
477
|
|
478
478
|
# If the sub-object has no id, generate a temporary one and add it to the sub-object.
|
479
479
|
unless sub_object[@options.id_attribute]? and sub_object[@options.id_attribute] isnt ''
|
480
|
-
sub_object[@options.id_attribute] = @
|
480
|
+
sub_object[@options.id_attribute] = @generate_id()
|
481
481
|
|
482
482
|
# Add a delete method to the sub-object.
|
483
483
|
sub_object.delete = =>
|
@@ -609,6 +609,21 @@ class Vault
|
|
609
609
|
new_instance[key] = @clone object[key]
|
610
610
|
|
611
611
|
return new_instance
|
612
|
+
|
613
|
+
# Generate a new unique (within the set of generated ids) id.
|
614
|
+
generate_id: ->
|
615
|
+
until id_is_available
|
616
|
+
# Generate a new id and assume it's available.
|
617
|
+
id = new Date().getTime()
|
618
|
+
id_is_available = true
|
619
|
+
|
620
|
+
# Flag the new id as unavailable if it's taken.
|
621
|
+
id_is_available = false for taken in @ids_in_use when id is taken
|
622
|
+
|
623
|
+
# Store the new id so that it's not used again.
|
624
|
+
@ids_in_use.push id
|
625
|
+
|
626
|
+
return id
|
612
627
|
|
613
628
|
# Attach the Vault class to the window so that it can be used by other scripts.
|
614
629
|
window.Vault = this
|
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.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-04 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Store and manage collections of objects without a connection.
|
15
15
|
email:
|