forestify 1.0.2 → 1.0.3

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.
@@ -0,0 +1,5 @@
1
+ Usage :
2
+
3
+ rails generate forestify Model
4
+
5
+ This generator will create a migration to add the necessary columns to your model.
@@ -0,0 +1,30 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ # See https://github.com/olkarls/has_permalink/blob/master/lib/generators/has_permalink_generator.rb
4
+ class ForestifyGenerator < ActiveRecord::Generators::Base
5
+
6
+ desc "This generator creates a migration file to make your existing model 'forestify-ready'"
7
+
8
+ def self.source_root
9
+ @source_root ||= File.expand_path('../templates', __FILE__)
10
+ end
11
+
12
+ def generate_migration
13
+ migration_template "forestify_migration.rb.erb", "db/migrate/#{migration_file_name}"
14
+ end
15
+
16
+ protected
17
+
18
+ def migration_name
19
+ "add_forestify_to_#{name.underscore}"
20
+ end
21
+
22
+ def migration_file_name
23
+ "#{migration_name}.rb"
24
+ end
25
+
26
+ def migration_class_name
27
+ migration_name.camelize
28
+ end
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+
3
+ def self.change
4
+ change_table :<%= name.underscore.camelize.tableize %> do |t|
5
+ t.integer :forestify_left_position
6
+ t.integer :forestify_right_position
7
+ t.integer :forestify_level
8
+ end
9
+ end
10
+
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forestify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -17,8 +17,9 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - README.md
21
- - LICENSE
20
+ - lib/generators/templates/forestify_migration.rb.erb
21
+ - lib/generators/forestify_generator.rb
22
+ - lib/generators/USAGE
22
23
  - lib/forestify.rb
23
24
  homepage: ''
24
25
  licenses:
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2012 Gabriel Malkas
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,67 +0,0 @@
1
- # forestify
2
-
3
- forestify creates forests out of your Active Record models : it implements a simple data-structure which hierarchizes your data.
4
-
5
- For example, given the following model :
6
-
7
- ```ruby
8
- class Tag < ActiveRecord::Base
9
- attr_accessible :name
10
- forestify
11
- end
12
- ```
13
-
14
- You can then do something like this :
15
-
16
- ```ruby
17
- # This produces the following tree
18
- # { left_position, name, right_position, level }
19
- # { 0, Vehicle, 9, 0 } { 10, Animal, 11, 0}
20
- # { 1, Car, 4, 1 } { 5, Plane, 6, 1 } { 7, Boat, 8, 1 }
21
- # { 2, Audi, 3, 2}
22
-
23
- vehicle = Tag.create!(name: "Vehicle")
24
- animal = Tag.create!(name: "Animal")
25
- car = Tag.create!(name: "Car", parent_id: vehicle.id)
26
- plane = Tag.create!(name: "plane", parent_id: vehicle.id)
27
- boat = Tag.create!(name: "Boat", parent_id: vehicle.id)
28
- audi = Tag.create!(name: "Audi", parent_id: car.id)
29
-
30
- [vehicle, animal, car, plane, boat, audi].each { |n| n.reload }
31
-
32
- audi.parents
33
- # => [vehicle, car]
34
- car.leaf?
35
- # => false
36
- car.node?
37
- # => true
38
- vehicle.parent.nil?
39
- # => true
40
- car.siblings.all
41
- # => [plane, boat]
42
- ```
43
-
44
- # Installation
45
-
46
- Run ```gem install forestify``` or add this line to your Gemfile ```gem 'forestify'``` then run ```bundle install```
47
-
48
- Although I will add generators later, you still need to manually add migrations to make your models "forestify-ready".
49
-
50
- ```ruby
51
- change_table :tags do |t|
52
- t.integer :left_position
53
- t.integer :right_position
54
- t.integer :level
55
- end
56
- ```
57
-
58
- # Updates
59
- ## 2012-02-06 version 1.0.1
60
- * Cleaned up tests, added two methods: 'siblings' and 'parent'
61
-
62
- ## 2012-02-05 version 1.0.0
63
- * First draft
64
-
65
- # LICENSE
66
-
67
- Copyright 2012 Gabriel Malkas. Released under MIT License. See LICENSE for details.