matic_timestamp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ Mongomatic::Plugins::Timestamps
2
+
3
+ matic_timestamp is a plugin for Mongomatic to automatically add created_at and updated_at
4
+
5
+ Usage
6
+
7
+ require 'matic_timestamp'
8
+
9
+ class Monkey < Mongomatic::Base
10
+ include Mongomatic::Plugins::Timestamps
11
+ end
12
+
13
+ m = Monkey.new
14
+ m.insert
15
+ Monkey.find_one.created_at # Time object
16
+ m.update
17
+ Monkey.find_one.updated_at # More recent Time object
@@ -0,0 +1,19 @@
1
+ class TimestampObserver < Mongomatic::Observer
2
+ def before_insert(instance, opts)
3
+ instance[:created_at] = Time.now.utc
4
+ end
5
+ def before_insert_or_update(instance, opts)
6
+ instance[:updated_at] = Time.now.utc
7
+ end
8
+ end
9
+
10
+ module Mongomatic
11
+ module Plugins
12
+ module Timestamps
13
+ def self.included(base)
14
+ base.send(:include, Mongomatic::Observable)
15
+ base.send(:observer, :TimestampObserver)
16
+ end
17
+ end
18
+ end
19
+ end
File without changes
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matic_timestamp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Dusty Doris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-19 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Plugin for Mongomatic to automatically add created_at and updated_at
18
+ email: github@dusty.name
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.txt
25
+ files:
26
+ - README.txt
27
+ - lib/matic_timestamp.rb
28
+ - test/test_matic_timestamp.rb
29
+ has_rdoc: true
30
+ homepage: http://github.com/dusty/matic_timestamp
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ requirements: []
51
+
52
+ rubyforge_project: none
53
+ rubygems_version: 1.6.2
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Plugin for Mongomatic to automatically add created_at and updated_at
57
+ test_files: []
58
+