acts_as_better_tree 0.9.5 → 1.0.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 +7 -0
- data/README.md +2 -2
- data/lib/acts_as_better_tree.rb +6 -12
- data/lib/acts_as_better_tree/version.rb +1 -1
- metadata +8 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 626f6d72ed65efb1cac94e550e27e3af3cb7206f
|
4
|
+
data.tar.gz: ea21b886ce356e30985e9702757fb54e557245e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca36af0c8a56427ce3d30e4f0d3e6d3c5fef6a011fd3ec31b57a1d42f88b399224c1ef29691e119d642a4033e195aafa12a41312d18ad143d197fc50b5f0e36d
|
7
|
+
data.tar.gz: ece9981f83c38cf1e6d07a2e1dd2ca00f1717364b89bcc2e002c126536b70baf02212ee78ea8042ad26641b3e31639427b3e6e2bd5350a49d891f861b99dafa4
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
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
|
-
|
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"
|
data/lib/acts_as_better_tree.rb
CHANGED
@@ -8,15 +8,15 @@ module ActiveRecord
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def acts_as_better_tree(options = {}
|
11
|
+
def acts_as_better_tree(options = {})
|
12
12
|
configuration = {:order => "id ASC", :destroy_dependent => true }
|
13
13
|
configuration.update(options) if options.is_a?(Hash)
|
14
14
|
|
15
15
|
belongs_to :parent, :class_name => name, :foreign_key => :parent_id
|
16
|
-
has_many :children, {:class_name => name, :foreign_key => :parent_id
|
17
|
-
has_many :parents_children, {:class_name => name, :primary_key => :parent_id, :foreign_key => :parent_id
|
16
|
+
has_many :children, -> {order(configuration[:order])}, {:class_name => name, :foreign_key => :parent_id}.merge(configuration[:destroy_dependent] ? {:dependent => :destroy} : {})
|
17
|
+
has_many :parents_children, -> {order(configuration[:order])}, {:class_name => name, :primary_key => :parent_id, :foreign_key => :parent_id}
|
18
18
|
belongs_to :root, :class_name => name, :foreign_key => :root_id
|
19
|
-
scope :roots,
|
19
|
+
scope :roots, -> {order(configuration[:order]).where(:parent_id => nil)}
|
20
20
|
after_create :assign_csv_ids
|
21
21
|
after_validation :update_csv_ids, :on => :update
|
22
22
|
|
@@ -161,23 +161,17 @@ module ActiveRecord
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def update_csv_ids
|
164
|
-
return unless parent_foreign_key_changed?
|
164
|
+
return unless parent_foreign_key_changed?
|
165
165
|
old_csv_ids = self.csv_ids
|
166
166
|
self.csv_ids = build_csv_ids
|
167
167
|
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}"
|
168
|
+
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
169
|
end
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
-
#ActiveRecord::Base.send :include, ActiveRecord::Acts::BetterTree
|
176
|
-
#
|
177
|
-
#ActiveRecord::Base.class_eval do
|
178
|
-
# include ActiveRecord::Acts::BetterTree
|
179
|
-
#end
|
180
|
-
|
181
175
|
class ActiveRecord::Base
|
182
176
|
include ActiveRecord::Acts::BetterTree
|
183
177
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_better_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Isaac Sloan
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: acts_as_better_tree is great for anyone who needs a fast tree capable
|
15
14
|
of handling millions of nodes without slowing down on writes like nestedset or on
|
@@ -20,7 +19,7 @@ executables: []
|
|
20
19
|
extensions: []
|
21
20
|
extra_rdoc_files: []
|
22
21
|
files:
|
23
|
-
- .gitignore
|
22
|
+
- ".gitignore"
|
24
23
|
- Gemfile
|
25
24
|
- Gemfile.lock
|
26
25
|
- LICENSE
|
@@ -34,27 +33,26 @@ files:
|
|
34
33
|
- spec/spec_helper.rb
|
35
34
|
homepage: https://github.com/isaacsloan/acts_as_better_tree
|
36
35
|
licenses: []
|
36
|
+
metadata: {}
|
37
37
|
post_install_message:
|
38
38
|
rdoc_options: []
|
39
39
|
require_paths:
|
40
40
|
- lib
|
41
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
42
|
requirements:
|
44
|
-
- -
|
43
|
+
- - ">="
|
45
44
|
- !ruby/object:Gem::Version
|
46
45
|
version: '0'
|
47
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
47
|
requirements:
|
50
|
-
- -
|
48
|
+
- - ">="
|
51
49
|
- !ruby/object:Gem::Version
|
52
50
|
version: '0'
|
53
51
|
requirements: []
|
54
52
|
rubyforge_project:
|
55
|
-
rubygems_version:
|
53
|
+
rubygems_version: 2.4.5.1
|
56
54
|
signing_key:
|
57
|
-
specification_version:
|
55
|
+
specification_version: 4
|
58
56
|
summary: acts_as_better_tree is backwards compatible with acts_as_tree and remains
|
59
57
|
fast with large datasets by storing the ancestry of every node in the field csv_ids.
|
60
58
|
test_files:
|