Module: Customize::Inherited::ClassMethods

Defined in:
lib/customize/inherited.rb

Instance Method Summary collapse

Instance Method Details

#rootObject



45
46
47
# File 'lib/customize/inherited.rb', line 45

def root
  joins(:inherit_node).where("parent_id is null")
end

#type_tree(node = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/customize/inherited.rb', line 49

def type_tree node = nil
  roots = root
  converter = proc {|items, node|
    out = items.select { |item|
      node.nil? || (item.inherit_node.id != node.id && 
        (node.parent_node.nil? || item.inherit_node.id != node.parent_node.id))
    }.collect { |item|
      {:id=>item.id,:label=>item.label,:inherit_node_id=>item.inherit_node.id, :children=>converter.call(item.children, node)}
    }
  }
  
  converter.call(roots, node)
end