searchlogic 2.1.12 → 2.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 2.1.13 released 2009-07-29
2
+
3
+ * Applied bug fix from http://github.com/skanev/searchlogic to make #order work with association ordering.
4
+ * Applied bug fix to allow for custom ordering conditions.
5
+
1
6
  == 2.1.12 released 2009-07-28
2
7
 
3
8
  * Fixed bug when dealing with scopes that return nil.
data/README.rdoc CHANGED
@@ -1,7 +1,5 @@
1
1
  = Searchlogic
2
2
 
3
- <b>Searchlogic has been <em>completely</em> rewritten for v2. It is much simpler and has taken an entirely new approach. To give you an idea, v1 had ~2300 lines of code, v2 has ~420 lines of code.</b>
4
-
5
3
  Searchlogic provides common named scopes and object based searching for ActiveRecord.
6
4
 
7
5
  == Helpful links
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 12
2
+ :patch: 13
3
3
  :major: 2
4
4
  :minor: 1
@@ -8,9 +8,10 @@ module Searchlogic
8
8
  end
9
9
  end
10
10
 
11
- # In AR multiple joins are sometimes in a single join query, and other time they
11
+ # In AR multiple joins are sometimes in a single join query, and other times they
12
12
  # are not. The merge_joins method in AR should account for this, but it doesn't.
13
- # This fixes that problem.
13
+ # This fixes that problem. This way there is one join per string, which allows
14
+ # the merge_joins method to delete duplicates.
14
15
  def merge_joins_with_searchlogic(*args)
15
16
  joins = merge_joins_without_searchlogic(*args)
16
17
  joins.collect { |j| j.is_a?(String) ? j.split(" ") : j }.flatten.uniq
@@ -27,8 +27,10 @@ module Searchlogic
27
27
  #
28
28
  # named_scope :id_gt, searchlogic_lambda(:integer) { |value| {:conditions => ["id > ?", value]} }
29
29
  #
30
- # If you are wanting a string, you don't have to do anything, because Searchlogic assumes you are want a string.
31
- # If you want something else, you need to specify it as I did in the above example.
30
+ # If you are wanting a string, you don't have to do anything, because Searchlogic assumes you want a string.
31
+ # If you want something else, you need to specify it as I did in the above example. Comments are appreciated
32
+ # on this, if you know of a better solution please let me know. But this is the best I could come up with,
33
+ # without being intrusive and altering default behavior.
32
34
  def searchlogic_lambda(type = :string, &block)
33
35
  proc = lambda(&block)
34
36
  proc.searchlogic_arg_type = type
@@ -23,14 +23,17 @@ module Searchlogic
23
23
  !association_condition_details(name).nil?
24
24
  end
25
25
 
26
- # Is the ane of the method a valie name for an association alias condition?
26
+ # Is the named of the method a valid name for an association alias condition?
27
27
  # An alias being "gt" for "greater_than", etc.
28
28
  def association_alias_condition?(name)
29
29
  !association_alias_condition_details(name).nil?
30
30
  end
31
31
 
32
32
  # A convenience method for creating inner join sql to that your inner joins
33
- # are consistent with how Active Record creates them.
33
+ # are consistent with how Active Record creates them. Basically a tool for
34
+ # you to use when writing your own named scopes. This way you know for sure
35
+ # that duplicate joins will be removed when chaining scopes together that
36
+ # use the same join.
34
37
  def inner_joins(association_name)
35
38
  ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, association_name, nil).join_associations.collect { |assoc| assoc.association_join }
36
39
  end
@@ -2,6 +2,10 @@ module Searchlogic
2
2
  module NamedScopes
3
3
  # Handles dynamically creating named scopes for associations.
4
4
  module AssociationOrdering
5
+ def association_ordering_condition?(name)
6
+ !association_ordering_condition_details(name).nil?
7
+ end
8
+
5
9
  private
6
10
  def method_missing(name, *args, &block)
7
11
  if details = association_ordering_condition_details(name)
@@ -28,6 +28,7 @@ module Searchlogic
28
28
 
29
29
  CONDITIONS = {}
30
30
 
31
+ # Add any / all variations to every comparison and wildcard condition
31
32
  COMPARISON_CONDITIONS.merge(WILDCARD_CONDITIONS).each do |condition, aliases|
32
33
  CONDITIONS[condition] = aliases
33
34
  CONDITIONS["#{condition}_any".to_sym] = aliases.collect { |a| "#{a}_any".to_sym }
@@ -47,7 +48,7 @@ module Searchlogic
47
48
  #
48
49
  # :conditions => {:column => value}
49
50
  #
50
- # ActiveRecord hides this internally, so we have to try and pull it out with this
51
+ # ActiveRecord hides this internally in a Proc, so we have to try and pull it out with this
51
52
  # method.
52
53
  def named_scope_options(name)
53
54
  key = scopes.key?(name.to_sym) ? name.to_sym : primary_condition_name(name)
@@ -68,7 +69,8 @@ module Searchlogic
68
69
  # User.search(:age_is_4 => true) == User.all(:conditions => {:age => 4})
69
70
  #
70
71
  # We also use it when trying to "copy" the underlying named scope for association
71
- # conditions.
72
+ # conditions. This way our aliased scope accepts the same number of parameters for
73
+ # the underlying scope.
72
74
  def named_scope_arity(name)
73
75
  options = named_scope_options(name)
74
76
  options.respond_to?(:arity) ? options.arity : nil
@@ -19,12 +19,16 @@ module Searchlogic
19
19
  def order_condition?(name) # :nodoc:
20
20
  !order_condition_details(name).nil?
21
21
  end
22
+
23
+ def custom_order_condition?(name) # :nodoc:
24
+ !custom_order_condition_details(name).nil?
25
+ end
22
26
 
23
27
  private
24
28
  def method_missing(name, *args, &block)
25
29
  if name == :order
26
30
  named_scope name, lambda { |scope_name|
27
- return {} if !order_condition?(scope_name)
31
+ return {} if !order_condition?(scope_name) && !custom_order_condition?(scope_name) && !association_ordering_condition?(scope_name)
28
32
  send(scope_name).proxy_options
29
33
  }
30
34
  send(name, *args)
@@ -43,6 +47,12 @@ module Searchlogic
43
47
  {}
44
48
  end
45
49
  end
50
+
51
+ def custom_order_condition_details(name)
52
+ if name.to_s =~ /^(ascend|descend)_by_(.+)$/
53
+ {:order_as => $1, :scope => name.to_sym}
54
+ end
55
+ end
46
56
 
47
57
  def create_order_conditions(column)
48
58
  named_scope("ascend_by_#{column}".to_sym, {:order => "#{table_name}.#{column} ASC"})
data/searchlogic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{searchlogic}
5
- s.version = "2.1.12"
5
+ s.version = "2.1.13"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Johnson of Binary Logic"]
9
- s.date = %q{2009-07-28}
9
+ s.date = %q{2009-07-29}
10
10
  s.description = %q{Searchlogic provides common named scopes and object based searching for ActiveRecord.}
11
11
  s.email = %q{bjohnson@binarylogic.com}
12
12
  s.extra_rdoc_files = [
@@ -20,4 +20,8 @@ describe "Association Ordering" do
20
20
  it "should ascend with a belongs to" do
21
21
  User.ascend_by_company_name.proxy_options.should == Company.ascend_by_name.proxy_options.merge(:joins => :company)
22
22
  end
23
+
24
+ it "should work through #order" do
25
+ Company.order('ascend_by_users_username').proxy_options.should == Company.ascend_by_users_username.proxy_options
26
+ end
23
27
  end
@@ -20,6 +20,13 @@ describe "Ordering" do
20
20
  it "should have order" do
21
21
  User.order("ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
22
22
  end
23
+
24
+ it "should have order by custom scope" do
25
+ User.column_names.should_not include("custom")
26
+ %w(bjohnson thunt fisons).each { |username| User.create(:username => username) }
27
+ User.named_scope(:ascend_by_custom, :order => "username ASC, name DESC")
28
+ User.order("ascend_by_custom").proxy_options.should == User.ascend_by_custom.proxy_options
29
+ end
23
30
 
24
31
  it "should have priorty to columns over conflicting association columns" do
25
32
  Company.ascend_by_users_count
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.12
4
+ version: 2.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-28 00:00:00 -04:00
12
+ date: 2009-07-29 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency