Module: CollectiveIdea::Acts::NestedSet::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb,
lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/movable.rb,
lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb,
lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/relatable.rb,
lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/rebuildable.rb,
lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb,
lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/transactable.rb
Defined Under Namespace
Modules: ClassMethods, Movable, Prunable, Rebuildable, Relatable, Transactable, Validatable
Instance Method Summary (collapse)
-
- (Boolean) child?
Returns true is this is a child node.
-
- (Boolean) leaf?
Returns true if this is the end of a branch.
-
- (Object) left(target = self)
Value of the left column.
-
- (Object) nested_set_scope(options = {})
All nested set queries should use this nested_set_scope, which performs finds on the base ActiveRecord class, using the :scope declared in the acts_as_nested_set declaration.
-
- (Object) parent_id(target = self)
Any instance method that returns a collection makes use of Rails 2.1's named_scope (which is bundled for Rails 2.0), so it can be treated as a finder.
-
- (Object) right(target = self)
Value of the right column.
-
- (Boolean) root?
Returns true if this is a root node.
- - (Object) to_text
Instance Method Details
- (Boolean) child?
Returns true is this is a child node
118 119 120 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 118 def child? !root? end |
- (Boolean) leaf?
Returns true if this is the end of a branch.
123 124 125 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 123 def leaf? persisted? && right.to_i - left.to_i == 1 end |
- (Object) left(target = self)
Value of the left column
103 104 105 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 103 def left(target = self) target[left_column_name] end |
- (Object) nested_set_scope(options = {})
All nested set queries should use this nested_set_scope, which performs finds on the base ActiveRecord class, using the :scope declared in the acts_as_nested_set declaration.
130 131 132 133 134 135 136 137 138 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 130 def nested_set_scope( = {}) if (scopes = Array([:scope])).any? [:conditions] = scopes.inject({}) do |conditions,attr| conditions.merge attr => self[attr] end end self.class.nested_set_scope end |
- (Object) parent_id(target = self)
Any instance method that returns a collection makes use of Rails 2.1's named_scope (which is bundled for Rails 2.0), so it can be treated as a finder.
category.self_and_descendants.count category.ancestors.find(:all, :conditions => "name like '%foo%'")
Value of the parent column
98 99 100 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 98 def parent_id(target = self) target[parent_column_name] end |
- (Object) right(target = self)
Value of the right column
108 109 110 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 108 def right(target = self) target[right_column_name] end |
- (Boolean) root?
Returns true if this is a root node.
113 114 115 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 113 def root? parent_id.nil? end |
- (Object) to_text
140 141 142 143 144 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb', line 140 def to_text self_and_descendants.map do |node| "#{'*'*(node.level+1)} #{node.id} #{node.to_s} (#{node.parent_id}, #{node.left}, #{node.right})" end.join("\n") end |