https://github.com/flanker/acts_as_graph
Add graph(DAG) support to your Ruby models
https://github.com/flanker/acts_as_graph
ruby rubygem
Last synced: 6 months ago
JSON representation
Add graph(DAG) support to your Ruby models
- Host: GitHub
- URL: https://github.com/flanker/acts_as_graph
- Owner: flanker
- Created: 2018-05-10T02:52:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T01:38:58.000Z (over 4 years ago)
- Last Synced: 2025-06-19T03:53:01.400Z (7 months ago)
- Topics: ruby, rubygem
- Language: Ruby
- Homepage: https://rubygems.org/gems/acts_as_graph
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# acts_as_graph
[](https://travis-ci.com/flanker/acts_as_graph)
A very simple acts as graph for your model
rubygems.org link: https://rubygems.org/gems/acts_as_graph
## How to use
If you have a model like this code below:
```ruby
class Task
attr_reader :title
attr_accessor :depended_tasks
def initialize title, depended_tasks = []
@title = title
@depended_tasks = depended_tasks
end
end
```
Then you could use `acts_as_graph`
```ruby
class Task
include ActsAsGraph
acts_as_graph children: :depended_tasks
attr_reader :title
attr_accessor :depended_tasks
def initialize title, depended_tasks = []
@title = title
@depended_tasks = depended_tasks
end
end
```
And Then:
```ruby
task.descendant_depended_tasks # returns all the descendant
task.has_circular_reference? # check if descendant has circular reference
```
[Check unit tests for more information](https://github.com/flanker/acts_as_graph/blob/master/spec/acts_as_graph_spec.rb)