Module: Spider::Model::Tree
- Defined in:
- lib/spiderfw/model/mixins/tree.rb
Defined Under Namespace
Modules: ClassMethods, MapperMethods
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(model) ⇒ Object
5
6
7
8
|
# File 'lib/spiderfw/model/mixins/tree.rb', line 5
def self.included(model)
model.extend(ClassMethods)
model.mapper_include(MapperMethods)
end
|
Instance Method Details
#tree_all(element) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/spiderfw/model/mixins/tree.rb', line 10
def tree_all(element)
element = self.class.elements[element] unless element.is_a?(Element)
left_el = element.attributes[:tree_left]
right_el = element.attributes[:tree_right]
left = get(left_el)
right = get(right_el)
return nil unless (left && right)
c = Condition.and
c[left_el] = (left..right)
q = Query.new(c)
q.order_by(left_el) unless element.attributes[:order] == false
res = element.model.find(q)
return [] unless res
right_stack = []
res.each do |obj|
if (right_stack.length > 0)
right_stack.pop while (right_stack[right_stack.length-1] && right_stack[right_stack.length-1] < obj.get(right_el))
obj.set(element.attributes[:tree_depth], right_stack.length)
end
right_stack << obj.get(right_el)
end
return res
end
|