ltree_hierarchy 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +30 -24
- data/README.md +2 -0
- data/lib/ltree_hierarchy/hierarchy.rb +16 -16
- data/lib/ltree_hierarchy/version.rb +1 -1
- metadata +7 -11
- data/init.rb +0 -1
- data/ltree_hierarchy-0.0.7.gem +0 -0
- data/ltree_hierarchy.gemspec +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5c26309b9170981b2ed394e7810e2160c19f4aa
|
4
|
+
data.tar.gz: fe39b129c2da491c88aa665d47a73f3743ea00c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6257d1cf2fa25878fd43941ba1ce3716c248ad71b2a8bddfdf4d174e9750bd33ea9683a5e26cf8520816dfd001e7e4f4cb79191c0cb782f5232f785c01e951bf
|
7
|
+
data.tar.gz: 39e117fcd55f69f7f65bb5b582fe64200e10565659e1c8dc62547c14f0e3ded48b687b13bbacfb7180bc489b44854ec825ecfa4873f97b7ac353d194bb71f400
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ltree_hierarchy (0.0.
|
5
|
-
activerecord (>= 3.1)
|
6
|
-
pg
|
4
|
+
ltree_hierarchy (0.0.8)
|
5
|
+
activerecord (>= 3.1.0)
|
6
|
+
pg
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (
|
12
|
-
activesupport (=
|
13
|
-
builder (~> 3.
|
14
|
-
activerecord (
|
15
|
-
activemodel (=
|
16
|
-
activesupport (=
|
17
|
-
arel (~>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
11
|
+
activemodel (4.2.7.1)
|
12
|
+
activesupport (= 4.2.7.1)
|
13
|
+
builder (~> 3.1)
|
14
|
+
activerecord (4.2.7.1)
|
15
|
+
activemodel (= 4.2.7.1)
|
16
|
+
activesupport (= 4.2.7.1)
|
17
|
+
arel (~> 6.0)
|
18
|
+
activesupport (4.2.7.1)
|
19
|
+
i18n (~> 0.7)
|
20
|
+
json (~> 1.7, >= 1.7.7)
|
21
|
+
minitest (~> 5.1)
|
22
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
arel (6.0.3)
|
25
|
+
builder (3.2.2)
|
24
26
|
i18n (0.7.0)
|
25
|
-
|
26
|
-
|
27
|
-
pg (0.
|
28
|
-
rake (
|
29
|
-
|
27
|
+
json (1.8.3)
|
28
|
+
minitest (5.9.1)
|
29
|
+
pg (0.19.0)
|
30
|
+
rake (11.3.0)
|
31
|
+
thread_safe (0.3.5)
|
32
|
+
tzinfo (1.2.2)
|
33
|
+
thread_safe (~> 0.1)
|
30
34
|
|
31
35
|
PLATFORMS
|
32
36
|
ruby
|
33
37
|
|
34
38
|
DEPENDENCIES
|
35
|
-
activerecord (~> 3.2)
|
36
39
|
ltree_hierarchy!
|
37
|
-
minitest
|
38
|
-
rake
|
40
|
+
minitest
|
41
|
+
rake
|
42
|
+
|
43
|
+
BUNDLED WITH
|
44
|
+
1.13.6
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/cfabianski/ltree_hierarchy.svg?branch=master)](https://travis-ci.org/cfabianski/ltree_hierarchy)
|
2
|
+
|
1
3
|
# Ltree Hierarchy
|
2
4
|
|
3
5
|
A simplistic gem that allows ActiveRecord models to be organized in a tree or hierarchy. It uses a materialized path implementation based around PostgreSQL's [ltree](http://www.postgresql.org/docs/current/static/ltree.html) data type, associated functions and operators.
|
@@ -26,18 +26,18 @@ module Ltree
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def roots
|
29
|
-
where(ltree_parent_fragment_column => nil)
|
29
|
+
where("#{table_name}.#{ltree_parent_fragment_column}" => nil)
|
30
30
|
end
|
31
31
|
|
32
32
|
def at_depth(depth)
|
33
|
-
where(["NLEVEL(#{ltree_path_column}) = ?", depth])
|
33
|
+
where(["NLEVEL(#{table_name}.#{ltree_path_column}) = ?", depth])
|
34
34
|
end
|
35
35
|
|
36
36
|
def leaves
|
37
|
-
subquery = where("#{ltree_parent_fragment_column} IS NOT NULL")
|
38
|
-
.select("DISTINCT #{ltree_parent_fragment_column}")
|
37
|
+
subquery = where("#{table_name}.#{ltree_parent_fragment_column} IS NOT NULL")
|
38
|
+
.select("DISTINCT #{table_name}.#{ltree_parent_fragment_column}")
|
39
39
|
|
40
|
-
where("#{ltree_fragment_column} NOT IN(#{subquery.to_sql})")
|
40
|
+
where("#{table_name}.#{ltree_fragment_column} NOT IN(#{subquery.to_sql})")
|
41
41
|
end
|
42
42
|
|
43
43
|
def lowest_common_ancestor_paths(paths)
|
@@ -52,7 +52,7 @@ module Ltree
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def lowest_common_ancestors(paths)
|
55
|
-
where(ltree_path_column => lowest_common_ancestor_paths(paths))
|
55
|
+
where("#{table_name}.#{ltree_path_column}" => lowest_common_ancestor_paths(paths))
|
56
56
|
end
|
57
57
|
|
58
58
|
module InstanceMethods
|
@@ -120,7 +120,7 @@ module Ltree
|
|
120
120
|
# SET path = NEW.path || subpath(path, nlevel(OLD.path))
|
121
121
|
# WHERE path <@ OLD.path AND id != NEW.id;
|
122
122
|
ltree_scope.where(
|
123
|
-
["#{ltree_path_column} <@ :old_path AND #{ltree_fragment_column} != :id", old_path: ltree_path_was, id: ltree_fragment]
|
123
|
+
["#{ltree_scope.table_name}.#{ltree_path_column} <@ :old_path AND #{ltree_scope.table_name}.#{ltree_fragment_column} != :id", old_path: ltree_path_was, id: ltree_fragment]
|
124
124
|
).update_all(
|
125
125
|
["#{ltree_path_column} = :new_path || subpath(#{ltree_path_column}, nlevel(:old_path))", new_path: ltree_path, old_path: ltree_path_was]
|
126
126
|
)
|
@@ -149,32 +149,32 @@ module Ltree
|
|
149
149
|
end
|
150
150
|
|
151
151
|
def root
|
152
|
-
ltree_scope.where("#{ltree_path_column} = SUBPATH(?, 0, 1)", ltree_path).first
|
152
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} = SUBPATH(?, 0, 1)", ltree_path).first
|
153
153
|
end
|
154
154
|
|
155
155
|
def ancestors
|
156
|
-
ltree_scope.where("#{ltree_path_column} @> ? AND #{ltree_fragment_column} != ?", ltree_path, ltree_fragment)
|
156
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} @> ? AND #{ltree_scope.table_name}.#{ltree_fragment_column} != ?", ltree_path, ltree_fragment)
|
157
157
|
end
|
158
158
|
|
159
159
|
def self_and_ancestors
|
160
|
-
ltree_scope.where("#{ltree_path_column} @> ?", ltree_path)
|
160
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} @> ?", ltree_path)
|
161
161
|
end
|
162
162
|
alias :and_ancestors :self_and_ancestors
|
163
163
|
|
164
164
|
def siblings
|
165
165
|
ltree_scope.where(
|
166
|
-
"#{ltree_parent_fragment_column} = ? AND #{ltree_fragment_column} != ?",
|
166
|
+
"#{ltree_scope.table_name}.#{ltree_parent_fragment_column} = ? AND #{ltree_scope.table_name}.#{ltree_fragment_column} != ?",
|
167
167
|
ltree_parent_fragment, ltree_fragment
|
168
168
|
)
|
169
169
|
end
|
170
170
|
|
171
171
|
def self_and_siblings
|
172
|
-
ltree_scope.where(ltree_parent_fragment_column => ltree_parent_fragment)
|
172
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_parent_fragment_column}" => ltree_parent_fragment)
|
173
173
|
end
|
174
174
|
alias :and_siblings :self_and_siblings
|
175
175
|
|
176
176
|
def descendants
|
177
|
-
ltree_scope.where("#{ltree_path_column} <@ ? AND #{ltree_fragment_column} != ?", ltree_path, ltree_fragment)
|
177
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} <@ ? AND #{ltree_scope.table_name}.#{ltree_fragment_column} != ?", ltree_path, ltree_fragment)
|
178
178
|
end
|
179
179
|
|
180
180
|
def descendents
|
@@ -183,7 +183,7 @@ module Ltree
|
|
183
183
|
end
|
184
184
|
|
185
185
|
def self_and_descendants
|
186
|
-
ltree_scope.where("#{ltree_path_column} <@ ?", ltree_path)
|
186
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} <@ ?", ltree_path)
|
187
187
|
end
|
188
188
|
alias :and_descendants :self_and_descendants
|
189
189
|
|
@@ -194,11 +194,11 @@ module Ltree
|
|
194
194
|
alias :and_descendents :self_and_descendents
|
195
195
|
|
196
196
|
def children
|
197
|
-
ltree_scope.where(ltree_parent_fragment_column => ltree_fragment)
|
197
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_parent_fragment_column}" => ltree_fragment)
|
198
198
|
end
|
199
199
|
|
200
200
|
def self_and_children
|
201
|
-
ltree_scope.where("#{ltree_fragment_column} = :id OR #{ltree_parent_fragment_column} = :id", id: ltree_fragment)
|
201
|
+
ltree_scope.where("#{ltree_scope.table_name}.#{ltree_fragment_column} = :id OR #{ltree_scope.table_name}.#{ltree_parent_fragment_column} = :id", id: ltree_fragment)
|
202
202
|
end
|
203
203
|
alias :and_children :self_and_children
|
204
204
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltree_hierarchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Worley
|
8
|
-
-
|
8
|
+
- Cédric Fabianski
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 4.2.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 4.2.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: minitest
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,13 +82,10 @@ files:
|
|
82
82
|
- MIT-LICENSE
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
|
-
- init.rb
|
86
85
|
- lib/ltree_hierarchy.rb
|
87
86
|
- lib/ltree_hierarchy/hierarchy.rb
|
88
87
|
- lib/ltree_hierarchy/version.rb
|
89
|
-
|
90
|
-
- ltree_hierarchy.gemspec
|
91
|
-
homepage: https://github.com/Leadformance/ltree_hierarchy
|
88
|
+
homepage: https://github.com/cfabianski/ltree_hierarchy
|
92
89
|
licenses:
|
93
90
|
- MIT
|
94
91
|
metadata: {}
|
@@ -108,9 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
105
|
version: '0'
|
109
106
|
requirements: []
|
110
107
|
rubyforge_project: ltree_hierarchy
|
111
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.5.2
|
112
109
|
signing_key:
|
113
110
|
specification_version: 4
|
114
111
|
summary: Organize ActiveRecord models into a tree using PostgreSQL's ltree datatype
|
115
112
|
test_files: []
|
116
|
-
has_rdoc:
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "ltree_hierarchy"
|
data/ltree_hierarchy-0.0.7.gem
DELETED
Binary file
|
data/ltree_hierarchy.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "ltree_hierarchy/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "ltree_hierarchy"
|
7
|
-
s.version = Ltree::Hierarchy::VERSION
|
8
|
-
s.authors = ["Rob Worley", "Leadformance"]
|
9
|
-
s.email = ["dev@leadformance.com"]
|
10
|
-
s.homepage = "https://github.com/Leadformance/ltree_hierarchy"
|
11
|
-
s.summary = "Organize ActiveRecord models into a tree using PostgreSQL's ltree datatype"
|
12
|
-
s.description = "Organizes ActiveRecord models into a tree/hierarchy using a materialized path implementation based around PostgreSQL's ltree datatype. ltree's operators ensure that queries are fast and easily understood."
|
13
|
-
|
14
|
-
s.rubyforge_project = "ltree_hierarchy"
|
15
|
-
|
16
|
-
s.files = Dir["{lib/**/*,[A-Z]*}"]
|
17
|
-
s.platform = Gem::Platform::RUBY
|
18
|
-
s.license = "MIT"
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
if RUBY_PLATFORM == "java"
|
22
|
-
s.add_dependency "activerecord-jdbcpostgresql-adapter"
|
23
|
-
else
|
24
|
-
s.add_dependency "pg"
|
25
|
-
end
|
26
|
-
|
27
|
-
s.add_dependency "activerecord", ">= 3.1.0"
|
28
|
-
|
29
|
-
s.add_development_dependency "minitest"
|
30
|
-
s.add_development_dependency "rake"
|
31
|
-
end
|