Skip to content

spox/grimoire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grimoire

Light weight generic dependency resolver. Supports weighted solutions via scored units.

Usage

Basic usage flow:

  • Create a system
system = Grimoire::System.new
  • Add units
system.add_units(
  Grimoire::Unit.new(
    :name => 'unit1',
    :version => '1.0.0'
  ),
  Grimoire::Unit.new(
    :name => 'unit1',
    :version => '1.1.0'
  ),
  ...
)
  • Create a score keeper

NOTE: Score keeper is optional and must be subclassed. This example will not actually work.

score_keeper = Grimoire::ScoreKeeper.new
  • Create solver
solver = Grimoire::Solver.new(
  :system => system,
  :score_keeper => score_keeper,
  :requirements => [
    ['unit1', '> 2.0.0'],
    ['unit2', '> 1', '< 3']
  ]
)
  • Create a solver with restrictions (optional)
solver = Grimoire::Solver.new(
  :system => system,
  :score_keeper => score_keeper,
  :requirements => [
    ['unit1', '> 2.0.0'],
    ['unit2', '> 1', '< 3']
  ],
  :restrictions => [
    ['unit1', '< 3'],
    ['unit2', '> 1.2.0']
  ]
)
  • Generate solutions
solutions = solver.generate!
p solutions.pop

The ideal solution will be the first path on the queue.

Info