Class: Dolphin::Models::Rdb::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/dolphin/models/rdb/event.rb

Instance Attribute Summary

Attributes inherited from Base

#db

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Dolphin::Models::Rdb::Base

Instance Method Details

#get(params) ⇒ Object



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
# File 'lib/dolphin/models/rdb/event.rb', line 9

def get(params)
  options = {
    :count => params[:count]
  }

  if params[:start_id]
    options[:start] = params[:start_id]
  elsif params[:start_time]
    options[:start] = params[:start_time]
  end

  if options[:start]
    event = db.find(:uuid => params[:start_id])
    h = {}
    h['id'] = event.uuid
    h['event'] = MultiJson.load(event.value)
    h['created_at'] = SimpleUUID::UUID.new(event.uuid).to_time.iso8601
    [h]
  else
    db.order(Sequel.desc(:id)).find_all.collect do |event| {
      'id' => event.uuid,
      'event' => MultiJson.load(event.value),
      'created_at' => SimpleUUID::UUID.new(event.uuid).to_time.iso8601
    }
    end
  end
end

#put(event) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/dolphin/models/rdb/event.rb', line 37

def put(event)
  d = db.new
  d.uuid = SimpleUUID::UUID.new(Time.now).to_guid
  d.value = MultiJson.dump(event[:messages])
  d.timestamp = DateTime.now
  d.save
  d.uuid
end