Class: CollectiveIdea::Acts::NestedSet::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_nested_set/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, validate_nodes) ⇒ Tree

Returns a new instance of Tree



12
13
14
15
16
# File 'lib/awesome_nested_set/tree.rb', line 12

def initialize(model, validate_nodes)
  @model = model
  @validate_nodes = validate_nodes
  @indices = {}
end

Instance Attribute Details

#indicesObject

Returns the value of attribute indices



6
7
8
# File 'lib/awesome_nested_set/tree.rb', line 6

def indices
  @indices
end

#modelObject (readonly)

Returns the value of attribute model



5
6
7
# File 'lib/awesome_nested_set/tree.rb', line 5

def model
  @model
end

#validate_nodesObject (readonly)

Returns the value of attribute validate_nodes



5
6
7
# File 'lib/awesome_nested_set/tree.rb', line 5

def validate_nodes
  @validate_nodes
end

Instance Method Details

#rebuild!Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/awesome_nested_set/tree.rb', line 18

def rebuild!
  # Don't rebuild a valid tree.
  return true if model.valid?

  root_nodes.each do |root_node|
    # setup index for this scope
    indices[scope_for_rebuild.call(root_node)] ||= 0
    set_left_and_rights(root_node)
  end
end