0
|
1 |
# -*- ruby -*-
|
|
2 |
#encoding: utf-8
|
|
3 |
|
|
4 |
require 'sequel/model'
|
|
5 |
|
|
6 |
require 'thingfish/mixins'
|
|
7 |
require 'thingfish/metastore/pggraph' unless defined?( Thingfish::Metastore::PgGraph )
|
|
8 |
|
|
9 |
|
|
10 |
### A row representing a relationship between two node objects.
|
|
11 |
###
|
|
12 |
class Thingfish::Metastore::PgGraph::Edge < Sequel::Model( :edges )
|
|
13 |
|
|
14 |
# Related resource associations
|
|
15 |
many_to_one :node, :key => :id_p
|
|
16 |
|
|
17 |
# Dataset methods
|
|
18 |
#
|
|
19 |
dataset_module do
|
|
20 |
#########
|
|
21 |
protected
|
|
22 |
#########
|
|
23 |
|
|
24 |
### Returns a Sequel expression suitable for use as the key of a query against
|
|
25 |
### the specified property field.
|
|
26 |
###
|
|
27 |
def prop_expr( field )
|
|
28 |
return Sequel.pg_jsonb( :prop ).get_text( field.to_s )
|
|
29 |
end
|
|
30 |
end
|
|
31 |
|
|
32 |
|
|
33 |
### Do some initial attribute setup for new objects.
|
|
34 |
###
|
|
35 |
def initialize( * )
|
|
36 |
super
|
|
37 |
self[ :prop ] ||= Sequel.pg_jsonb({})
|
|
38 |
end
|
|
39 |
|
|
40 |
|
|
41 |
#########
|
|
42 |
protected
|
|
43 |
#########
|
|
44 |
|
|
45 |
### Proxy method -- fetch a value from the edge property hash if it exists.
|
|
46 |
###
|
|
47 |
def method_missing( sym, *args, &block )
|
|
48 |
return self.prop[ sym.to_s ] || super
|
|
49 |
end
|
|
50 |
|
|
51 |
end # Thingfish::Metastore::PgGraph::Edge
|
|
52 |
|