lib/scoped_search/definition.rb in scoped_search-2.7.1 vs lib/scoped_search/definition.rb in scoped_search-3.0.0

- old
+ new

@@ -82,11 +82,15 @@ def column @column ||= begin if klass.columns_hash.has_key?(field.to_s) klass.columns_hash[field.to_s] else - raise ActiveRecord::UnknownAttributeError, "#{klass.inspect} doesn't have column #{field.inspect}." + if "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}".to_f < 4.1 + raise ActiveRecord::UnknownAttributeError, "#{klass.inspect} doesn't have column #{field.inspect}." + else + raise ActiveRecord::UnknownAttributeError.new( klass, field ) + end end end end # Returns the column type of this field. @@ -241,12 +245,10 @@ # Registers the search_for named scope within the class that is used for searching. def register_named_scope! # :nodoc definition = self if @klass.ancestors.include?(ActiveRecord::Base) case ActiveRecord::VERSION::MAJOR - when 2 - @klass.named_scope(:search_for, lambda { |*args| ScopedSearch::QueryBuilder.build_query(definition, args[0], args[1]) }) when 3 @klass.scope(:search_for, lambda { |*args| find_options = ScopedSearch::QueryBuilder.build_query(definition, args[0], args[1]) search_scope = @klass.scoped search_scope = search_scope.where(find_options[:conditions]) if find_options[:conditions] @@ -256,11 +258,11 @@ search_scope }) when 4 @klass.scope(:search_for, lambda { |*args| find_options = ScopedSearch::QueryBuilder.build_query(definition, args[0], args[1]) - search_scope = @klass.all + search_scope = @klass search_scope = search_scope.where(find_options[:conditions]) if find_options[:conditions] search_scope = search_scope.includes(find_options[:include]) if find_options[:include] search_scope = search_scope.references(find_options[:include]) if find_options[:include] search_scope = search_scope.joins(find_options[:joins]) if find_options[:joins] search_scope = search_scope.reorder(find_options[:order]) if find_options[:order] @@ -268,10 +270,10 @@ }) else raise "This ActiveRecord version is currently not supported!" end else - raise "Currently, only ActiveRecord 2.1 or higher is supported!" + raise "Currently, only ActiveRecord 3 or newer is supported!" end end # Registers the complete_for method within the class that is used for searching. def register_complete_for! # :nodoc