Module: Adocca::Acts::ActsAsFastNestedSet::InstanceMethods

Defined in:
lib/acts_as_fast_nested_set.rb

Instance Method Summary collapse

Instance Method Details

#descendantsObject

All our children and their children etc



152
153
154
155
156
157
158
# File 'lib/acts_as_fast_nested_set.rb', line 152

def descendants
  cache_value("#{self.class.name}:#{self.id}:descendants") do
    self.class.find(:all, 
                    :conditions => ["node_id LIKE ? AND id != ?#{unique_with_and}", 
                                    "#{self.node_id}%", self.id] + unique_params)
  end
end

#destroy_descendantsObject

Destroys all children and their children etc



137
138
139
140
141
142
# File 'lib/acts_as_fast_nested_set.rb', line 137

def destroy_descendants
  self.class.connection.delete(
      self.class.sanitizeSQL(
          ["DELETE FROM #{self.class.table_name} WHERE node_id LIKE ? AND id != ?#{unique_with_and}", 
           "#{self.node_id}%", self.id] + unique_params))
end

#get_uniqueness_keyObject

Get a String suitable for using as a Memcache lock when creating a nodeid.



116
117
118
119
120
121
122
123
124
125
# File 'lib/acts_as_fast_nested_set.rb', line 116

def get_uniqueness_key
  options = self.class.get_options
  uniqueness_key = "acts_as_fast_nested_set#{self.class.table_name}:nodeid_lock:"
  if options[:uniqueness_scope]
    options[:uniqueness_scope].each do |col|
      uniqueness_key << "#{self.send(col)}:"
    end
  end
  return uniqueness_key
end

#kinObject

Returns the entire thread



129
130
131
132
133
# File 'lib/acts_as_fast_nested_set.rb', line 129

def kin
  self.class.find(:all, :conditions => ["node_id LIKE ?#{unique_with_and}", 
                                        "#{root_id}.%"] + 
                                        unique_params)
end

#levelObject



160
161
162
163
164
165
166
# File 'lib/acts_as_fast_nested_set.rb', line 160

def level
  if self.node_id.nil?
    1
  else
    self.node_id.count "."
  end
end

#siblingsObject

All nodes with the same parent



146
147
148
# File 'lib/acts_as_fast_nested_set.rb', line 146

def siblings
  self.class.find_all_by_parent_id(self.parent_id)
end