Permalink
Browse files

Move key normalization to method.

  • Loading branch information...
1 parent 873619d commit dcc2f476cca1ed7a661a8baa2327e9cdf06ac850 @jnunemaker jnunemaker committed Oct 10, 2012
Showing with 17 additions and 5 deletions.
  1. +17 −5 lib/plucky/query.rb
View
@@ -192,19 +192,19 @@ def amend(opts={})
end
def [](key)
- key = key.to_sym if key.respond_to?(:to_sym)
+ key = normalized_key(key)
- if OptionKeys.include?(key)
+ if options_key?(key)
@options[key]
else
@criteria[key]
end
end
def []=(key, value)
- key = key.to_sym if key.respond_to?(:to_sym)
+ key = normalized_key(key)
- if OptionKeys.include?(key)
+ if options_key?(key)
@options[key] = value
else
@criteria[key] = value
@@ -234,9 +234,21 @@ def inspect
private
+ def normalized_key(key)
+ if key.respond_to?(:to_sym)
+ key.to_sym
+ else
+ key
+ end
+ end
+
+ def options_key?(key)
+ OptionKeys.include?(key)
+ end
+
def set_field_inclusion(fields, value)
fields_option = {}
- fields.each { |field| fields_option[field.to_sym] = value }
+ fields.each { |field| fields_option[normalized_key(field)] = value }
clone.tap { |query| query.options[:fields] = fields_option }
end
end

0 comments on commit dcc2f47

Please sign in to comment.