Easy Resolution of Before/After Relations For Ruby
Depression resolves before/after relations by forming a graph of them and
flattening it. It supports simple before/after as well as "greedy" relations.
Getting Started
$ gem install depression
After installation the first steps are really easy. You simply need a bunch of
objects that respond to #name
as well as #relations
and return something
more or less unique and a hash, resp.
require "depression"
Item = Struct.new(:name, :relations)
items = [
Item.new(:foo, {}),
Item.new(:bar, :before => [:foo]),
Item.new(:baz, :after => [:foo])
]
sorted = Depression.process(items)
puts sorted.map {|i| i.name }.join(",")
# bar,foo,baz
Greedy Relations
TODO
Resolving Conflicts
TODO
Resolving Circular Relations
TODO
Dependencies
Runs fine on Ruby 1.9.2 and JRuby 1.5.6.
To do & Ideas
- Gracefully drop greedy relations if they conflict with normal relations
- Implement a "friendly" mode that simply drops "older" relations until a
circular relation is resolved
- Visualize various stages of relation resolution (probably via GraphViz)
- Maybe switch to TSort
Contributing
- Fork at github.com/lgierth/depression
- Create a new branch
- Commit, commit, commit!
- Open a Pull Request
You can also open an issue for discussion first, if you want.
License
Depression is subject to an MIT-style license that can be found in the LICENSE
file.