better_nested_set 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +12 -0
- data/Gemfile.lock +18 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +224 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/app/helpers/better_nested_set_helper.rb +121 -0
- data/better_nested_set.gemspec +75 -0
- data/lib/better_nested_set.rb +16 -0
- data/lib/symetrie_com/acts_as_better_nested_set.rb +1130 -0
- data/pkg/better_nested_set-0.1.0.gem +0 -0
- data/test/RUNNING_UNIT_TESTS +1 -0
- data/test/abstract_unit.rb +25 -0
- data/test/acts_as_nested_set_test.rb +1368 -0
- data/test/database.yml +15 -0
- data/test/fixtures/mixin.rb +33 -0
- data/test/fixtures/mixins.yml +66 -0
- data/test/mysql.rb +2 -0
- data/test/postgresql.rb +2 -0
- data/test/schema.rb +12 -0
- data/test/sqlite3.rb +2 -0
- metadata +141 -0
data/test/database.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
mysql:
|
2
|
+
:adapter: mysql
|
3
|
+
:host: localhost
|
4
|
+
:username: rails
|
5
|
+
:password:
|
6
|
+
:database: acts_as_nested_set_plugin_test
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:host: localhost
|
10
|
+
:username: rails
|
11
|
+
:password:
|
12
|
+
:database: acts_as_nested_set_plugin_test
|
13
|
+
sqlite3:
|
14
|
+
:adapter: sqlite3
|
15
|
+
:dbfile: test/acts_as_nested_set_plugin_test.db
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Mixin < ActiveRecord::Base
|
2
|
+
belongs_to :parent_node, :class_name => 'Mixin', :foreign_key => 'parent_id'
|
3
|
+
end
|
4
|
+
|
5
|
+
class NestedSet < Mixin
|
6
|
+
acts_as_nested_set :scope => "mixins.root_id IS NULL"
|
7
|
+
end
|
8
|
+
|
9
|
+
class NestedSetWithStringScope < Mixin
|
10
|
+
acts_as_nested_set :scope => 'mixins.root_id = #{root_id}'
|
11
|
+
end
|
12
|
+
|
13
|
+
class NS1 < NestedSetWithStringScope
|
14
|
+
end
|
15
|
+
|
16
|
+
class NS2 < NS1
|
17
|
+
my_callbacks = [:before_create, :before_save, :before_update, :before_destroy,
|
18
|
+
:after_create, :after_save, :after_update, :after_destroy]
|
19
|
+
my_callbacks.each do |sym|
|
20
|
+
define_method(sym) do
|
21
|
+
$callbacks ||= []
|
22
|
+
$callbacks << sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class NestedSetWithSymbolScope < Mixin
|
28
|
+
acts_as_nested_set :scope => :root
|
29
|
+
end
|
30
|
+
|
31
|
+
class Category < Mixin
|
32
|
+
acts_as_nested_set
|
33
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Nested set mixins
|
2
|
+
|
3
|
+
<% (1..10).each do |counter| %>
|
4
|
+
set_<%= counter %>:
|
5
|
+
id: <%= counter+3000 %>
|
6
|
+
type: NestedSet
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
# Big old set
|
10
|
+
<%
|
11
|
+
[[4001, 0, 1, 20],
|
12
|
+
[4002, 4001, 2, 7],
|
13
|
+
[4003, 4002, 3, 4],
|
14
|
+
[4004, 4002, 5, 6],
|
15
|
+
[4005, 4001, 8, 13],
|
16
|
+
[4006, 4005, 9, 10],
|
17
|
+
[4007, 4005, 11, 12],
|
18
|
+
[4008, 4001, 14, 19],
|
19
|
+
[4009, 4008, 15, 16],
|
20
|
+
[4010, 4008, 17, 18]].each do |set| %>
|
21
|
+
tree_<%= set[0] %>:
|
22
|
+
id: <%= set[0]%>
|
23
|
+
parent_id: <%= set[1]%>
|
24
|
+
type: NestedSetWithStringScope
|
25
|
+
lft: <%= set[2]%>
|
26
|
+
rgt: <%= set[3]%>
|
27
|
+
root_id: 42
|
28
|
+
|
29
|
+
<% end %>
|
30
|
+
|
31
|
+
|
32
|
+
# Third group of nested set fixtures.
|
33
|
+
# the following schematic may help when working with this nested set:
|
34
|
+
# ____________________________________________________________________________________________________________
|
35
|
+
# | root_node |
|
36
|
+
# | _____________ _______________________________________ _________________________________________ |
|
37
|
+
# | | child_left | | child_middle | | child_right | |
|
38
|
+
# | | | | _________ _________ _________ | | _________ ___________________ | |
|
39
|
+
# | | | | | gc_1 | | gc_2 | | gc_3 | | | | gc_4 | | gc_5 | | |
|
40
|
+
# | | | | | | | | | | | | | | | ___________ | | |
|
41
|
+
# | | | | | | | | | | | | | | | | gg_child | | | |
|
42
|
+
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16________17 18 19 20
|
43
|
+
# | | | | |________| |________| |________| | | |________| |__________________| | |
|
44
|
+
# | |____________| |_______________________________________| |_______________________________________| |
|
45
|
+
# |___________________________________________________________________________________________________________|
|
46
|
+
<%
|
47
|
+
[ ["root_node", 101, 1, 1, 20, 0, "NS1"],
|
48
|
+
["child_left", 102, 1, 2, 3, 101, "NestedSetWithStringScope"],
|
49
|
+
["child_middle", 103, 3, 4, 11, 101, "NS2"],
|
50
|
+
["child_right", 104, 5, 12, 19, 101, "NestedSetWithStringScope"],
|
51
|
+
["gc_1", 105, 3, 5, 6, 103, "NestedSetWithStringScope"],
|
52
|
+
["gc_2", 106, 3, 7, 8, 103, "NestedSetWithStringScope"],
|
53
|
+
["gc_3", 107, 3, 9, 10, 103, "NestedSetWithStringScope"],
|
54
|
+
["gc_4", 108, 6, 13, 14, 104, "NS2"],
|
55
|
+
["gc_5", 109, 7, 15, 18, 104, "NS1"],
|
56
|
+
["gg_child", 110, 9, 16, 17, 109, "NestedSetWithStringScope"]].each do |set| %>
|
57
|
+
ns_<%= set[0] %>:
|
58
|
+
id: <%= set[1]%>
|
59
|
+
parent_id: <%= set[5]%>
|
60
|
+
pos: <%= set[2]%>
|
61
|
+
lft: <%= set[3]%>
|
62
|
+
rgt: <%= set[4]%>
|
63
|
+
root_id: 101
|
64
|
+
type: <%= set[6]%>
|
65
|
+
|
66
|
+
<% end %>
|
data/test/mysql.rb
ADDED
data/test/postgresql.rb
ADDED
data/test/schema.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
create_table :mixins, :force => true do |t|
|
3
|
+
t.column :parent_id, :integer
|
4
|
+
t.column :pos, :integer
|
5
|
+
t.column :created_at, :datetime
|
6
|
+
t.column :updated_at, :datetime
|
7
|
+
t.column :lft, :integer
|
8
|
+
t.column :rgt, :integer
|
9
|
+
t.column :root_id, :integer
|
10
|
+
t.column :type, :string
|
11
|
+
end
|
12
|
+
end
|
data/test/sqlite3.rb
ADDED
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: better_nested_set
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Bailey
|
14
|
+
- Jean-Christophe Michel
|
15
|
+
- Dirk Breuer
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2011-03-11 00:00:00 +01:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
type: :development
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 23
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
version: 1.0.0
|
36
|
+
name: bundler
|
37
|
+
version_requirements: *id001
|
38
|
+
prerelease: false
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
type: :development
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 7
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 5
|
50
|
+
- 2
|
51
|
+
version: 1.5.2
|
52
|
+
name: jeweler
|
53
|
+
version_requirements: *id002
|
54
|
+
prerelease: false
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
type: :development
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
name: rcov
|
67
|
+
version_requirements: *id003
|
68
|
+
prerelease: false
|
69
|
+
description: This plugin provides an enhanced acts_as_nested_set mixin for ActiveRecord, the object-relational mapping layer of the framework Ruby on Rails. The original nested set in Rails lacks many important features, such as moving branches within a tree.
|
70
|
+
email: dirk.breuer@gmail.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.rdoc
|
78
|
+
files:
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- VERSION
|
85
|
+
- app/helpers/better_nested_set_helper.rb
|
86
|
+
- better_nested_set.gemspec
|
87
|
+
- lib/better_nested_set.rb
|
88
|
+
- lib/symetrie_com/acts_as_better_nested_set.rb
|
89
|
+
- pkg/better_nested_set-0.1.0.gem
|
90
|
+
- test/RUNNING_UNIT_TESTS
|
91
|
+
- test/abstract_unit.rb
|
92
|
+
- test/acts_as_nested_set_test.rb
|
93
|
+
- test/database.yml
|
94
|
+
- test/fixtures/mixin.rb
|
95
|
+
- test/fixtures/mixins.yml
|
96
|
+
- test/mysql.rb
|
97
|
+
- test/postgresql.rb
|
98
|
+
- test/schema.rb
|
99
|
+
- test/sqlite3.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/railsbros-dirk/better_nested_set
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.5.0
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: This plugin provides an ehanced acts_as_nested_set mixin for ActiveRecord
|
134
|
+
test_files:
|
135
|
+
- test/abstract_unit.rb
|
136
|
+
- test/acts_as_nested_set_test.rb
|
137
|
+
- test/fixtures/mixin.rb
|
138
|
+
- test/mysql.rb
|
139
|
+
- test/postgresql.rb
|
140
|
+
- test/schema.rb
|
141
|
+
- test/sqlite3.rb
|