Skip to content

Commit

Permalink
Move nesting operator to method.
Browse files Browse the repository at this point in the history
Also doc'd the nesting operator constant.
  • Loading branch information
jnunemaker committed Oct 10, 2012
1 parent 7617e6c commit aba6884
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/plucky/criteria_hash.rb
Expand Up @@ -14,6 +14,8 @@ class CriteriaHash
# criteria hash is simple.
SimpleQueryMaxSize = [SimpleIdQueryKeys.size, SimpleIdAndTypeQueryKeys.size].max

# Internal: Used by normalized_value to determine if we need to run the
# value through another criteria hash to normalize it.
NestingOperators = [:$or, :$and, :$nor]

def initialize(hash={}, options={})
Expand Down Expand Up @@ -138,7 +140,7 @@ def normalized_value(parent_key, key, value)
case value
when Array, Set
value = value.map { |v| Plucky.to_object_id(v) } if object_id?(parent_key)
if NestingOperators.include?(key)
if nesting_operator?(key)
value.map { |v| CriteriaHash.new(v, options).to_hash }
elsif parent_key == key
# we're not nested and not the value for a symbol operator
Expand All @@ -161,5 +163,9 @@ def normalized_value(parent_key, key, value)
value
end
end

def nesting_operator?(key)
NestingOperators.include?(key)
end
end
end

0 comments on commit aba6884

Please sign in to comment.