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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8702a58ec4688699a35046a850ce350e00f54f72
4
- data.tar.gz: f71234610e0718fa40f823a92d0d3027d01746a4
3
+ metadata.gz: 861a2dffcff74a32cc269574fe99e5efde59fc2c
4
+ data.tar.gz: 1c07b2bf9a7386b441b8439006f70fadfda6fd60
5
5
  SHA512:
6
- metadata.gz: c3505c248cd6384c9e0794cb5ffb3d090257e8020be9c6c1c90e7b96a7c7c9d43f3b09222d0a140d2b362f73a0ec0dbc3816a175fe77fc455406939c54f6f15b
7
- data.tar.gz: 13529ef441028d66c44d7e6e2ac775c265ea200cba704b6929ee7398cd49cde3e6f7b63b7d09754e7e5748977abab996b48973b0f29b9eccf413c64890305bec
6
+ metadata.gz: 1fe5c03619545c96e4ebcee1b50f59182a5fb59a621238931f443fd1541fa0774cd3b985712267339dfd52af668559d44a65ba076891246dfe1780975714a081
7
+ data.tar.gz: 8c93dd008ced535632adc8d94c5ce97fc1e5491cdc8531fb9bfcddd67fcb8325c3470466fa9d1d103366d124667c94d710a20b467fe0f6fc57f1b29635719f9a
data/.gitignore CHANGED
@@ -1,9 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ pkg
11
+ tmp
12
+ gemfiles/*.lock
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 add a migration into your model with attributes *lft* and *rgt*. For example, if you have a model called *Territory* (to manage countries, cities and all the other hierarchies) with the following relationship:
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 add a migration like this:
28
- ```ruby
29
- class AddSortedTreeFields < ActiveRecord::Migration
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
- Into the model you have to include Hierarchies adding the code below:
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 command initializes your tree and fills *lft* and *rgt* attributes with corresponding information.
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
 
@@ -5,7 +5,7 @@ require 'hierarchical_db/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "hierarchical_db"
8
- spec.version = "0.1.1"
8
+ spec.version = "0.1.2"
9
9
  spec.authors = ["Gustavo"]
10
10
  spec.email = ["ginzunza@rebuss.cl"]
11
11
 
@@ -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.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
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file