dm-aspects 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/lib/datamapper/aspects/bson_id.rb +30 -1
- data/lib/dm-aspects/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19d6a6eef086183c567938fcb7d963be0990ea05
|
4
|
+
data.tar.gz: b83bd9acf7e9e998638a39049f682be85c81fa56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe5f27486d39cf40804f6c678b59f241009be964b09b0138795256014feafab666a51c585767f4e64448b9cc5b2660dd707b489f5bf03f4f04515307a8bd9644
|
7
|
+
data.tar.gz: 39609270d6e706a806e49fc04a0e1bf98b64eb5e3a0e7f03a510c3af3c7de31badd19f7ac0d5632b0076ec3699a4cdcb3d9bcd8bbae7b8ce5e461b3d8c03070b
|
data/Rakefile
CHANGED
@@ -2,17 +2,46 @@
|
|
2
2
|
|
3
3
|
module DataMapper
|
4
4
|
module Aspects
|
5
|
+
# Public: Provides a valid BSON Object ID key property.
|
6
|
+
# Also validates that BSON IDs are valid object ids.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# my_obj.id.id_is_valid?
|
11
|
+
# # => true
|
12
|
+
#
|
13
|
+
# my_obj.id.id_generation_time
|
14
|
+
# # => 2014-05-09 06:07:00 UTC
|
5
15
|
module BSONID
|
6
16
|
def self.included(base)
|
17
|
+
# Public: Provides the default aspect's attributes.
|
7
18
|
base.property :id, String, length: 24, key: true, default: Moped::BSON::ObjectId.new.to_s
|
19
|
+
|
20
|
+
# Internal: Validates that the BSON ID is a valid object id.
|
8
21
|
base.validates_with_method :id, method: :id_is_valid?
|
9
22
|
|
23
|
+
# Public: Retrieves the generation time of the BSON Object ID.
|
24
|
+
#
|
25
|
+
# Examples
|
26
|
+
#
|
27
|
+
# id_generation_time()
|
28
|
+
# # => 2014-05-09 06:07:00 UTC
|
29
|
+
#
|
30
|
+
# Returns the generation time of the BSON Object ID as a String.
|
10
31
|
def id_generation_time
|
11
32
|
Moped::BSON::ObjectId.from_string(@id).generation_time
|
12
33
|
end
|
13
34
|
|
35
|
+
# Public: Checks if the ID is a valid BSON Object ID.
|
36
|
+
#
|
37
|
+
# Examples
|
38
|
+
#
|
39
|
+
# id_is_valid?()
|
40
|
+
# # => true
|
41
|
+
#
|
42
|
+
# Returns true if ID is valid, false if not.
|
14
43
|
def id_is_valid?
|
15
|
-
Moped::BSON::
|
44
|
+
Moped::BSON::ObjectId.legal?(@id)
|
16
45
|
end
|
17
46
|
end
|
18
47
|
end
|
data/lib/dm-aspects/version.rb
CHANGED