Class: Hari::Node::Queries::Relation
- Inherits:
-
Object
- Object
- Hari::Node::Queries::Relation
show all
- Includes:
- Runnable, Step
- Defined in:
- lib/hari/node/queries/relation.rb,
lib/hari/node/queries/relation/step.rb,
lib/hari/node/queries/relation/start.rb,
lib/hari/node/queries/relation/runnable.rb,
lib/hari/node/queries/relation/backend/sorted_set.rb
Defined Under Namespace
Modules: Backend, Runnable, Step
Classes: Start
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Runnable
#result
Constructor Details
#initialize(parent, direction, relation, *args) ⇒ Relation
Returns a new instance of Relation.
17
18
19
20
21
22
23
24
|
# File 'lib/hari/node/queries/relation.rb', line 17
def initialize(parent, direction, relation, *args)
@parent, @direction, @relation = parent, direction, relation
@level = parent.level + 1
@options = {}
args..each { |k, v| send k, v }
@options[:backend] = args.first.presence || Backend::SortedSet
end
|
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
13
14
15
|
# File 'lib/hari/node/queries/relation.rb', line 13
def direction
@direction
end
|
#level ⇒ Object
Returns the value of attribute level.
13
14
15
|
# File 'lib/hari/node/queries/relation.rb', line 13
def level
@level
end
|
#options ⇒ Object
Returns the value of attribute options.
13
14
15
|
# File 'lib/hari/node/queries/relation.rb', line 13
def options
@options
end
|
#parent ⇒ Object
Returns the value of attribute parent.
13
14
15
|
# File 'lib/hari/node/queries/relation.rb', line 13
def parent
@parent
end
|
#relation ⇒ Object
Also known as:
name
Returns the value of attribute relation.
13
14
15
|
# File 'lib/hari/node/queries/relation.rb', line 13
def relation
@relation
end
|
Instance Method Details
#backend ⇒ Object
26
27
28
|
# File 'lib/hari/node/queries/relation.rb', line 26
def backend
options[:backend]
end
|
#calculate_limit ⇒ Object
30
31
32
|
# File 'lib/hari/node/queries/relation.rb', line 30
def calculate_limit
options[:limit] || -1
end
|
#call(final = true) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/hari/node/queries/relation.rb', line 78
def call(final = true)
if level == 1
backend.fetch parent.node, call_args(final)
else
backend.step start_node, parent.call(false), call_args(final)
end
end
|
#call_args(final = true) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/hari/node/queries/relation.rb', line 86
def call_args(final = true)
{
relation: relation,
direction: direction,
limit: calculate_limit,
from: options[:from],
step: options[:step],
result: result_type(final)
}
end
|
#count ⇒ Object
69
70
71
72
|
# File 'lib/hari/node/queries/relation.rb', line 69
def count
options[:result_type] = :count
result
end
|
#from(score, direction = nil) ⇒ Object
41
42
43
44
45
|
# File 'lib/hari/node/queries/relation.rb', line 41
def from(score, direction = nil)
direction ||= :up
options[:from] = { score: score, direction: direction.to_s }
self
end
|
#result_type(final = false) ⇒ Object
97
98
99
100
101
|
# File 'lib/hari/node/queries/relation.rb', line 97
def result_type(final = false)
return :nodes_ids unless final
options.fetch :result_type, :nodes
end
|
#start_node ⇒ Object
74
75
76
|
# File 'lib/hari/node/queries/relation.rb', line 74
def start_node
level == 1 ? parent.node : parent.start_node
end
|
#type(name) ⇒ Object
63
64
65
66
67
|
# File 'lib/hari/node/queries/relation.rb', line 63
def type(name)
fail 'type not supported for chained queries' if level > 1
Type.new self, name
end
|