minidoc 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/minidoc/timestamps.rb +22 -0
- data/lib/minidoc/version.rb +1 -1
- data/spec/minidoc/timestamps_spec.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a39428fa02e34cc7687e65ebc52bda5a0dfa5417
|
4
|
+
data.tar.gz: 4bb38f83b40229e7709bb57689388cf8601671fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e03054151882676cae311c7967eac76b82461c7cf51eff00edac9edfec77ea8f61f7bb4476825d104150c7d44c5235e80aab8b9b626c3d9353fbf53300c1f12
|
7
|
+
data.tar.gz: ad3cf4397561d99fd462a2a42dbfe3a167a9b197566073480f8204b719bb349cb156bdd7ab11895929c7b8e77e69f17fa9966a6c7a766f78e23a803dcb8bcfdc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -15,8 +15,8 @@ things as simple as possible.
|
|
15
15
|
|
16
16
|
* Interact with Ruby objects instead of hashes
|
17
17
|
* Full access to the powerful MongoDB client
|
18
|
-
* Thread safe
|
19
|
-
* Simple and easily extensible
|
18
|
+
* Thread safe (hopefully)
|
19
|
+
* Simple and easily extensible
|
20
20
|
* ActiveModel-compatible
|
21
21
|
* Validations
|
22
22
|
* Timestamp tracking (created_at/updated_at)
|
data/lib/minidoc/timestamps.rb
CHANGED
@@ -15,6 +15,28 @@ module Minidoc::Timestamps
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def set(attributes)
|
19
|
+
if self.class.record_timestamps
|
20
|
+
super(attributes.merge(updated_at: Time.now.utc))
|
21
|
+
else
|
22
|
+
super(attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def atomic_set(query, attributes)
|
27
|
+
if self.class.record_timestamps
|
28
|
+
super(query, attributes.merge(updated_at: Time.now.utc))
|
29
|
+
else
|
30
|
+
super(query, attributes)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def unset(*keys)
|
35
|
+
super
|
36
|
+
|
37
|
+
set(updated_at: Time.now.utc) if self.class.record_timestamps
|
38
|
+
end
|
39
|
+
|
18
40
|
private
|
19
41
|
|
20
42
|
def create
|
data/lib/minidoc/version.rb
CHANGED
@@ -4,6 +4,8 @@ describe Minidoc::Timestamps do
|
|
4
4
|
class TimestampsUser < Minidoc
|
5
5
|
include Minidoc::Timestamps
|
6
6
|
|
7
|
+
attribute :name, String
|
8
|
+
|
7
9
|
timestamps!
|
8
10
|
end
|
9
11
|
|
@@ -20,5 +22,27 @@ describe Minidoc::Timestamps do
|
|
20
22
|
user.save
|
21
23
|
expect(user.created_at).to_not eq user.updated_at
|
22
24
|
end
|
25
|
+
|
26
|
+
it "updates updated_at when doc is changed with #set" do
|
27
|
+
user = TimestampsUser.create
|
28
|
+
sleep 0.001
|
29
|
+
user.set(name: "Abby Normal")
|
30
|
+
expect(user.created_at).to_not eq user.updated_at
|
31
|
+
end
|
32
|
+
|
33
|
+
it "updates updated_at when doc is changed with #atomic_set" do
|
34
|
+
user = TimestampsUser.create
|
35
|
+
sleep 0.001
|
36
|
+
user.atomic_set({ name: nil }, name: "Abby Normal")
|
37
|
+
expect(user.created_at).to_not eq user.updated_at
|
38
|
+
end
|
39
|
+
|
40
|
+
it "updates updated_at when doc is changed with #unset" do
|
41
|
+
user = TimestampsUser.create(name: "Abby Normal")
|
42
|
+
sleep 0.001
|
43
|
+
user.unset(:name)
|
44
|
+
expect(user.name).to be_nil
|
45
|
+
expect(user.created_at).to_not eq user.updated_at
|
46
|
+
end
|
23
47
|
end
|
24
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-10-
|
12
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|