Module: ActiveRecord::Acts::MaterializedPath::SingletonMethods

Defined in:
lib/acts_as_materialized_path.rb

Instance Method Summary collapse

Instance Method Details

#delete(id) ⇒ Object

FIXME - handle arrays of ids



169
170
171
172
173
# File 'lib/acts_as_materialized_path.rb', line 169

def delete(id)
  transaction do
    inner_delete(id) + super(id)
  end
end

#inner_delete(id) ⇒ Object

:nodoc:



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/acts_as_materialized_path.rb', line 156

def inner_delete(id)#:nodoc:
  c = find(id, :select => mp_column)
rescue RecordNotFound then
  return 0
else
  count = 0
  c.children.each do |child|
    count += self.delete(child.id)
  end
  return count
end

#num2path_string(num) ⇒ Object

:nodoc:

Raises:



138
139
140
141
142
143
144
145
# File 'lib/acts_as_materialized_path.rb', line 138

def num2path_string(num)#:nodoc:
  str = num.to_s(mp_base)
  len = str.length

  raise PathMaxExceeded unless len <= mp_places

  '0'*(mp_places-len)+str
end

#rootsObject



133
134
135
# File 'lib/acts_as_materialized_path.rb', line 133

def roots
  siblings('')
end

#siblings(path, select = '*') ⇒ Object

utility funtion to return a set of siblings



148
149
150
151
152
153
154
# File 'lib/acts_as_materialized_path.rb', line 148

def siblings(path, select = '*')
  find( :all,
        :select => select,
        :conditions =>
        [ mp_like, path + '_' * mp_places + mp_delimiter],
        :order => mp_asc )
end