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

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Tree) initialize(model, validate_nodes)

Returns a new instance of Tree



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

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

Instance Attribute Details

- (Object) indices

Returns the value of attribute indices



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

def indices
  @indices
end

- (Object) model (readonly)

Returns the value of attribute model



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

def model
  @model
end

- (Object) validate_nodes (readonly)

Returns the value of attribute validate_nodes



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

def validate_nodes
  @validate_nodes
end

Instance Method Details

- (Object) rebuild!



18
19
20
21
22
23
24
25
26
27
# File 'lib/plugins/awesome_nested_set/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