Module: Nelumba::Object

Included in:
Activity
Defined in:
lib/nelumba-mongodb/object.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nelumba-mongodb/object.rb', line 3

def self.included(klass)
  klass.class_eval do
    include MongoMapper::Document

    def initialize(*args, &blk)
      init(*args, &blk)

      super(*args, &blk)
    end

    # Ensure writes happen (lol mongo defaults)
    safe

    belongs_to :author, :class_name => 'Nelumba::Person'
    key :author_id, ObjectId

    key :title
    key :uid
    key :url
    key :display_name
    key :summary
    key :content
    key :image

    key :text
    key :html

    # Automated Timestamps
    key :published, Time
    key :updated,   Time
    before_save :update_timestamps

    def update_timestamps
      now = Time.now.utc
      self[:published] ||= now if !persisted?
      self[:updated]     = now
    end
  end
end