Class: Dolphin::Models::Cassandra::Event

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

Constant Summary collapse

COLUMN_FAMILY =
'events'.freeze
ROW_KEY =
'history'.freeze

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::Cassandra::Base

Instance Method Details

#get(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dolphin/models/cassandra/event.rb', line 13

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

  db.get(COLUMN_FAMILY, ROW_KEY, options).collect do |event| {
    'id' => event[0].to_guid,
    'event' => MultiJson.load(event[1]),
    'created_at' => SimpleUUID::UUID.new(event[0].to_guid).to_time.iso8601
  }
  end
end

#put(event) ⇒ Object



33
34
35
36
37
38
# File 'lib/dolphin/models/cassandra/event.rb', line 33

def put(event)
  column_name = SimpleUUID::UUID.new(Time.now).to_guid
  value = MultiJson.dump(event[:messages])
  db.insert(COLUMN_FAMILY, ROW_KEY, {column_name => value})
  column_name
end