tree_structure 0.1.0 → 0.1.1
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/README.md +43 -9
- data/lib/tree_structure/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d032b8c727b5b4e55d53740672656ca1a1a9638d0c71de8d8dd7673581d33a4b
|
4
|
+
data.tar.gz: c82e3c06808f6fb3bec5600a3e2f44e785ba60d0ae7b56a09c4df7f3f9278335
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cefcd2b009f0bb73fee3fbb7307823c43c1a33bfb671085a4ea7704065544b37ec313ba6558b6425cbd896aeb86245621c6c88e11d2e32f5fa0a85ede7708a81
|
7
|
+
data.tar.gz: fd2f6ad0286a9f9b4e4a891b75089c3cfa0a40c875f7c113d0287c0664ce54d0a63b9e9c54708aa2c71c8753026c7270cc8424de7ea7d84cedc5415a22e070be
|
data/README.md
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# TreeStructure
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tree_structure`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
2
|
+
Tree Structure allows the records of a ActiveRecord model to be organized in a tree structure.
|
6
3
|
|
7
4
|
## Installation
|
8
5
|
|
@@ -20,15 +17,52 @@ Or install it yourself as:
|
|
20
17
|
|
21
18
|
$ gem install tree_structure
|
22
19
|
|
23
|
-
##
|
20
|
+
## Development
|
24
21
|
|
25
|
-
|
22
|
+
After installing the `tree_structure` gem in your Gemfile, follow these steps to set up the tree structure:
|
26
23
|
|
27
|
-
|
24
|
+
1. **Add a `parent_id` column** to the table where you want to organize the tree structure. You can do this by creating a migration:
|
25
|
+
```ruby
|
26
|
+
class AddParentIdToYourModel < ActiveRecord::Migration[6.0]
|
27
|
+
def change
|
28
|
+
add_column :your_model_name, :parent_id, :integer
|
29
|
+
add_index :your_model_name, :parent_id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
2. **Include the TreeStructure module** in the model that will be organized in a tree structure. For example:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class YourModelName < ApplicationRecord
|
39
|
+
include TreeStructure
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
3. **Run your migrations** to update the database schema:
|
45
|
+
```ruby
|
46
|
+
rails db:migrate
|
47
|
+
````
|
28
48
|
|
29
|
-
|
49
|
+
### Example Usage
|
50
|
+
|
51
|
+
Once you have set up your model, you can start using the tree structure features. For example:
|
52
|
+
|
53
|
+
# Create root nodes
|
54
|
+
```ruby
|
55
|
+
root1 = YourModelName.create(name: 'Root 1')
|
56
|
+
root2 = YourModelName.create(name: 'Root 2')
|
57
|
+
```
|
58
|
+
|
59
|
+
# Create child nodes
|
60
|
+
```ruby
|
61
|
+
child1 = YourModelName.create(name: 'Child 1', parent: root1)
|
62
|
+
child2 = YourModelName.create(name: 'Child 2', parent: root1)
|
63
|
+
child3 = YourModelName.create(name: 'Child 3', parent: root2)
|
64
|
+
```
|
30
65
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
66
|
|
33
67
|
## Contributing
|
34
68
|
|