Module: SortTree

Extended by:
ActiveSupport::Concern
Defined in:
lib/ztree/sort_tree.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#sorted_childrenObject



30
31
32
# File 'lib/ztree/sort_tree.rb', line 30

def sorted_children
  children.sort_by{|c| c.send(self.class.order_column)}
end

#sorted_children_idsObject



34
35
36
# File 'lib/ztree/sort_tree.rb', line 34

def sorted_children_ids
  sorted_children.inject([]) {|ids, c| ids << c.id} if !children.empty?
end

#update_order(num) ⇒ Object



42
43
44
# File 'lib/ztree/sort_tree.rb', line 42

def update_order(num)
  update_attribute(self.class.order_column, num)
end

#update_order_numberObject



38
39
40
# File 'lib/ztree/sort_tree.rb', line 38

def update_order_number
  update_order(parent ? parent.children.size + 1 : 0)
end

#update_sorted_numbers(numbers) ⇒ Object



46
47
48
49
# File 'lib/ztree/sort_tree.rb', line 46

def update_sorted_numbers(numbers)
  return false if numbers.size != children.size
  self.class.update_sorted_numbers(numbers)
end