Browse files

bug fix: & and | operations should not influence operands object

  • Loading branch information...
1 parent 26f9d79 commit 30c1f653b6c795de94d9b4c4449fea652fd746bf Olga.QuickLizard committed Oct 23, 2011
Showing with 14 additions and 13 deletions.
  1. +8 −8 lib/de/de.rb
  2. +5 −4 lib/de/sunspot_solr/search.rb
  3. +1 −1 lib/de/version.rb
View
16 lib/de/de.rb
@@ -114,6 +114,13 @@ def to_s
str
end
+ def copy
+ obj = self.clone
+ obj.parent = nil
+
+ obj
+ end
+
# def to_hash
# {
# :name => @name,
@@ -128,14 +135,7 @@ class << self
# def load(hash)
# raise Error::InvalidExpressionError if (hash.keys - [:name, :content, :class, :children]).length > 0
#
-# klass = hash[:class].constantize
-# params = case klass.method(:new).arity
-# when -1,0 then []
-# when -2,1 then [hash[:name]]
-# else [hash[:name], hash[:content]]
-# end
-#
-# obj = klass.send(:new, *params)
+# obj = hash[:class].constantize.send(:new, hash[:name], hash[:content])
# hash[:children].each { |child| obj << load(child) }
# end
end
View
9 lib/de/sunspot_solr/search.rb
@@ -126,7 +126,8 @@ def ==(obj)
# Search object
#
def &(obj)
- Search.new("#{@name}+#{obj.name}", @klass, @options, [self.children, obj.children].flatten)
+ children = (self.children + obj.children).collect { |child| child.copy }
+ Search.new("#{@name}+#{obj.name}", @klass, @options, children)
end
#
@@ -146,12 +147,12 @@ def |(obj)
[self, obj].select { |element| element.has_children? }.each do |element|
if element.children.length == 1
if element.first_child.is_a?(De::SunspotSolr::Or)
- element.first_child.children.each { |child| expression_content << child }
+ element.first_child.children.each { |child| expression_content << child.copy }
else
- expression_content << element.first_child
+ expression_content << element.first_child.copy
end
else
- expression_content << SunspotSolr::And.new(element.children)
+ expression_content << SunspotSolr::And.new(element.children.collect { |child| child.copy })
end
end
View
2 lib/de/version.rb
@@ -1,3 +1,3 @@
module De
- VERSION = "0.0.5"
+ VERSION = "0.0.6"
end

0 comments on commit 30c1f65

Please sign in to comment.