Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move key normalization to method.

  • Loading branch information...
commit dcc2f476cca1ed7a661a8baa2327e9cdf06ac850 1 parent 873619d
@jnunemaker jnunemaker authored
Showing with 17 additions and 5 deletions.
  1. +17 −5 lib/plucky/query.rb
View
22 lib/plucky/query.rb
@@ -192,9 +192,9 @@ 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]
@@ -202,9 +202,9 @@ def [](key)
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
Please sign in to comment.
Something went wrong with that request. Please try again.