Module: Exegesis::Document::ClassMethods

Defined in:
lib/exegesis/document.rb

Instance Method Summary collapse

Instance Method Details

#database(db = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/exegesis/document.rb', line 17

def database(db=nil)
  if db 
    if db.is_a?(Exegesis::Database::Singleton) || db.is_a?(Exegesis::Database)
      @database = db
    else
      raise ArgumentError, "please supply either an Exegesis::Database or Exegesis::Database::Singleton"
    end
  else
    @database
  end
end

#timestamps!Object



29
30
31
32
33
34
35
36
# File 'lib/exegesis/document.rb', line 29

def timestamps!
  define_method :set_timestamps do
    @attributes['updated_at'] = Time.now
    @attributes['created_at'] ||= Time.now
  end
  expose 'updated_at', :as => Time
  expose 'created_at', :as => Time
end

#unique_id(meth = nil, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/exegesis/document.rb', line 38

def unique_id meth=nil, &block
  if block
    @unique_id_method = block
  elsif meth
    @unique_id_method = meth
  else
    @unique_id_method ||= nil
  end
end