pg_ltree 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pg_ltree/ltree.rb +20 -4
- data/lib/pg_ltree/scoped_for.rb +1 -0
- data/lib/pg_ltree/version.rb +1 -1
- data/test/dummy/config/database.yml +14 -0
- data/test/dummy/log/development.log +167 -681
- data/test/dummy/log/test.log +135809 -21732
- data/test/pg_ltree/ltree_test.rb +16 -0
- data/test/pg_ltree/scoped_for_test.rb +190 -151
- data/test/test_helper.rb +0 -7
- metadata +44 -70
- data/lib/tasks/pg_ltree_tasks.rake +0 -4
- data/test/doc/_index.html +0 -88
- data/test/doc/class_list.html +0 -58
- data/test/doc/css/common.css +0 -1
- data/test/doc/css/full_list.css +0 -57
- data/test/doc/css/style.css +0 -339
- data/test/doc/file_list.html +0 -57
- data/test/doc/frames.html +0 -26
- data/test/doc/index.html +0 -88
- data/test/doc/js/app.js +0 -219
- data/test/doc/js/full_list.js +0 -181
- data/test/doc/js/jquery.js +0 -4
- data/test/doc/method_list.html +0 -57
- data/test/doc/top-level-namespace.html +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea3d57bbe24a87605eb3cc1bd653cb7d0ed7170
|
4
|
+
data.tar.gz: 27e68347ac9e861a985bdba1b0b7821189d04015
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e55426faace49c393326faca66f9344c62b20490171415291dcb1037f4f6f1ba331b07ca51c816bf2524a4ee4ac112ff20d6646931ab0e14acbce132ea1f60fb
|
7
|
+
data.tar.gz: f7f5510c4ae6c7ea369690ee5be01700d66499b10e8fcef05c4d200439a327537d28b88e91bcd09c72a8ca1e1dcfd1a182dd1dad7fd8fa6971174a4815120061
|
data/lib/pg_ltree/ltree.rb
CHANGED
@@ -10,14 +10,15 @@ module PgLtree
|
|
10
10
|
# Initialzie ltree for active model
|
11
11
|
#
|
12
12
|
# @param column [String] ltree column name
|
13
|
-
def ltree(column = :path)
|
13
|
+
def ltree(column = :path, options: { cascade: true })
|
14
14
|
cattr_accessor :ltree_path_column
|
15
15
|
|
16
16
|
self.ltree_path_column = column
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
if options[:cascade]
|
19
|
+
self.after_update :cascade_update
|
20
|
+
self.after_destroy :cascade_destroy
|
21
|
+
end
|
21
22
|
|
22
23
|
extend ClassMethods
|
23
24
|
include InstanceMethods
|
@@ -185,6 +186,21 @@ module PgLtree
|
|
185
186
|
ltree_scope.where "? @> #{ltree_path_column} AND nlevel(#{ltree_path_column}) = NLEVEL(?) + 1",
|
186
187
|
ltree_path, ltree_path
|
187
188
|
end
|
189
|
+
|
190
|
+
# Update all childen for current path
|
191
|
+
#
|
192
|
+
# @return [ActiveRecord::Relation]
|
193
|
+
def cascade_update
|
194
|
+
ltree_scope.where(["#{ltree_path_column} <@ ?", ltree_path_was]).
|
195
|
+
update_all ["#{ltree_path_column} = ? || subpath(#{ltree_path_column}, nlevel(?))", ltree_path, ltree_path_was]
|
196
|
+
end
|
197
|
+
|
198
|
+
# Delete all children for current path
|
199
|
+
#
|
200
|
+
# @return [ActiveRecord::Relation]
|
201
|
+
def cascade_destroy
|
202
|
+
ltree_scope.where("#{ltree_path_column} <@ ?", ltree_path_was).delete_all
|
203
|
+
end
|
188
204
|
end
|
189
205
|
end
|
190
206
|
end
|
data/lib/pg_ltree/scoped_for.rb
CHANGED
data/lib/pg_ltree/version.rb
CHANGED