-
Notifications
You must be signed in to change notification settings - Fork 275
/
node_mixin.rb
66 lines (61 loc) · 1.71 KB
/
node_mixin.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module Neo4j
module NodeMixin
# Returns an enumeration of aggregates that this nodes belongs to.
#
# Is used in combination with the Neo4j::AggregateNodeMixin
#
# ==== Example
#
# class MyNode
# include Neo4j::NodeMixin
# include Neo4j::NodeAggregateMixin
# end
#
# agg1 = MyNode
# agg1.aggregate([node1,node2]).group_by(:colour)
#
# agg2 = MyNode
# agg2.aggregate([node1,node2]).group_by(:age)
#
# node1.aggregates.to_a # => [agg1, agg2]
#
def aggregates
Neo4j::Aggregate::AggregateEnum.new(self)
end
# Returns an enumeration of groups that this nodes belongs to.
#
# Is used in combination with the Neo4j::AggregateNodeMixin
#
# ==== Parameters
#
# * group which aggregate group we want, default is :all - an enumeration of all groups will be return
#
#
# ==== Returns
# an enumeration of all groups that this node belongs to, or if the group parameter was used
# only the given group or nil if not found.
#
# ==== Example
#
# class MyNode
# include Neo4j::NodeMixin
# include Neo4j::AggregateNodeMixin
# end
#
# agg1 = MyNode
# agg1.aggregate(:colours).group_by(:colour)
#
# agg2 = MyNode
# agg2.aggregate(:age).group_by(:age)
#
# agg1 << node1
# agg2 << node1
#
# node1.aggregate_groups.to_a # => [agg1[some_group], agg2[some_other_group]]
#
def aggregate_groups(group = :all)
return relationships.incoming(:aggregate).nodes if group == :all
relationships.incoming(:aggregate).filter{self[:aggregate_group] == group.to_s}.nodes.to_a[0]
end
end
end