hierarchical_db 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +12 -9
- data/README.md +28 -11
- data/hierarchical_db.gemspec +1 -1
- data/lib/hierarchical_db.rb +5 -2
- metadata +1 -12
- data/hierarchical_db-0.0.0.gem +0 -0
- data/hierarchical_db-0.0.1.gem +0 -0
- data/hierarchical_db-0.0.2.gem +0 -0
- data/hierarchical_db-0.0.3.gem +0 -0
- data/hierarchical_db-0.0.4.gem +0 -0
- data/hierarchical_db-0.0.5.gem +0 -0
- data/hierarchical_db-0.0.6.gem +0 -0
- data/hierarchical_db-0.0.7.gem +0 -0
- data/hierarchical_db-0.0.8.gem +0 -0
- data/hierarchical_db-0.0.9.gem +0 -0
- data/hierarchical_db-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 861a2dffcff74a32cc269574fe99e5efde59fc2c
|
4
|
+
data.tar.gz: 1c07b2bf9a7386b441b8439006f70fadfda6fd60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe5c03619545c96e4ebcee1b50f59182a5fb59a621238931f443fd1541fa0774cd3b985712267339dfd52af668559d44a65ba076891246dfe1780975714a081
|
7
|
+
data.tar.gz: 8c93dd008ced535632adc8d94c5ce97fc1e5491cdc8531fb9bfcddd67fcb8325c3470466fa9d1d103366d124667c94d710a20b467fe0f6fc57f1b29635719f9a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,22 +18,19 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install hierarchical_db
|
20
20
|
|
21
|
-
Next you have to
|
21
|
+
Next you have to use the hierarchical_db generator into your model. For example, if you have a model called *Territory* (to manage countries, cities and all the other hierarchies) with the following relationship:
|
22
22
|
```ruby
|
23
23
|
class Territory < ActiveRecord::Base
|
24
24
|
belongs_to :parent_territory, class_name: 'Territory'
|
25
25
|
end
|
26
26
|
```
|
27
|
-
You have to
|
28
|
-
```
|
29
|
-
|
30
|
-
def change
|
31
|
-
add_column :territories, :lft, :integer
|
32
|
-
add_column :territories, :rgt, :integer
|
33
|
-
end
|
34
|
-
end
|
27
|
+
You have to execute the generator with the code below:
|
28
|
+
```
|
29
|
+
rails g hierarchical_db territories
|
35
30
|
```
|
36
|
-
|
31
|
+
Now your model has the attributes *lft* and *rgt* that are essential to the gem work properly.
|
32
|
+
|
33
|
+
Next into the model you have to include Hierarchies adding the code below:
|
37
34
|
```ruby
|
38
35
|
class Territory < ActiveRecord::Base
|
39
36
|
include HierarchicalDb #we added this
|
@@ -56,7 +53,27 @@ Continuing the example, if you have data inside your Territory model, then you h
|
|
56
53
|
```ruby
|
57
54
|
Territory.sort_tree
|
58
55
|
```
|
59
|
-
This
|
56
|
+
This is a Class method and is imperative to use this after load seeds or when you first enter information inside your model. If you don't have any data inside your model this method doesn't have any sense. On the other hand, if you have data inside your model and you has never executed *sort_tree* then this gem won't work.<br>
|
57
|
+
Sort_tree initializes your tree and fills *lft* and *rgt* attributes with corresponding information.<br>
|
58
|
+
After execute this command you will able to use all useful methods below
|
59
|
+
###Useful Methods
|
60
|
+
|
61
|
+
#####display_tree
|
62
|
+
This is a Class method and returns graphically and tabulated the entire tree. Example:
|
63
|
+
```ruby
|
64
|
+
Territory.display_tree
|
65
|
+
```
|
66
|
+
#####descendants
|
67
|
+
Returns an array with all childrens order by lft attribute, example:
|
68
|
+
```ruby
|
69
|
+
object.descendants
|
70
|
+
```
|
71
|
+
#####descendants_count
|
72
|
+
If you want to know how many descendants has your model, then you can execute:
|
73
|
+
```ruby
|
74
|
+
object.descendants_count
|
75
|
+
```
|
76
|
+
It returns a number of descendants.
|
60
77
|
|
61
78
|
## Development
|
62
79
|
|
data/hierarchical_db.gemspec
CHANGED
data/lib/hierarchical_db.rb
CHANGED
@@ -2,13 +2,15 @@ require "hierarchical_db/version"
|
|
2
2
|
require 'active_support/concern'
|
3
3
|
|
4
4
|
module HierarchicalDb extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
@sorted = 0
|
6
6
|
included do
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
def saludar
|
11
|
-
puts "Hola"
|
11
|
+
puts "Hola: #{self.sorted}"
|
12
|
+
self.sorted = 1
|
13
|
+
puts "Después Hola: #{self.sorted}"
|
12
14
|
end
|
13
15
|
|
14
16
|
def sort_tree
|
@@ -20,6 +22,7 @@ module HierarchicalDb extend ActiveSupport::Concern
|
|
20
22
|
right = 2
|
21
23
|
root_nodes.each{|n| right = n.sort_subtree(right) }
|
22
24
|
end
|
25
|
+
# self.sorted = 1
|
23
26
|
end
|
24
27
|
|
25
28
|
def display_tree
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierarchical_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo
|
@@ -54,17 +54,6 @@ files:
|
|
54
54
|
- Rakefile
|
55
55
|
- bin/console
|
56
56
|
- bin/setup
|
57
|
-
- hierarchical_db-0.0.0.gem
|
58
|
-
- hierarchical_db-0.0.1.gem
|
59
|
-
- hierarchical_db-0.0.2.gem
|
60
|
-
- hierarchical_db-0.0.3.gem
|
61
|
-
- hierarchical_db-0.0.4.gem
|
62
|
-
- hierarchical_db-0.0.5.gem
|
63
|
-
- hierarchical_db-0.0.6.gem
|
64
|
-
- hierarchical_db-0.0.7.gem
|
65
|
-
- hierarchical_db-0.0.8.gem
|
66
|
-
- hierarchical_db-0.0.9.gem
|
67
|
-
- hierarchical_db-0.1.0.gem
|
68
57
|
- hierarchical_db.gemspec
|
69
58
|
- lib/generators/hierarchical_db/templates/migration_existing.rb
|
70
59
|
- lib/generators/hierarchical_db_generator.rb
|
data/hierarchical_db-0.0.0.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.1.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.2.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.3.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.4.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.5.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.6.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.7.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.8.gem
DELETED
Binary file
|
data/hierarchical_db-0.0.9.gem
DELETED
Binary file
|
data/hierarchical_db-0.1.0.gem
DELETED
Binary file
|