dm-aspects 0.0.2 → 0.0.3
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/Gemfile +2 -2
- data/README.md +37 -1
- data/lib/datamapper/aspects/bson_id.rb +20 -0
- data/lib/dm-aspects/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76edcbc7c99910f52334bb2a686fca0346c68156
|
4
|
+
data.tar.gz: 79f3f4292a74babff405e208ce23a4dfb76de132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b7f4abd012ffe1d8fd88118e0bf9d1aeeac4ea74c614c41a4c4ce3451e2fecd3f34082360831bc940be77b4f45592018661ef5a3fabf8fcc7f87b348765c723
|
7
|
+
data.tar.gz: f4ecb216fcb3df27be1675e3b2a7281a4e84f8b3ceeca65259ec671a692bbb3b39d486c4b0f8afffa49346b9caf3b5b7e731d8f8657ba627fc25dcf258385497
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,6 +14,42 @@ And then execute:
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
+
### DataMapper::Aspects::BSONID
|
18
|
+
|
19
|
+
Adds a primary key property called `:id` to your model that uses BSONID:
|
20
|
+
|
21
|
+
property :id, String, length: 24, key: true, default: Moped::BSON::ObjectId.new
|
22
|
+
|
23
|
+
Moped::BSON has been found to be the fastest BSON ObjectId library for ruby, so it
|
24
|
+
was chosen for ObjectID generation and validation. However, `dm-aspects` has not declared
|
25
|
+
this as a dependency, since all `dm-aspects` are optional (and declaring `moped` as a
|
26
|
+
dependency would drag a bunch of unwanted code in and slow down your boot up time).
|
27
|
+
|
28
|
+
As such, you to add this to you Gemfile before using this module:
|
29
|
+
|
30
|
+
````ruby
|
31
|
+
gem 'moped', require: 'moped/bson'
|
32
|
+
````
|
33
|
+
|
34
|
+
Example:
|
35
|
+
|
36
|
+
````ruby
|
37
|
+
class MyModel
|
38
|
+
include DataMapper::Resource
|
39
|
+
include DataMapper::Aspects::BSONID
|
40
|
+
|
41
|
+
# :id is added automatically
|
42
|
+
property :name
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
MyModel.create(name: 'Example')
|
47
|
+
# => #<MyModel @id="53673b2c89d50f5c7400001f" @name="Example">
|
48
|
+
````
|
49
|
+
|
50
|
+
---
|
51
|
+
|
52
|
+
|
17
53
|
### DataMapper::Aspects::Slug
|
18
54
|
|
19
55
|
Adds a `:slug` property to your model:
|
@@ -36,7 +72,7 @@ end
|
|
36
72
|
|
37
73
|
MyModel.create(slug: 'my-slug')
|
38
74
|
MyModel.find_by_slug('')
|
39
|
-
# => #<
|
75
|
+
# => #<MyModel @id=1 @slug="my-slug">
|
40
76
|
````
|
41
77
|
|
42
78
|
---
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
module Aspects
|
5
|
+
module BSONID
|
6
|
+
def self.included(base)
|
7
|
+
base.property :id, String, length: 24, key: true, default: Moped::BSON::ObjectId.new.to_s
|
8
|
+
base.validates_with_method :id, method: :id_is_valid?
|
9
|
+
|
10
|
+
def id_generation_time
|
11
|
+
Moped::BSON::ObjectId.from_string(@id).generation_time
|
12
|
+
end
|
13
|
+
|
14
|
+
def id_is_valid?
|
15
|
+
Moped::BSON::Objectid.legal?(@id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/dm-aspects/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-aspects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- StyleSeek Engineering Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dm-core
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- dm-aspects.gemspec
|
83
83
|
- lib/datamapper/aspects.rb
|
84
|
+
- lib/datamapper/aspects/bson_id.rb
|
84
85
|
- lib/datamapper/aspects/slug.rb
|
85
86
|
- lib/datamapper/aspects/status.rb
|
86
87
|
- lib/datamapper/aspects/utils.rb
|
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.2.
|
110
|
+
rubygems_version: 2.2.2
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Aspect-Oriented modules to add enhance your DataMapper models.
|