To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 04 / 043366b6d2160c545cba1a2e40dbe400262cc0d0.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.71 KB)

1 1296:038ba2d95de8 Chris
class Note < ActiveRecord::Base
2
  acts_as_nested_set :scope => [:notable_id, :notable_type]
3
end
4
5
class Default < ActiveRecord::Base
6
  self.table_name = 'categories'
7
  acts_as_nested_set
8
end
9
10
class ScopedCategory < ActiveRecord::Base
11
  self.table_name = 'categories'
12
  acts_as_nested_set :scope => :organization
13
end
14
15
class RenamedColumns < ActiveRecord::Base
16
  acts_as_nested_set :parent_column => 'mother_id', :left_column => 'red', :right_column => 'black'
17
end
18
19
class Category < ActiveRecord::Base
20
  acts_as_nested_set
21
22
  validates_presence_of :name
23
24
  # Setup a callback that we can switch to true or false per-test
25
  set_callback :move, :before, :custom_before_move
26
  cattr_accessor :test_allows_move
27
  @@test_allows_move = true
28
  def custom_before_move
29
    @@test_allows_move
30
  end
31
32
  def to_s
33
    name
34
  end
35
36
  def recurse &block
37
    block.call self, lambda{
38
      self.children.each do |child|
39
        child.recurse &block
40
      end
41
    }
42
  end
43
end
44
45
class Thing < ActiveRecord::Base
46
  acts_as_nested_set :counter_cache => 'children_count'
47
end
48
49
class DefaultWithCallbacks < ActiveRecord::Base
50
51
  self.table_name = 'categories'
52
53
  attr_accessor :before_add, :after_add, :before_remove, :after_remove
54
55
  acts_as_nested_set :before_add => :do_before_add_stuff,
56
    :after_add     => :do_after_add_stuff,
57
    :before_remove => :do_before_remove_stuff,
58
    :after_remove  => :do_after_remove_stuff
59
60
  private
61
62
    [ :before_add, :after_add, :before_remove, :after_remove ].each do |hook_name|
63
      define_method "do_#{hook_name}_stuff" do |child_node|
64
        self.send("#{hook_name}=", child_node)
65
      end
66
    end
67
68
end
69
70
class Broken < ActiveRecord::Base
71
  acts_as_nested_set
72
end