Influence include order
Opened this issue · 0 comments
vinzent commented
I've got some parse order dependent code. To be able to switch to this or any external classifier I'd need some way to influence the order the classes are included.
I thought about that the rules could take a key order to sort the rules.
Then (hopefully) the classify::apply each would include them in the desired order.
example in pure ruby:
hsh = {
'rule-z' => {
'match' => 'all',
'rules' => [
{
'fact' => "%{facts.os.name}",
'operator' => '==',
'value' => 'Fedora'
}
],
'classes' => [ 'class-z' ],
'order' => 600,
},
'rule-a' => {
'match' => 'all',
'rules' => [
{
'fact' => "%{facts.os.name}",
'operator' => '==',
'value' => 'Fedora'
}
],
'classes' => [ 'class-a' ],
'order' => 500,
},
}
puts "Original:"
puts hsh
puts
puts "Sorted:"
puts Hash[hsh.sort_by { |k,v| hsh[k]['order'] }]
output:
Original:
{"rule-z"=>{"match"=>"all", "rules"=>[{"fact"=>"%{facts.os.name}", "operator"=>"==", "value"=>"Fedora"}], "classes"=>["class-z"], "order"=>600}, "rule-a"=>{"match"=>"all", "rules"=>[{"fact"=>"%{facts.os.name}", "operator"=>"==", "value"=>"Fedora"}], "classes"=>["class-a"], "order"=>500}}
Sorted:
{"rule-a"=>{"match"=>"all", "rules"=>[{"fact"=>"%{facts.os.name}", "operator"=>"==", "value"=>"Fedora"}], "classes"=>["class-a"], "order"=>500}, "rule-z"=>{"match"=>"all", "rules"=>[{"fact"=>"%{facts.os.name}", "operator"=>"==", "value"=>"Fedora"}], "classes"=>["class-z"], "order"=>600}}