Mercurial > pumpbridge
comparison src/edge.coffee @ 0:b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Thu, 05 Jun 2014 10:35:15 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b73191efc65b |
---|---|
1 # edge.coffee | |
2 # | |
3 # A network edge between users in OStatus or pump.io graph | |
4 # | |
5 # Copyright 2013, E14N (https://e14n.com/) | |
6 # | |
7 # Licensed under the Apache License, Version 2.0 (the "License"); | |
8 # you may not use this file except in compliance with the License. | |
9 # You may obtain a copy of the License at | |
10 # | |
11 # http://www.apache.org/licenses/LICENSE-2.0 | |
12 # | |
13 # Unless required by applicable law or agreed to in writing, software | |
14 # distributed under the License is distributed on an "AS IS" BASIS, | |
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
16 # See the License for the specific language governing permissions and | |
17 # limitations under the License. | |
18 | |
19 _ = require("underscore") | |
20 async = require("async") | |
21 DatabankObject = require("databank").DatabankObject | |
22 Edge = DatabankObject.subClass("edge") | |
23 | |
24 Edge.schema = | |
25 pkey: "from_to" | |
26 fields: [ | |
27 "from" | |
28 "to" | |
29 "created" | |
30 "received" | |
31 ] | |
32 indices: [ | |
33 "from" | |
34 "to" | |
35 ] | |
36 | |
37 Edge.beforeCreate = (props, callback) -> | |
38 if not props.from or not props.to | |
39 callback new Error("Need 'from' and 'to' in an edge'"), null | |
40 return | |
41 props.from_to = Edge.key(props.from, props.to) | |
42 props.received = Date.now() | |
43 callback null, props | |
44 return | |
45 | |
46 Edge::beforeSave = (callback) -> | |
47 edge = this | |
48 if not edge.from or not edge.to | |
49 callback new Error("Need 'from' and 'to' in an edge'"), null | |
50 return | |
51 edge.from_to = Edge.key(edge.from, edge.to) | |
52 edge.received = Date.now() unless edge.received | |
53 callback null | |
54 return | |
55 | |
56 Edge.key = (fromId, toId) -> | |
57 fromId + "→" + toId | |
58 | |
59 module.exports = Edge |