dm-aspects 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77a91169bc5a83e7318913fdea269fcf5b3ff186
4
- data.tar.gz: e7e48625182f7285b3a9d5dcfdaa2e18db4f711c
3
+ metadata.gz: 76edcbc7c99910f52334bb2a686fca0346c68156
4
+ data.tar.gz: 79f3f4292a74babff405e208ce23a4dfb76de132
5
5
  SHA512:
6
- metadata.gz: d20d1431f8c1255ebe418706b40c36e6675d7b4dec2d46886f835f0ee0bd8f5791fbd0288326ee202edf21d9f4e66d47009fd8d7b830cdae7b062ae2eee1481a
7
- data.tar.gz: 8457cb7a73f440c810e981456b1fca67c2c271a535c6fb7e15455cf6757c1ec83e224c9ee98c584801a3dbcfb522dd10b1d58f973ce61e17f256568bf4ccf2be
6
+ metadata.gz: 3b7f4abd012ffe1d8fd88118e0bf9d1aeeac4ea74c614c41a4c4ce3451e2fecd3f34082360831bc940be77b4f45592018661ef5a3fabf8fcc7f87b348765c723
7
+ data.tar.gz: f4ecb216fcb3df27be1675e3b2a7281a4e84f8b3ceeca65259ec671a692bbb3b39d486c4b0f8afffa49346b9caf3b5b7e731d8f8657ba627fc25dcf258385497
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in dm-aspects.gemspec
4
2
  gemspec
3
+
4
+ gem 'moped', require: 'moped/bson'
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
- # => #<Game @id=1 @slug="my-slug">
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
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Aspects
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
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.2
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-01-11 00:00:00.000000000 Z
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.0
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.