Permalink
Browse files

Explicit > method missing for criteria hash

Also used instance variables where possible instead of methods.
  • Loading branch information...
1 parent d32960c commit 33c016fa0e812ab79ed2acb1e3eb8e9c4ac772cc @jnunemaker jnunemaker committed Oct 11, 2012
Showing with 17 additions and 21 deletions.
  1. +17 −13 lib/plucky/criteria_hash.rb
  2. +0 −8 spec/plucky/criteria_hash_spec.rb
@@ -27,39 +27,47 @@ def initialize_copy(original)
super
@options = @options.dup
@source = @source.dup
- each do |key, value|
+ @source.each do |key, value|
self[key] = value.clone if value.duplicable?
end
end
+ def [](key)
+ @source[key]
+ end
+
def []=(key, value)
normalized_key = normalized_key(key)
if key.is_a?(SymbolOperator)
operator = :"$#{key.operator}"
normalized_value = normalized_value(normalized_key, operator, value)
- source[normalized_key] ||= {}
- source[normalized_key][operator] = normalized_value
+ @source[normalized_key] ||= {}
+ @source[normalized_key][operator] = normalized_value
else
if key == :conditions
value.each { |k, v| self[k] = v }
else
normalized_value = normalized_value(normalized_key, normalized_key, value)
- source[normalized_key] = normalized_value
+ @source[normalized_key] = normalized_value
end
end
end
+ def keys
+ @source.keys
+ end
+
def ==(other)
- source == other.source
+ @source == other.source
end
def to_hash
- source
+ @source
end
def merge(other)
- target = source.dup
+ target = @source.dup
other.source.each_key do |key|
value, other_value = target[key], other[key]
target[key] =
@@ -122,10 +130,6 @@ def simple?
key_set == SimpleIdQueryKeys || key_set == SimpleIdAndTypeQueryKeys
end
- def method_missing(method, *args, &block)
- @source.send(method, *args, &block)
- end
-
def object_id?(key)
object_ids.include?(key.to_sym)
end
@@ -135,7 +139,7 @@ def normalized_key(key)
end
def key_normalizer
- @key_normalizer ||= options.fetch(:key_normalizer) {
+ @key_normalizer ||= @options.fetch(:key_normalizer) {
Normalizers::CriteriaHashKey.new
}
end
@@ -145,7 +149,7 @@ def normalized_value(parent_key, key, value)
end
def value_normalizer
- @value_normalizer ||= options.fetch(:value_normalizer) {
+ @value_normalizer ||= @options.fetch(:value_normalizer) {
Normalizers::CriteriaHashValue.new(self)
}
end
@@ -1,14 +1,6 @@
require 'helper'
describe Plucky::CriteriaHash do
- it "delegates missing methods to the source hash" do
- hash = {:baz => 'wick', :foo => 'bar'}
- criteria = described_class.new(hash)
- criteria[:foo].should == 'bar'
- criteria[:baz].should == 'wick'
- criteria.keys.to_set.should == [:baz, :foo].to_set
- end
-
context "#initialize_copy" do
before do
@original = described_class.new({

0 comments on commit 33c016f

Please sign in to comment.