Module: IndexTree::ActsAsIndexedNode

Defined in:
lib/index_tree/acts_as_indexed_node.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_indexed_node(options = {}, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/index_tree/acts_as_indexed_node.rb', line 3

def acts_as_indexed_node(options={}, &block)
  if options[:root]
    include IndexTree::RootElement
  else
    include IndexTree::NodeElement
  end

  # Find what associations were defined in the given block
  # And set the child nodes
  if block_given?
    current_associations = reflections.keys
    yield
    associations_in_block = reflections.keys - current_associations
    child_nodes *associations_in_block
  end
end