Commit 3808bd6
Changed files (1)
app
models
scim
app/models/scim/visitor.rb
@@ -2,15 +2,19 @@
module Scim
class Visitor
- def self.result_for(tree)
+ def initialize(attribute_mappings = {})
+ @attribute_mappings = attribute_mappings
+ end
+
+ def visit(tree)
attribute = tree[:attribute].to_s
- attr = SCIM::User::ATTRIBUTES[attribute] || attribute
+ attr = @attribute_mappings[attribute] || attribute
case tree[:operator].to_s
when 'and'
- result_for(tree[:left]).merge(result_for(tree[:right]))
+ visit(tree[:left]).merge(visit(tree[:right]))
when 'or'
- result_for(tree[:left]).or(result_for(tree[:right]))
+ visit(tree[:left]).or(visit(tree[:right]))
when 'eq'
User.where(attr => tree[:value].to_s[1..-2])
when 'ne'
@@ -41,5 +45,9 @@ module Scim
User.none
end
end
+
+ def self.result_for(tree)
+ new(SCIM::User::ATTRIBUTES).visit(tree)
+ end
end
end