Class: CollectiveIdea::Acts::NestedSet::Tree
- Inherits:
-
Object
- Object
- CollectiveIdea::Acts::NestedSet::Tree
- Defined in:
- lib/awesome_nested_set/tree.rb
Instance Attribute Summary collapse
-
#indices ⇒ Object
Returns the value of attribute indices.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#validate_nodes ⇒ Object
readonly
Returns the value of attribute validate_nodes.
Instance Method Summary collapse
-
#initialize(model, validate_nodes) ⇒ Tree
constructor
A new instance of Tree.
- #rebuild! ⇒ Object
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
#indices ⇒ Object
Returns the value of attribute indices.
6 7 8 |
# File 'lib/awesome_nested_set/tree.rb', line 6 def indices @indices end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/awesome_nested_set/tree.rb', line 5 def model @model end |
#validate_nodes ⇒ Object (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 28 |
# 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) reset_counter_cache(root_node) end end |