acts_as_better_tree 0.9.5 → 1.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f07221f4791cd4d8d7b787a5f3d1f9a68e014afd52a4d0154957ad8f52682e1e
4
+ data.tar.gz: 1191ba6ae360a58e740e47b62e02389953ad3a96d4f87c4199908ae9647f58e4
5
+ SHA512:
6
+ metadata.gz: 4839b18fe54fe6f09f85adcba967a0c3eb5972434320ec18592409795069f93932c1fa830a15b21c8d9a91f50905c7e1644cd5cced3bcced3a70ce9c99ccd70f
7
+ data.tar.gz: 891fe34801023abea508701c6c96b07365fe632237e9016eb367c64d836fd6f4bd8ff31b5cd7baef37e83243d7fae27ed4b6761bc73ad1cd3e3dc102ed5e4ca7
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in acts_as_better_tree.gemspec
4
4
  gemspec
5
- gem 'sqlite3'
6
5
  gem 'rspec'
7
6
  gem 'rails', ">= 3.2.5"
8
- gem "factory_girl"
7
+ gem "factory_girl"
8
+ gem "csv"
data/Gemfile.lock CHANGED
@@ -1,80 +1,180 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acts_as_better_tree (0.9.4)
4
+ acts_as_better_tree (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionmailer (3.2.7)
10
- actionpack (= 3.2.7)
11
- mail (~> 2.4.4)
12
- actionpack (3.2.7)
13
- activemodel (= 3.2.7)
14
- activesupport (= 3.2.7)
15
- builder (~> 3.0.0)
16
- erubis (~> 2.7.0)
17
- journey (~> 1.0.4)
18
- rack (~> 1.4.0)
19
- rack-cache (~> 1.2)
20
- rack-test (~> 0.6.1)
21
- sprockets (~> 2.1.3)
22
- activemodel (3.2.7)
23
- activesupport (= 3.2.7)
24
- builder (~> 3.0.0)
25
- activerecord (3.2.7)
26
- activemodel (= 3.2.7)
27
- activesupport (= 3.2.7)
28
- arel (~> 3.0.2)
29
- tzinfo (~> 0.3.29)
30
- activeresource (3.2.7)
31
- activemodel (= 3.2.7)
32
- activesupport (= 3.2.7)
33
- activesupport (3.2.7)
34
- i18n (~> 0.6)
35
- multi_json (~> 1.0)
36
- arel (3.0.2)
37
- builder (3.0.0)
9
+ actioncable (8.0.2)
10
+ actionpack (= 8.0.2)
11
+ activesupport (= 8.0.2)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ zeitwerk (~> 2.6)
15
+ actionmailbox (8.0.2)
16
+ actionpack (= 8.0.2)
17
+ activejob (= 8.0.2)
18
+ activerecord (= 8.0.2)
19
+ activestorage (= 8.0.2)
20
+ activesupport (= 8.0.2)
21
+ mail (>= 2.8.0)
22
+ actionmailer (8.0.2)
23
+ actionpack (= 8.0.2)
24
+ actionview (= 8.0.2)
25
+ activejob (= 8.0.2)
26
+ activesupport (= 8.0.2)
27
+ mail (>= 2.8.0)
28
+ rails-dom-testing (~> 2.2)
29
+ actionpack (8.0.2)
30
+ actionview (= 8.0.2)
31
+ activesupport (= 8.0.2)
32
+ nokogiri (>= 1.8.5)
33
+ rack (>= 2.2.4)
34
+ rack-session (>= 1.0.1)
35
+ rack-test (>= 0.6.3)
36
+ rails-dom-testing (~> 2.2)
37
+ rails-html-sanitizer (~> 1.6)
38
+ useragent (~> 0.16)
39
+ actiontext (8.0.2)
40
+ actionpack (= 8.0.2)
41
+ activerecord (= 8.0.2)
42
+ activestorage (= 8.0.2)
43
+ activesupport (= 8.0.2)
44
+ globalid (>= 0.6.0)
45
+ nokogiri (>= 1.8.5)
46
+ actionview (8.0.2)
47
+ activesupport (= 8.0.2)
48
+ builder (~> 3.1)
49
+ erubi (~> 1.11)
50
+ rails-dom-testing (~> 2.2)
51
+ rails-html-sanitizer (~> 1.6)
52
+ activejob (8.0.2)
53
+ activesupport (= 8.0.2)
54
+ globalid (>= 0.3.6)
55
+ activemodel (8.0.2)
56
+ activesupport (= 8.0.2)
57
+ activerecord (8.0.2)
58
+ activemodel (= 8.0.2)
59
+ activesupport (= 8.0.2)
60
+ timeout (>= 0.4.0)
61
+ activestorage (8.0.2)
62
+ actionpack (= 8.0.2)
63
+ activejob (= 8.0.2)
64
+ activerecord (= 8.0.2)
65
+ activesupport (= 8.0.2)
66
+ marcel (~> 1.0)
67
+ activesupport (8.0.2)
68
+ base64
69
+ benchmark (>= 0.3)
70
+ bigdecimal
71
+ concurrent-ruby (~> 1.0, >= 1.3.1)
72
+ connection_pool (>= 2.2.5)
73
+ drb
74
+ i18n (>= 1.6, < 2)
75
+ logger (>= 1.4.2)
76
+ minitest (>= 5.1)
77
+ securerandom (>= 0.3)
78
+ tzinfo (~> 2.0, >= 2.0.5)
79
+ uri (>= 0.13.1)
80
+ base64 (0.2.0)
81
+ benchmark (0.4.0)
82
+ bigdecimal (3.1.9)
83
+ builder (3.3.0)
84
+ concurrent-ruby (1.3.5)
85
+ connection_pool (2.5.0)
86
+ crass (1.0.6)
87
+ csv (3.3.3)
88
+ date (3.4.1)
38
89
  diff-lcs (1.1.3)
39
- erubis (2.7.0)
90
+ drb (2.2.1)
91
+ erubi (1.13.1)
40
92
  factory_girl (3.6.1)
41
93
  activesupport (>= 3.0.0)
42
- hike (1.2.1)
43
- i18n (0.6.0)
44
- journey (1.0.4)
45
- json (1.7.4)
46
- mail (2.4.4)
47
- i18n (>= 0.4.0)
48
- mime-types (~> 1.16)
49
- treetop (~> 1.4.8)
50
- mime-types (1.19)
51
- multi_json (1.3.6)
52
- polyglot (0.3.3)
53
- rack (1.4.1)
54
- rack-cache (1.2)
55
- rack (>= 0.4)
56
- rack-ssl (1.3.2)
57
- rack
58
- rack-test (0.6.1)
59
- rack (>= 1.0)
60
- rails (3.2.7)
61
- actionmailer (= 3.2.7)
62
- actionpack (= 3.2.7)
63
- activerecord (= 3.2.7)
64
- activeresource (= 3.2.7)
65
- activesupport (= 3.2.7)
66
- bundler (~> 1.0)
67
- railties (= 3.2.7)
68
- railties (3.2.7)
69
- actionpack (= 3.2.7)
70
- activesupport (= 3.2.7)
71
- rack-ssl (~> 1.3.2)
72
- rake (>= 0.8.7)
73
- rdoc (~> 3.4)
74
- thor (>= 0.14.6, < 2.0)
75
- rake (0.9.2.2)
76
- rdoc (3.12)
77
- json (~> 1.4)
94
+ globalid (1.2.1)
95
+ activesupport (>= 6.1)
96
+ i18n (1.14.7)
97
+ concurrent-ruby (~> 1.0)
98
+ io-console (0.8.0)
99
+ irb (1.15.2)
100
+ pp (>= 0.6.0)
101
+ rdoc (>= 4.0.0)
102
+ reline (>= 0.4.2)
103
+ logger (1.7.0)
104
+ loofah (2.24.0)
105
+ crass (~> 1.0.2)
106
+ nokogiri (>= 1.12.0)
107
+ mail (2.8.1)
108
+ mini_mime (>= 0.1.1)
109
+ net-imap
110
+ net-pop
111
+ net-smtp
112
+ marcel (1.0.4)
113
+ mini_mime (1.1.5)
114
+ mini_portile2 (2.8.8)
115
+ minitest (5.25.5)
116
+ net-imap (0.5.6)
117
+ date
118
+ net-protocol
119
+ net-pop (0.1.2)
120
+ net-protocol
121
+ net-protocol (0.2.2)
122
+ timeout
123
+ net-smtp (0.5.1)
124
+ net-protocol
125
+ nio4r (2.7.4)
126
+ nokogiri (1.18.7)
127
+ mini_portile2 (~> 2.8.2)
128
+ racc (~> 1.4)
129
+ pp (0.6.2)
130
+ prettyprint
131
+ prettyprint (0.2.0)
132
+ psych (5.2.3)
133
+ date
134
+ stringio
135
+ racc (1.8.1)
136
+ rack (3.1.12)
137
+ rack-session (2.1.0)
138
+ base64 (>= 0.1.0)
139
+ rack (>= 3.0.0)
140
+ rack-test (2.2.0)
141
+ rack (>= 1.3)
142
+ rackup (2.2.1)
143
+ rack (>= 3)
144
+ rails (8.0.2)
145
+ actioncable (= 8.0.2)
146
+ actionmailbox (= 8.0.2)
147
+ actionmailer (= 8.0.2)
148
+ actionpack (= 8.0.2)
149
+ actiontext (= 8.0.2)
150
+ actionview (= 8.0.2)
151
+ activejob (= 8.0.2)
152
+ activemodel (= 8.0.2)
153
+ activerecord (= 8.0.2)
154
+ activestorage (= 8.0.2)
155
+ activesupport (= 8.0.2)
156
+ bundler (>= 1.15.0)
157
+ railties (= 8.0.2)
158
+ rails-dom-testing (2.2.0)
159
+ activesupport (>= 5.0.0)
160
+ minitest
161
+ nokogiri (>= 1.6)
162
+ rails-html-sanitizer (1.6.2)
163
+ loofah (~> 2.21)
164
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
165
+ railties (8.0.2)
166
+ actionpack (= 8.0.2)
167
+ activesupport (= 8.0.2)
168
+ irb (~> 1.13)
169
+ rackup (>= 1.0.0)
170
+ rake (>= 12.2)
171
+ thor (~> 1.0, >= 1.2.2)
172
+ zeitwerk (~> 2.6)
173
+ rake (13.2.1)
174
+ rdoc (6.13.1)
175
+ psych (>= 4.0.0)
176
+ reline (0.6.1)
177
+ io-console (~> 0.5)
78
178
  rspec (2.11.0)
79
179
  rspec-core (~> 2.11.0)
80
180
  rspec-expectations (~> 2.11.0)
@@ -83,24 +183,29 @@ GEM
83
183
  rspec-expectations (2.11.2)
84
184
  diff-lcs (~> 1.1.3)
85
185
  rspec-mocks (2.11.1)
86
- sprockets (2.1.3)
87
- hike (~> 1.2)
88
- rack (~> 1.0)
89
- tilt (~> 1.1, != 1.3.0)
90
- sqlite3 (1.3.6)
91
- thor (0.15.4)
92
- tilt (1.3.3)
93
- treetop (1.4.10)
94
- polyglot
95
- polyglot (>= 0.3.1)
96
- tzinfo (0.3.33)
186
+ securerandom (0.4.1)
187
+ stringio (3.1.6)
188
+ thor (1.3.2)
189
+ timeout (0.4.3)
190
+ tzinfo (2.0.6)
191
+ concurrent-ruby (~> 1.0)
192
+ uri (1.0.3)
193
+ useragent (0.16.11)
194
+ websocket-driver (0.7.7)
195
+ base64
196
+ websocket-extensions (>= 0.1.0)
197
+ websocket-extensions (0.1.5)
198
+ zeitwerk (2.7.2)
97
199
 
98
200
  PLATFORMS
99
201
  ruby
100
202
 
101
203
  DEPENDENCIES
102
204
  acts_as_better_tree!
205
+ csv
103
206
  factory_girl
104
207
  rails (>= 3.2.5)
105
208
  rspec
106
- sqlite3
209
+
210
+ BUNDLED WITH
211
+ 2.6.5
data/README.md CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- Required fields are parent_id, root_id, csv_ids.
22
+ Required fields are parent_id, root_id, csv_ids.
23
23
 
24
24
  create_table :categories do |t|
25
25
  t.column :root_id, :integer
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
  t.column :name, :string
29
29
  end
30
30
 
31
- If upgrading from acts_as_tree just add root_id and csv_ids and run Category.tree_to_better_tree!
31
+ If upgrading from acts_as_tree just add root_id and csv_ids and run Category.tree_to_better_tree!
32
32
 
33
33
  class Category < ActiveRecord::Base
34
34
  acts_as_better_tree :order => "name"
@@ -1,3 +1,3 @@
1
1
  module ActsAsBetterTree
2
- VERSION = "0.9.5"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require "acts_as_better_tree/version"
2
- require "csv"
3
2
  module ActiveRecord
4
3
  module Acts
5
4
  module BetterTree
@@ -8,15 +7,31 @@ module ActiveRecord
8
7
  end
9
8
 
10
9
  module ClassMethods
11
- def acts_as_better_tree(options = {}, &b)
10
+ def acts_as_better_tree(options = {})
12
11
  configuration = {:order => "id ASC", :destroy_dependent => true }
13
12
  configuration.update(options) if options.is_a?(Hash)
14
13
 
15
- belongs_to :parent, :class_name => name, :foreign_key => :parent_id
16
- has_many :children, {:class_name => name, :foreign_key => :parent_id, :order => configuration[:order]}.merge(configuration[:destroy_dependent] ? {:dependent => :destroy} : {}), &b
17
- has_many :parents_children, {:class_name => name, :primary_key => :parent_id, :foreign_key => :parent_id, :order => configuration[:order]}, &b
18
- belongs_to :root, :class_name => name, :foreign_key => :root_id
19
- scope :roots, :order => configuration[:order], :conditions => {:parent_id => nil}
14
+ belongs_to :parent,
15
+ class_name: name,
16
+ foreign_key: :parent_id,
17
+ optional: true,
18
+ dependent: :destroy
19
+ has_many :children,
20
+ -> { order(configuration[:order]) },
21
+ class_name: name,
22
+ foreign_key: :parent_id,
23
+ dependent: configuration[:destroy_dependent] ? :destroy : nil
24
+ has_many :parents_children,
25
+ -> { order(configuration[:order]) },
26
+ class_name: name,
27
+ primary_key: :parent_id,
28
+ foreign_key: :parent_id
29
+ belongs_to :root,
30
+ class_name: name,
31
+ foreign_key: :root_id,
32
+ optional: true,
33
+ dependent: :destroy
34
+ scope :roots, -> {order(configuration[:order]).where(:parent_id => nil)}
20
35
  after_create :assign_csv_ids
21
36
  after_validation :update_csv_ids, :on => :update
22
37
 
@@ -116,11 +131,11 @@ module ActiveRecord
116
131
  end
117
132
 
118
133
  def move_to_child_of(category)
119
- self.update_attributes(:parent_id => category.id)
134
+ self.update(parent_id: category.id)
120
135
  end
121
136
 
122
137
  def make_root
123
- self.update_attributes(:parent_id => nil)
138
+ self.update(parent_id: nil)
124
139
  end
125
140
 
126
141
  def to_csv(nodes = self.children)
@@ -157,27 +172,21 @@ module ActiveRecord
157
172
  end
158
173
 
159
174
  def assign_csv_ids
160
- self.update_attributes(:csv_ids => build_csv_ids, :root_id => build_root_id)
175
+ self.update(csv_ids: build_csv_ids, root_id: build_root_id)
161
176
  end
162
177
 
163
178
  def update_csv_ids
164
- return unless parent_foreign_key_changed?
179
+ return unless parent_foreign_key_changed?
165
180
  old_csv_ids = self.csv_ids
166
181
  self.csv_ids = build_csv_ids
167
182
  self.root_id = build_root_id
168
- self.class.update_all("csv_ids = Replace(csv_ids, '#{old_csv_ids},', '#{self.csv_ids},'), root_id = #{self.root_id}", "csv_ids like '#{old_csv_ids},%'")
183
+ self.class.where("csv_ids like '#{old_csv_ids},%'").update_all("csv_ids = Replace(csv_ids, '#{old_csv_ids},', '#{self.csv_ids},'), root_id = #{self.root_id}") unless self.new_record?
169
184
  end
170
185
  end
171
186
  end
172
187
  end
173
188
  end
174
189
 
175
- #ActiveRecord::Base.send :include, ActiveRecord::Acts::BetterTree
176
- #
177
- #ActiveRecord::Base.class_eval do
178
- # include ActiveRecord::Acts::BetterTree
179
- #end
180
-
181
190
  class ActiveRecord::Base
182
191
  include ActiveRecord::Acts::BetterTree
183
192
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_better_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Isaac Sloan
9
- autorequire:
10
8
  bindir: bin
11
9
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
10
+ date: 2025-04-11 00:00:00.000000000 Z
13
11
  dependencies: []
14
12
  description: acts_as_better_tree is great for anyone who needs a fast tree capable
15
13
  of handling millions of nodes without slowing down on writes like nestedset or on
@@ -20,7 +18,7 @@ executables: []
20
18
  extensions: []
21
19
  extra_rdoc_files: []
22
20
  files:
23
- - .gitignore
21
+ - ".gitignore"
24
22
  - Gemfile
25
23
  - Gemfile.lock
26
24
  - LICENSE
@@ -34,27 +32,23 @@ files:
34
32
  - spec/spec_helper.rb
35
33
  homepage: https://github.com/isaacsloan/acts_as_better_tree
36
34
  licenses: []
37
- post_install_message:
35
+ metadata: {}
38
36
  rdoc_options: []
39
37
  require_paths:
40
38
  - lib
41
39
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
40
  requirements:
44
- - - ! '>='
41
+ - - ">="
45
42
  - !ruby/object:Gem::Version
46
43
  version: '0'
47
44
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
45
  requirements:
50
- - - ! '>='
46
+ - - ">="
51
47
  - !ruby/object:Gem::Version
52
48
  version: '0'
53
49
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 1.8.21
56
- signing_key:
57
- specification_version: 3
50
+ rubygems_version: 3.6.2
51
+ specification_version: 4
58
52
  summary: acts_as_better_tree is backwards compatible with acts_as_tree and remains
59
53
  fast with large datasets by storing the ancestry of every node in the field csv_ids.
60
54
  test_files: