-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodel.rb
More file actions
41 lines (33 loc) · 700 Bytes
/
model.rb
File metadata and controls
41 lines (33 loc) · 700 Bytes
1
2
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
class Message
include DataMapper::Resource
property :id, Serial
property :owner, String
property :body, Text
property :created_at, Time
def to_json(*a)
{
'owner' => owner,
'body' => body,
'created_at' => created_at
}.to_json(*a)
end
end
class User
include DataMapper::Resource
property :id, Serial
property :username, String
def to_json(*a)
{ 'username' => username }.to_json(*a)
end
end
class StreamResponse
attr_accessor :type, :data, :body
def initialize(type, data)
@type = type
@data = data
end
def send(output)
output << "event: #{type.to_s}\n"
output << "data: #{data.to_json}\n\n"
end
end