Module: ChronicTree::ActiveRecord::Relation

Included in:
ChronicTree
Defined in:
lib/chronic_tree/active_record/relation.rb

Instance Method Summary collapse

Instance Method Details

#ancestors_relation(time_at, scope_name) ⇒ Object



27
28
29
30
31
# File 'lib/chronic_tree/active_record/relation.rb', line 27

def ancestors_relation(time_at, scope_name)
  existed_relation(time_at, scope_name).
    includes(:parent).
    order(:distance)
end

#children_relation(time_at, scope_name) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/chronic_tree/active_record/relation.rb', line 4

def children_relation(time_at, scope_name)
  send("elements_under_#{scope_name}_parent").
    at(time_at).
    direct.
    exclude_root.
    includes(:child)
end

#descendants_relation(time_at, scope_name) ⇒ Object



23
24
25
# File 'lib/chronic_tree/active_record/relation.rb', line 23

def descendants_relation(time_at, scope_name)
  children_relation(time_at, scope_name).order(:distance).all_distance
end

#existed_relation(time_at, scope_name) ⇒ Object



18
19
20
21
# File 'lib/chronic_tree/active_record/relation.rb', line 18

def existed_relation(time_at, scope_name)
  send("elements_as_#{scope_name}_child").
    at(time_at)
end

#parent_relation(time_at, scope_name) ⇒ Object



12
13
14
15
16
# File 'lib/chronic_tree/active_record/relation.rb', line 12

def parent_relation(time_at, scope_name)
  existed_relation(time_at, scope_name).
    direct.
    exclude_root
end