Last active
December 20, 2015 17:29
-
-
Save andrebras/6168810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Automation::RulePatternFactory < Ruleby::Rulebook | |
include Ruleby | |
def patterns_from rules = [] | |
@rules = rules | |
build_rules | |
end | |
protected | |
def build_rules | |
@rules.each do |r| | |
klass = r.entity_type.constantize | |
klass_ref = r.entity_type.delete( r.entity_type.tr '^:', '' ).underscore.to_sym | |
pattern = [klass, klass_ref, -> { m.id == r.entity_id }] | |
if r.conditions.nil? || r.conditions.empty? | |
pattern | |
else | |
r.conditions.each { |c| pattern << [klass, klass_ref, -> {m.send(c.key) == c.value}] } | |
pattern | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment