hierarchy 1.0.6 → 1.0.7
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 +106 -0
- data/hierarchy.gemspec +17 -7
- data/lib/hierarchy/index_path.rb +4 -4
- data/lib/hierarchy/node.rb +2 -2
- data/lib/hierarchy.rb +74 -74
- data/lib/hierarchy_generator.rb +6 -6
- metadata +61 -40
- data/README.textile +0 -93
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3216ee2327673134cabc227dba69a8c0c65aea3a76de131147882a1b469e06b5
|
|
4
|
+
data.tar.gz: be02935315adf7c8aa28c5509524cd770fe12c0f46c35a3cf8284e8f8dc4bbb8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 529e2c8961cde1ecf43f4eb709238e4fed99d2be60b62db09421e39261bc1023684494f9130fdd0af533dee5fd1b7261538836b7ad1fe5c4e27cc937f4170eaa
|
|
7
|
+
data.tar.gz: b266febc4eff1430db81651581052d326126b4717da80b293424a825c40adcbc49fbe5809f2ae85f7dd0d1506ea55514ed9e893899c82121ab7d65503057dfb6
|
data/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
> ⚠️ **DEPRECATED:** `hierarchy` is no longer maintained. Consider `ancestry`,
|
|
2
|
+
> `closure_tree`, or `acts_as_tree` for tree-structured ActiveRecord data. The
|
|
3
|
+
> final release is v1.0.7.
|
|
4
|
+
|
|
5
|
+
Hierarchy
|
|
6
|
+
=========
|
|
7
|
+
|
|
8
|
+
**Use PostgreSQL `LTREE` columns in ActiveRecord**
|
|
9
|
+
|
|
10
|
+
| | |
|
|
11
|
+
|:------------|:--------------------------------|
|
|
12
|
+
| **Author** | Tim Morgan |
|
|
13
|
+
| **Version** | 1.0.6 (Nov 27, 2010) |
|
|
14
|
+
| **License** | Released under the MIT license. |
|
|
15
|
+
|
|
16
|
+
About
|
|
17
|
+
-----
|
|
18
|
+
|
|
19
|
+
The `LTREE` column type is a PostgreSQL-specific type (available from the ltree
|
|
20
|
+
extension) for representing hierarchies. It is more efficient than the typical
|
|
21
|
+
way of accomplishing hierarchical structures in SQL, the `parent_id` column (or
|
|
22
|
+
similar).
|
|
23
|
+
|
|
24
|
+
This gem lets you use an `LTREE`-utilizing hierarchy in ActiveRecord. Including
|
|
25
|
+
this gem in your project gets you a module you can include in your models,
|
|
26
|
+
providing an abundance of methods to help you navigate and manipulate the
|
|
27
|
+
hierarchy.
|
|
28
|
+
|
|
29
|
+
Installation
|
|
30
|
+
------------
|
|
31
|
+
|
|
32
|
+
**Important Note:** This gem requires Ruby 1.9+ and Rails 3.0+.
|
|
33
|
+
|
|
34
|
+
Firstly, add the gem to your Rails project's `Gemfile`:
|
|
35
|
+
|
|
36
|
+
```` ruby
|
|
37
|
+
gem 'hierarchy'
|
|
38
|
+
````
|
|
39
|
+
|
|
40
|
+
Then, run the generator to install the migration:
|
|
41
|
+
|
|
42
|
+
```` sh
|
|
43
|
+
rails generate hierarchy
|
|
44
|
+
````
|
|
45
|
+
|
|
46
|
+
Note that *this migration must precede any tables using `LTREEs`*, so reorder
|
|
47
|
+
the migration if you have to.
|
|
48
|
+
|
|
49
|
+
Usage
|
|
50
|
+
-----
|
|
51
|
+
|
|
52
|
+
Because this gem was hastily extracted from a personal project, it's a little
|
|
53
|
+
constraining in how it can be used. (Sorry.) Currently the gem requires that
|
|
54
|
+
your table schema have a column named @path@ of type `LTREE`, defined as in the
|
|
55
|
+
example below:
|
|
56
|
+
|
|
57
|
+
```` sql
|
|
58
|
+
path LTREE NOT NULL DEFAULT ''
|
|
59
|
+
````
|
|
60
|
+
|
|
61
|
+
Once you've got that column in your model, feel free to include the `Hierarchy`
|
|
62
|
+
module:
|
|
63
|
+
|
|
64
|
+
```` ruby
|
|
65
|
+
class Person < ActiveRecord::Base
|
|
66
|
+
include Hierarchy
|
|
67
|
+
end
|
|
68
|
+
````
|
|
69
|
+
|
|
70
|
+
You can now define hierarchy by setting a model's `parent`, like so:
|
|
71
|
+
|
|
72
|
+
```` ruby
|
|
73
|
+
person.parent = mother #=> Sets the `path` column appropriately
|
|
74
|
+
````
|
|
75
|
+
|
|
76
|
+
You also have access to a wealth of ways to traverse the hierarchy:
|
|
77
|
+
|
|
78
|
+
```` ruby
|
|
79
|
+
person.children.where(gender: :male)
|
|
80
|
+
person.top_level?
|
|
81
|
+
Person.treeified #=> returns a traversible tree of all people
|
|
82
|
+
````
|
|
83
|
+
|
|
84
|
+
For more information on what you can do, see the {Hierarchy} module
|
|
85
|
+
documentation.
|
|
86
|
+
|
|
87
|
+
Development
|
|
88
|
+
-----------
|
|
89
|
+
|
|
90
|
+
If you wish to develop for Hierarchy, the first thing you will want to do is get
|
|
91
|
+
specs up and running. This requires a call to `bundle install` (obviously) and
|
|
92
|
+
setting up your test database.
|
|
93
|
+
|
|
94
|
+
As you can see in the `spec/spec_helper.rb` file, the specs require that a
|
|
95
|
+
PostgreSQL database named `hierarchy_test` exist and be owned by a
|
|
96
|
+
`hierarchy_tester` user. Unfortunately I haven't written a way to configure this
|
|
97
|
+
(though patches are welcome). So, the following commands should suffice to get
|
|
98
|
+
you started:
|
|
99
|
+
|
|
100
|
+
```` sh
|
|
101
|
+
createuser hierarchy_tester # answer "no" to all prompts
|
|
102
|
+
createdb -O hierarchy_tester hierarchy_test
|
|
103
|
+
````
|
|
104
|
+
|
|
105
|
+
With those steps done you should be able to run `rake spec` and see the Glorious
|
|
106
|
+
Green.
|
data/hierarchy.gemspec
CHANGED
|
@@ -2,23 +2,24 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
+
# stub: hierarchy 1.0.7 ruby lib
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
8
|
s.name = "hierarchy"
|
|
8
|
-
s.version = "1.0.
|
|
9
|
+
s.version = "1.0.7"
|
|
9
10
|
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
12
|
s.authors = ["Tim Morgan"]
|
|
12
|
-
s.date = "
|
|
13
|
+
s.date = "2013-12-08"
|
|
13
14
|
s.description = "Adds ActiveRecord support for hierarchical data structures using PostgreSQL's LTREE column type."
|
|
14
15
|
s.email = "git@timothymorgan.info"
|
|
15
16
|
s.extra_rdoc_files = [
|
|
16
17
|
"LICENSE",
|
|
17
|
-
"README.
|
|
18
|
+
"README.md"
|
|
18
19
|
]
|
|
19
20
|
s.files = [
|
|
20
21
|
"LICENSE",
|
|
21
|
-
"README.
|
|
22
|
+
"README.md",
|
|
22
23
|
"hierarchy.gemspec",
|
|
23
24
|
"lib/hierarchy.rb",
|
|
24
25
|
"lib/hierarchy/index_path.rb",
|
|
@@ -29,11 +30,20 @@ Gem::Specification.new do |s|
|
|
|
29
30
|
s.homepage = "http://github.com/riscfuture/hierarchy"
|
|
30
31
|
s.require_paths = ["lib"]
|
|
31
32
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
|
32
|
-
s.rubygems_version = "1.
|
|
33
|
-
s.summary = "Use PostgreSQL LTREE type with ActiveRecord"
|
|
33
|
+
s.rubygems_version = "2.1.11"
|
|
34
|
+
s.summary = "[DEPRECATED] Use PostgreSQL LTREE type with ActiveRecord"
|
|
35
|
+
s.post_install_message = <<~MSG
|
|
36
|
+
|
|
37
|
+
⚠️ DEPRECATED: hierarchy is no longer maintained.
|
|
38
|
+
|
|
39
|
+
No longer maintained. Consider `ancestry`, `closure_tree`, or `acts_as_tree` for tree-structured ActiveRecord data.
|
|
40
|
+
|
|
41
|
+
This is the final release. No further updates are planned.
|
|
42
|
+
|
|
43
|
+
MSG
|
|
34
44
|
|
|
35
45
|
if s.respond_to? :specification_version then
|
|
36
|
-
s.specification_version =
|
|
46
|
+
s.specification_version = 4
|
|
37
47
|
|
|
38
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
39
49
|
s.add_runtime_dependency(%q<rails>, [">= 3.0.2"])
|
data/lib/hierarchy/index_path.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Hierarchy
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
# An array of integers representing an ordered list of IDs. Duck-types an
|
|
4
|
-
#
|
|
4
|
+
# `Array` in many ways.
|
|
5
5
|
|
|
6
6
|
class IndexPath
|
|
7
7
|
include Enumerable
|
|
@@ -25,9 +25,9 @@ module Hierarchy
|
|
|
25
25
|
@indexes = indexes
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
# Creates an index path from a PostgreSQL
|
|
28
|
+
# Creates an index path from a PostgreSQL `LTREE` column.
|
|
29
29
|
#
|
|
30
|
-
# @param [String] string An
|
|
30
|
+
# @param [String] string An `LTREE` column value, such as "1.10.22".
|
|
31
31
|
# @return [IndexPath] A corresponding index path.
|
|
32
32
|
|
|
33
33
|
def self.from_ltree(string)
|
data/lib/hierarchy/node.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Hierarchy
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
# A node in a tree structure. A node can have zero or more {#children}, and
|
|
4
4
|
# has a reverse link back to its parent.
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ module Hierarchy
|
|
|
7
7
|
# @return [Array<Node>] This node's children.
|
|
8
8
|
attr_reader :children
|
|
9
9
|
|
|
10
|
-
# @return [Node, nil] This node's parent, or
|
|
10
|
+
# @return [Node, nil] This node's parent, or `nil` if it is a root node.
|
|
11
11
|
attr_reader :parent
|
|
12
12
|
|
|
13
13
|
# @return The object this node contains.
|
data/lib/hierarchy.rb
CHANGED
|
@@ -2,19 +2,19 @@ require 'hierarchy_generator'
|
|
|
2
2
|
require 'hierarchy/index_path'
|
|
3
3
|
require 'hierarchy/node'
|
|
4
4
|
|
|
5
|
-
# Adds a tree structure to a model. This is very similar to
|
|
6
|
-
# but uses the PostgreSQL-specific
|
|
5
|
+
# Adds a tree structure to a model. This is very similar to `acts_as_nested_set`
|
|
6
|
+
# but uses the PostgreSQL-specific `ltree` feature for schema storage.
|
|
7
7
|
#
|
|
8
|
-
# Your model must have a
|
|
8
|
+
# Your model must have a `path` field of type `ltree`. This field will be a
|
|
9
9
|
# period-delimited list of IDs of records above this one in the hierarchy. In
|
|
10
10
|
# addition, you should also consider the following indexes:
|
|
11
11
|
#
|
|
12
|
-
#
|
|
12
|
+
# ```` sql
|
|
13
13
|
# CREATE INDEX index1 ON table USING gist(path)
|
|
14
14
|
# CREATE INDEX index2 ON table USING btree(path)
|
|
15
|
-
#
|
|
15
|
+
# ````
|
|
16
16
|
#
|
|
17
|
-
# replacing
|
|
17
|
+
# replacing `table` with your table and `index1`/`index2` with appropriate names
|
|
18
18
|
# for these indexes.
|
|
19
19
|
#
|
|
20
20
|
# @example
|
|
@@ -24,19 +24,16 @@ require 'hierarchy/node'
|
|
|
24
24
|
|
|
25
25
|
module Hierarchy
|
|
26
26
|
extend ActiveSupport::Concern
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
# @private
|
|
29
29
|
included do
|
|
30
|
-
extend ActiveSupport::Memoizable
|
|
31
|
-
memoize :index_path, :ancestors
|
|
32
|
-
|
|
33
30
|
scope :parent_of, ->(obj) { obj.top_level? ? where('false') : where(id: obj.index_path.last) }
|
|
34
31
|
scope :children_of, ->(obj) { where(path: obj.my_path) }
|
|
35
32
|
scope :ancestors_of, ->(obj) { obj.top_level? ? where('false') : where(id: obj.index_path.to_a) }
|
|
36
33
|
scope :descendants_of, ->(obj) { where("path <@ ?", obj.my_path) }
|
|
37
34
|
scope :siblings_of, ->(obj) { where(path: obj.path) }
|
|
38
|
-
scope :priority_order, order("NLEVEL(path) ASC")
|
|
39
|
-
scope :top_level, where("path IS NULL or path = ?", '')
|
|
35
|
+
scope :priority_order, -> { order("NLEVEL(path) ASC") }
|
|
36
|
+
scope :top_level, -> { where("path IS NULL or path = ?", '') }
|
|
40
37
|
|
|
41
38
|
before_save { |obj| obj.path ||= '' }
|
|
42
39
|
before_save :update_children_with_new_parent
|
|
@@ -68,91 +65,94 @@ module Hierarchy
|
|
|
68
65
|
end
|
|
69
66
|
end
|
|
70
67
|
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
#
|
|
76
|
-
# @param [ActiveRecord::Base] parent The parent object.
|
|
77
|
-
# @raise [ArgumentError] If @parent@ is an unsaved record with no primary key.
|
|
68
|
+
# Sets the object above this one in the hierarchy.
|
|
69
|
+
#
|
|
70
|
+
# @param [ActiveRecord::Base] parent The parent object.
|
|
71
|
+
# @raise [ArgumentError] If `parent` is an unsaved record with no primary key.
|
|
78
72
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
def parent=(parent)
|
|
74
|
+
raise ArgumentError, "Parent cannot be a new record" if parent.try(:new_record?)
|
|
75
|
+
self.path = parent.try(:my_path)
|
|
76
|
+
end
|
|
83
77
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
# Returns an array of ancestors above this object. Note that a) this array
|
|
79
|
+
# is ordered with the most senior ancestor at the beginning of the list, and
|
|
80
|
+
# b) this is an _array_, not a _relation_. For that reason, you can pass
|
|
81
|
+
# any additional scope options to the method.
|
|
82
|
+
#
|
|
83
|
+
# @param [Hash] options Additional finder options.
|
|
84
|
+
# @return [Array] The objects above this one in the hierarchy.
|
|
91
85
|
|
|
92
|
-
|
|
86
|
+
def ancestors(options={})
|
|
87
|
+
@ancestors ||= begin
|
|
93
88
|
return [] if top_level?
|
|
94
89
|
objects = self.class.ancestors_of(self).scoped(options).group_by(&:id)
|
|
95
90
|
index_path.map { |id| objects[id].first }
|
|
96
91
|
end
|
|
92
|
+
end
|
|
97
93
|
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
# @return [ActiveRecord::Relation] The objects below this one in the
|
|
95
|
+
# hierarchy.
|
|
100
96
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
def descendants
|
|
98
|
+
self.class.descendants_of self
|
|
99
|
+
end
|
|
104
100
|
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
# @return [ActiveRecord::Base] The object directly above this one in the
|
|
102
|
+
# hierarchy.
|
|
107
103
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
def parent
|
|
105
|
+
top_level? ? nil : self.class.parent_of(self).first
|
|
106
|
+
end
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
# @return [ActiveRecord::Relation] The objects directly below this one
|
|
109
|
+
# in the hierarchy.
|
|
114
110
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
def children
|
|
112
|
+
self.class.children_of self
|
|
113
|
+
end
|
|
118
114
|
|
|
119
|
-
|
|
115
|
+
# @return [Array] The objects at the same hierarchical level of this one.
|
|
120
116
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
def siblings
|
|
118
|
+
self.class.siblings_of(self) - [ self ]
|
|
119
|
+
end
|
|
124
120
|
|
|
125
|
-
|
|
121
|
+
# @return [true, false] Whether or not this object has no parents.
|
|
126
122
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
def top_level?
|
|
124
|
+
path.blank?
|
|
125
|
+
end
|
|
130
126
|
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
# @return root parent or nil(if current obj is top level)
|
|
128
|
+
def root
|
|
129
|
+
self.top_level? ? nil : self.class.find(self.path.split('.').first)
|
|
130
|
+
end
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
end
|
|
132
|
+
# @return [true, false] Whether or not this object has no children. Makes a
|
|
133
|
+
# database call.
|
|
137
134
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
end
|
|
135
|
+
def bottom_level?
|
|
136
|
+
children.empty?
|
|
137
|
+
end
|
|
142
138
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
# @private
|
|
140
|
+
def my_path
|
|
141
|
+
path.blank? ? id.to_s : "#{path}.#{id}"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# @private
|
|
145
|
+
def index_path
|
|
146
|
+
@index_path ||= IndexPath.from_ltree path.to_s
|
|
147
|
+
end
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
private
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
end
|
|
151
|
+
# if our parent has changed, update our children's paths
|
|
152
|
+
def update_children_with_new_parent
|
|
153
|
+
if path_changed? and not new_record? then
|
|
154
|
+
old_path = (path_was.blank? ? id.to_s : "#{path_was}.#{id}")
|
|
155
|
+
self.class.where("path <@ ?", old_path).update_all([ "path = TEXT2LTREE(REPLACE(LTREE2TEXT(path), ?, ?))", old_path, my_path ])
|
|
156
156
|
end
|
|
157
157
|
end
|
|
158
158
|
end
|
data/lib/hierarchy_generator.rb
CHANGED
|
@@ -5,18 +5,18 @@ require 'rails/generators/migration'
|
|
|
5
5
|
# @private
|
|
6
6
|
class HierarchyGenerator < Rails::Generators::Base
|
|
7
7
|
include Rails::Generators::Migration
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
source_root "#{File.dirname __FILE__}/../templates"
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
def self.next_migration_number(dirname)
|
|
12
12
|
if ActiveRecord::Base.timestamped_migrations then
|
|
13
|
-
Time.now.utc.strftime
|
|
13
|
+
Time.now.utc.strftime '%Y%m%d%H%M%S'
|
|
14
14
|
else
|
|
15
|
-
|
|
15
|
+
'%.3d' % (current_migration_number(dirname) + 1)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def copy_files
|
|
20
|
-
migration_template
|
|
20
|
+
migration_template 'add_ltree_type.rb', 'db/migrate/add_ltree_type.rb'
|
|
21
21
|
end
|
|
22
22
|
end
|
metadata
CHANGED
|
@@ -1,82 +1,98 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hierarchy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 1.0.7
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Tim Morgan
|
|
9
|
-
autorequire:
|
|
10
8
|
bindir: bin
|
|
11
9
|
cert_chain: []
|
|
12
|
-
date:
|
|
10
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
|
13
11
|
dependencies:
|
|
14
12
|
- !ruby/object:Gem::Dependency
|
|
15
13
|
name: rails
|
|
16
|
-
requirement:
|
|
17
|
-
none: false
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
15
|
requirements:
|
|
19
|
-
- -
|
|
16
|
+
- - ">="
|
|
20
17
|
- !ruby/object:Gem::Version
|
|
21
18
|
version: 3.0.2
|
|
22
19
|
type: :runtime
|
|
23
20
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 3.0.2
|
|
25
26
|
- !ruby/object:Gem::Dependency
|
|
26
27
|
name: pg
|
|
27
|
-
requirement:
|
|
28
|
-
none: false
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
|
-
- -
|
|
30
|
+
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '0'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements:
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
36
40
|
- !ruby/object:Gem::Dependency
|
|
37
41
|
name: jeweler
|
|
38
|
-
requirement:
|
|
39
|
-
none: false
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
40
43
|
requirements:
|
|
41
|
-
- -
|
|
44
|
+
- - ">="
|
|
42
45
|
- !ruby/object:Gem::Version
|
|
43
46
|
version: '0'
|
|
44
47
|
type: :development
|
|
45
48
|
prerelease: false
|
|
46
|
-
version_requirements:
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
47
54
|
- !ruby/object:Gem::Dependency
|
|
48
55
|
name: yard
|
|
49
|
-
requirement:
|
|
50
|
-
none: false
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
51
57
|
requirements:
|
|
52
|
-
- -
|
|
58
|
+
- - ">="
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
60
|
version: '0'
|
|
55
61
|
type: :development
|
|
56
62
|
prerelease: false
|
|
57
|
-
version_requirements:
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
58
68
|
- !ruby/object:Gem::Dependency
|
|
59
69
|
name: RedCloth
|
|
60
|
-
requirement:
|
|
61
|
-
none: false
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
62
71
|
requirements:
|
|
63
|
-
- -
|
|
72
|
+
- - ">="
|
|
64
73
|
- !ruby/object:Gem::Version
|
|
65
74
|
version: '0'
|
|
66
75
|
type: :development
|
|
67
76
|
prerelease: false
|
|
68
|
-
version_requirements:
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
69
82
|
- !ruby/object:Gem::Dependency
|
|
70
83
|
name: rspec
|
|
71
|
-
requirement:
|
|
72
|
-
none: false
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
85
|
requirements:
|
|
74
|
-
- -
|
|
86
|
+
- - ">="
|
|
75
87
|
- !ruby/object:Gem::Version
|
|
76
88
|
version: '0'
|
|
77
89
|
type: :development
|
|
78
90
|
prerelease: false
|
|
79
|
-
version_requirements:
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
80
96
|
description: Adds ActiveRecord support for hierarchical data structures using PostgreSQL's
|
|
81
97
|
LTREE column type.
|
|
82
98
|
email: git@timothymorgan.info
|
|
@@ -84,10 +100,10 @@ executables: []
|
|
|
84
100
|
extensions: []
|
|
85
101
|
extra_rdoc_files:
|
|
86
102
|
- LICENSE
|
|
87
|
-
- README.
|
|
103
|
+
- README.md
|
|
88
104
|
files:
|
|
89
105
|
- LICENSE
|
|
90
|
-
- README.
|
|
106
|
+
- README.md
|
|
91
107
|
- hierarchy.gemspec
|
|
92
108
|
- lib/hierarchy.rb
|
|
93
109
|
- lib/hierarchy/index_path.rb
|
|
@@ -96,26 +112,31 @@ files:
|
|
|
96
112
|
- templates/add_ltree_type.rb
|
|
97
113
|
homepage: http://github.com/riscfuture/hierarchy
|
|
98
114
|
licenses: []
|
|
99
|
-
|
|
115
|
+
metadata: {}
|
|
116
|
+
post_install_message: |2+
|
|
117
|
+
|
|
118
|
+
⚠️ DEPRECATED: hierarchy is no longer maintained.
|
|
119
|
+
|
|
120
|
+
No longer maintained. Consider `ancestry`, `closure_tree`, or `acts_as_tree` for tree-structured ActiveRecord data.
|
|
121
|
+
|
|
122
|
+
This is the final release. No further updates are planned.
|
|
123
|
+
|
|
100
124
|
rdoc_options: []
|
|
101
125
|
require_paths:
|
|
102
126
|
- lib
|
|
103
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
-
none: false
|
|
105
128
|
requirements:
|
|
106
|
-
- -
|
|
129
|
+
- - ">="
|
|
107
130
|
- !ruby/object:Gem::Version
|
|
108
131
|
version: '1.9'
|
|
109
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
-
none: false
|
|
111
133
|
requirements:
|
|
112
|
-
- -
|
|
134
|
+
- - ">="
|
|
113
135
|
- !ruby/object:Gem::Version
|
|
114
136
|
version: '0'
|
|
115
137
|
requirements: []
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
specification_version: 3
|
|
120
|
-
summary: Use PostgreSQL LTREE type with ActiveRecord
|
|
138
|
+
rubygems_version: 4.0.11
|
|
139
|
+
specification_version: 4
|
|
140
|
+
summary: "[DEPRECATED] Use PostgreSQL LTREE type with ActiveRecord"
|
|
121
141
|
test_files: []
|
|
142
|
+
...
|
data/README.textile
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
h1. Hierarchy -- Use PostgreSQL @LTREE@ columns in ActiveRecord
|
|
2
|
-
|
|
3
|
-
| *Author* | Tim Morgan |
|
|
4
|
-
| *Version* | 1.0.6 (Nov 27, 2010) |
|
|
5
|
-
| *License* | Released under the MIT license. |
|
|
6
|
-
|
|
7
|
-
h2. About
|
|
8
|
-
|
|
9
|
-
The @LTREE@ column type is a PostgreSQL-specific type (available from the ltree
|
|
10
|
-
extension) for representing hierarchies. It is more efficient than the typical
|
|
11
|
-
way of accomplishing hierarchical structures in SQL, the @parent_id@ column (or
|
|
12
|
-
similar).
|
|
13
|
-
|
|
14
|
-
This gem lets you use an @LTREE@-utilizing hierarchy in ActiveRecord. Including
|
|
15
|
-
this gem in your project gets you a module you can include in your models,
|
|
16
|
-
providing an abundance of methods to help you navigate and manipulate the
|
|
17
|
-
hierarchy.
|
|
18
|
-
|
|
19
|
-
h2. Installation
|
|
20
|
-
|
|
21
|
-
*Important Note:* This gem requires Ruby 1.9 and Rails 3.0.
|
|
22
|
-
|
|
23
|
-
Firstly, add the gem to your Rails project's @Gemfile@:
|
|
24
|
-
|
|
25
|
-
<pre><code>
|
|
26
|
-
gem 'hierarchy'
|
|
27
|
-
</code></pre>
|
|
28
|
-
|
|
29
|
-
Then, run the generator to install the migration:
|
|
30
|
-
|
|
31
|
-
<pre><code>
|
|
32
|
-
rails generate hierarchy
|
|
33
|
-
</code></pre>
|
|
34
|
-
|
|
35
|
-
Note that *this migration must precede any tables using @LTREEs@*, so reorder
|
|
36
|
-
the migration if you have to.
|
|
37
|
-
|
|
38
|
-
h2. Usage
|
|
39
|
-
|
|
40
|
-
Because this gem was hastily extracted from a personal project, it's a little
|
|
41
|
-
constraining in how it can be used. (Sorry.) Currently the gem requires that
|
|
42
|
-
your table schema have a column named @path@ of type @LTREE@, defined as in the
|
|
43
|
-
example below:
|
|
44
|
-
|
|
45
|
-
<pre><code>
|
|
46
|
-
path LTREE NOT NULL DEFAULT ''
|
|
47
|
-
</code></pre>
|
|
48
|
-
|
|
49
|
-
Once you've got that column in your model, feel free to include the @Hierarchy@
|
|
50
|
-
module:
|
|
51
|
-
|
|
52
|
-
<pre><code>
|
|
53
|
-
class Person < ActiveRecord::Base
|
|
54
|
-
include Hierarchy
|
|
55
|
-
end
|
|
56
|
-
</code></pre>
|
|
57
|
-
|
|
58
|
-
You can now define hierarchy by setting a model's @parent@, like so:
|
|
59
|
-
|
|
60
|
-
<pre><code>
|
|
61
|
-
person.parent = mother #=> Sets the `path` column appropriately
|
|
62
|
-
</code></pre>
|
|
63
|
-
|
|
64
|
-
You also have access to a wealth of ways to traverse the hierarchy:
|
|
65
|
-
|
|
66
|
-
<pre><code>
|
|
67
|
-
person.children.where(gender: :male)
|
|
68
|
-
person.top_level?
|
|
69
|
-
Person.treeified #=> returns a traversible tree of all people
|
|
70
|
-
</code></pre>
|
|
71
|
-
|
|
72
|
-
For more information on what you can do, see the {Hierarchy} module
|
|
73
|
-
documentation.
|
|
74
|
-
|
|
75
|
-
h2. Development
|
|
76
|
-
|
|
77
|
-
If you wish to develop for Hierarchy, the first thing you will want to do is get
|
|
78
|
-
specs up and running. This requires a call to @bundle install@ (obviously) and
|
|
79
|
-
setting up your test database.
|
|
80
|
-
|
|
81
|
-
As you can see in the @spec/spec_helper.rb@ file, the specs require that a
|
|
82
|
-
PostgreSQL database named @hierarchy_test@ exist and be owned by a
|
|
83
|
-
@hierarchy_tester@ user. Unfortunately I haven't written a way to configure this
|
|
84
|
-
(though patches are welcome). So, the following commands should suffice to get
|
|
85
|
-
you started:
|
|
86
|
-
|
|
87
|
-
<pre><code>
|
|
88
|
-
createuser hierarchy_tester # answer "no" to all prompts
|
|
89
|
-
createdb -O hierarchy_tester hierarchy_test
|
|
90
|
-
</code></pre>
|
|
91
|
-
|
|
92
|
-
With those steps done you should be able to run @rake spec@ and see the Glorious
|
|
93
|
-
Green.
|