searchlogic 2.4.32 → 2.5.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.ruby-version +1 -0
  4. data/Appraisals +6 -0
  5. data/Gemfile +2 -10
  6. data/Gemfile.lock +29 -29
  7. data/README.rdoc +2 -0
  8. data/Rakefile +4 -21
  9. data/gemfiles/ar2.3.10.gemfile +7 -0
  10. data/gemfiles/ar2.3.10.gemfile.lock +28 -0
  11. data/gemfiles/ar2.3.11.gemfile +7 -0
  12. data/gemfiles/ar2.3.11.gemfile.lock +28 -0
  13. data/gemfiles/ar2.3.12.gemfile +7 -0
  14. data/gemfiles/ar2.3.12.gemfile.lock +28 -0
  15. data/gemfiles/ar2.3.14.gemfile +7 -0
  16. data/gemfiles/ar2.3.14.gemfile.lock +28 -0
  17. data/gemfiles/ar2.3.9.gemfile +7 -0
  18. data/gemfiles/ar2.3.9.gemfile.lock +28 -0
  19. data/lib/searchlogic/active_record/consistency.rb +4 -4
  20. data/lib/searchlogic/active_record/named_scope_tools.rb +7 -7
  21. data/lib/searchlogic/active_record/scope.rb +30 -0
  22. data/lib/searchlogic/core_ext/proc.rb +1 -1
  23. data/lib/searchlogic/named_scopes/alias_scope.rb +15 -14
  24. data/lib/searchlogic/named_scopes/association_conditions.rb +16 -16
  25. data/lib/searchlogic/named_scopes/association_ordering.rb +8 -9
  26. data/lib/searchlogic/named_scopes/base.rb +16 -0
  27. data/lib/searchlogic/named_scopes/{conditions.rb → column_conditions.rb} +47 -28
  28. data/lib/searchlogic/named_scopes/or_conditions.rb +65 -37
  29. data/lib/searchlogic/named_scopes/ordering.rb +9 -10
  30. data/lib/searchlogic/rails_helpers.rb +5 -1
  31. data/lib/searchlogic/search/conditions.rb +4 -4
  32. data/lib/searchlogic/search/method_missing.rb +7 -12
  33. data/lib/searchlogic/search/ordering.rb +5 -1
  34. data/lib/searchlogic/search/to_yaml.rb +2 -2
  35. data/lib/searchlogic/version.rb +3 -0
  36. data/lib/searchlogic.rb +9 -9
  37. data/searchlogic.gemspec +21 -92
  38. data/spec/searchlogic/active_record/association_proxy_spec.rb +1 -1
  39. data/spec/searchlogic/active_record/consistency_spec.rb +1 -1
  40. data/spec/searchlogic/core_ext/object_spec.rb +1 -1
  41. data/spec/searchlogic/core_ext/proc_spec.rb +1 -1
  42. data/spec/searchlogic/named_scopes/alias_scope_spec.rb +9 -2
  43. data/spec/searchlogic/named_scopes/association_conditions_spec.rb +34 -1
  44. data/spec/searchlogic/named_scopes/association_ordering_spec.rb +1 -1
  45. data/spec/searchlogic/named_scopes/{conditions_spec.rb → column_conditions_spec.rb} +16 -5
  46. data/spec/searchlogic/named_scopes/or_conditions_spec.rb +33 -15
  47. data/spec/searchlogic/named_scopes/ordering_spec.rb +4 -10
  48. data/spec/searchlogic/search_spec.rb +105 -74
  49. data/spec/spec_helper.rb +10 -12
  50. metadata +136 -60
  51. data/VERSION.yml +0 -5
  52. data/lib/searchlogic/active_record/association_proxy.rb +0 -20
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f864b236c2dc4226146369b7231f7d83d895e35
4
+ data.tar.gz: 0b59222c85aa6367414d20842c9845146b21e42c
5
+ SHA512:
6
+ metadata.gz: a7b667cbce3a1ebd1e278a3f1a232a52c208b6d0f21456db2a58006ebe1e4cab8ec01c559b331a9d6210effea033023aa72694fb088dc492d179ebb8deb406be
7
+ data.tar.gz: 898cc067511831ac102fd3004dd2726466a03fcf5a77ff7cf0be9c2e03f70377d5e7b3823a1cc7a00f705ab2b35951b7a199e17291d254de1c5af70fb578a5e7
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ *.log
3
+ pkg/*
4
+ coverage/*
5
+ doc/*
6
+ benchmarks/*
7
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
data/Appraisals ADDED
@@ -0,0 +1,6 @@
1
+ [9,10,11,12,14].each do |i|
2
+ appraise "ar2.3.#{i}" do
3
+ gem 'activerecord', "2.3.#{i}"
4
+ end
5
+ end
6
+
data/Gemfile CHANGED
@@ -1,10 +1,2 @@
1
- source :rubygems
2
-
3
- gem 'activerecord', '~> 2.3.11'
4
-
5
- group :test do
6
- gem 'jeweler'
7
- gem 'ruby-debug19'
8
- gem 'rspec', '1.3.1'
9
- gem 'sqlite3'
10
- end
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,38 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ searchlogic (2.5.17)
5
+ activerecord (~> 2.3.12)
6
+ activesupport (~> 2.3.12)
7
+
1
8
  GEM
2
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
3
10
  specs:
4
- activerecord (2.3.11)
5
- activesupport (= 2.3.11)
6
- activesupport (2.3.11)
7
- archive-tar-minitar (0.5.2)
8
- columnize (0.3.2)
9
- git (1.2.5)
10
- jeweler (1.5.2)
11
- bundler (~> 1.0.0)
12
- git (>= 1.2.5)
11
+ activerecord (2.3.18)
12
+ activesupport (= 2.3.18)
13
+ activesupport (2.3.18)
14
+ appraisal (0.4.1)
15
+ bundler
13
16
  rake
14
- linecache19 (0.5.11)
15
- ruby_core_source (>= 0.1.4)
16
- rake (0.8.7)
17
- rspec (1.3.1)
18
- ruby-debug-base19 (0.11.24)
19
- columnize (>= 0.3.1)
20
- linecache19 (>= 0.5.11)
21
- ruby_core_source (>= 0.1.4)
22
- ruby-debug19 (0.11.6)
23
- columnize (>= 0.3.1)
24
- linecache19 (>= 0.5.11)
25
- ruby-debug-base19 (>= 0.11.19)
26
- ruby_core_source (0.1.4)
27
- archive-tar-minitar (>= 0.5.2)
28
- sqlite3 (1.3.3)
17
+ coderay (1.1.0)
18
+ method_source (0.8.2)
19
+ pry (0.9.12.6)
20
+ coderay (~> 1.0)
21
+ method_source (~> 0.8)
22
+ slop (~> 3.4)
23
+ rake (10.1.1)
24
+ rspec (1.3.2)
25
+ slop (3.4.7)
26
+ sqlite3 (1.3.8)
27
+ timecop (0.5.9.2)
29
28
 
30
29
  PLATFORMS
31
30
  ruby
32
31
 
33
32
  DEPENDENCIES
34
- activerecord (~> 2.3.11)
35
- jeweler
36
- rspec (= 1.3.1)
37
- ruby-debug19
33
+ appraisal (= 0.4.1)
34
+ pry
35
+ rspec (~> 1.3.1)
36
+ searchlogic!
38
37
  sqlite3
38
+ timecop (~> 0.5.9.1)
data/README.rdoc CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Searchlogic makes using ActiveRecord named scopes easier and less repetitive. It helps keep your code DRY, clean, and simple.
4
4
 
5
+ The specs pass with ActiveRecord 2.3.9 - 2.3.14 on Ruby 1.9.3-p125, 1.9.2-p318, and 1.8.7-p358
6
+
5
7
  == Helpful links
6
8
 
7
9
  * <b>Documentation:</b> http://rdoc.info/projects/binarylogic/searchlogic
data/Rakefile CHANGED
@@ -1,26 +1,9 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'bundler'
4
-
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
5
3
  Bundler.setup
6
-
7
- begin
8
- require 'jeweler'
9
- Jeweler::Tasks.new do |gem|
10
- gem.name = "searchlogic"
11
- gem.summary = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
12
- gem.description = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
13
- gem.email = "bjohnson@binarylogic.com"
14
- gem.homepage = "http://github.com/binarylogic/searchlogic"
15
- gem.authors = ["Ben Johnson of Binary Logic"]
16
- gem.add_bundler_dependencies
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
- end
22
-
4
+ require 'appraisal'
23
5
  require 'spec/rake/spectask'
6
+
24
7
  Spec::Rake::SpecTask.new(:spec) do |spec|
25
8
  spec.libs << 'lib' << 'spec'
26
9
  spec.spec_files = FileList['spec/**/*_spec.rb']
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "activerecord", "2.3.10"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: /Users/john/code/searchlogic
3
+ specs:
4
+ searchlogic (2.5.8)
5
+ activerecord (~> 2.3.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activerecord (2.3.10)
11
+ activesupport (= 2.3.10)
12
+ activesupport (2.3.10)
13
+ appraisal (0.4.1)
14
+ bundler
15
+ rake
16
+ rake (0.9.2.2)
17
+ rspec (1.3.2)
18
+ sqlite3 (1.3.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ activerecord (= 2.3.10)
25
+ appraisal (= 0.4.1)
26
+ rspec (~> 1.3.1)
27
+ searchlogic!
28
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "activerecord", "2.3.11"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: /Users/john/code/searchlogic
3
+ specs:
4
+ searchlogic (2.5.8)
5
+ activerecord (~> 2.3.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activerecord (2.3.11)
11
+ activesupport (= 2.3.11)
12
+ activesupport (2.3.11)
13
+ appraisal (0.4.1)
14
+ bundler
15
+ rake
16
+ rake (0.9.2.2)
17
+ rspec (1.3.2)
18
+ sqlite3 (1.3.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ activerecord (= 2.3.11)
25
+ appraisal (= 0.4.1)
26
+ rspec (~> 1.3.1)
27
+ searchlogic!
28
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "activerecord", "2.3.12"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: /Users/john/code/searchlogic
3
+ specs:
4
+ searchlogic (2.5.8)
5
+ activerecord (~> 2.3.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activerecord (2.3.12)
11
+ activesupport (= 2.3.12)
12
+ activesupport (2.3.12)
13
+ appraisal (0.4.1)
14
+ bundler
15
+ rake
16
+ rake (0.9.2.2)
17
+ rspec (1.3.2)
18
+ sqlite3 (1.3.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ activerecord (= 2.3.12)
25
+ appraisal (= 0.4.1)
26
+ rspec (~> 1.3.1)
27
+ searchlogic!
28
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "activerecord", "2.3.14"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: /Users/john/code/searchlogic
3
+ specs:
4
+ searchlogic (2.5.8)
5
+ activerecord (~> 2.3.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activerecord (2.3.14)
11
+ activesupport (= 2.3.14)
12
+ activesupport (2.3.14)
13
+ appraisal (0.4.1)
14
+ bundler
15
+ rake
16
+ rake (0.9.2.2)
17
+ rspec (1.3.2)
18
+ sqlite3 (1.3.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ activerecord (= 2.3.14)
25
+ appraisal (= 0.4.1)
26
+ rspec (~> 1.3.1)
27
+ searchlogic!
28
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "activerecord", "2.3.9"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: /Users/john/code/searchlogic
3
+ specs:
4
+ searchlogic (2.5.8)
5
+ activerecord (~> 2.3.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activerecord (2.3.9)
11
+ activesupport (= 2.3.9)
12
+ activesupport (2.3.9)
13
+ appraisal (0.4.1)
14
+ bundler
15
+ rake
16
+ rake (0.9.2.2)
17
+ rspec (1.3.2)
18
+ sqlite3 (1.3.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ activerecord (= 2.3.9)
25
+ appraisal (= 0.4.1)
26
+ rspec (~> 1.3.1)
27
+ searchlogic!
28
+ sqlite3
@@ -10,7 +10,7 @@ module Searchlogic
10
10
  alias_method_chain :merge_joins, :merged_duplicates
11
11
  end
12
12
  end
13
-
13
+
14
14
  # In AR multiple joins are sometimes in a single join query, and other times they
15
15
  # are not. The merge_joins method in AR should account for this, but it doesn't.
16
16
  # This fixes that problem. This way there is one join per string, which allows
@@ -19,7 +19,7 @@ module Searchlogic
19
19
  joins = merge_joins_without_singularity(*args)
20
20
  joins.collect { |j| j.is_a?(String) ? j.split(" ") : j }.flatten.uniq
21
21
  end
22
-
22
+
23
23
  # This method ensures that the order of the conditions in the joins are the same.
24
24
  # The strings of the joins MUST be exactly the same for AR to remove the duplicates.
25
25
  # AR is not consistent in this approach, resulting in duplicate joins errors when
@@ -38,8 +38,8 @@ module Searchlogic
38
38
  end
39
39
  end.uniq
40
40
  end
41
-
42
-
41
+
42
+
43
43
  def merge_joins_with_merged_duplicates(*args)
44
44
  args << "" if !Thread.current["searchlogic_delegation"]
45
45
  joins = merge_joins_without_merged_duplicates(*args)
@@ -14,14 +14,14 @@ module Searchlogic
14
14
  # method.
15
15
  def named_scope_options(name)
16
16
  key = scopes.key?(name.to_sym) ? name.to_sym : condition_scope_name(name)
17
-
18
- if key
17
+
18
+ if key && scopes[key]
19
19
  eval("options", scopes[key].binding)
20
20
  else
21
21
  nil
22
22
  end
23
23
  end
24
-
24
+
25
25
  # The arity for a named scope's proc is important, because we use the arity
26
26
  # to determine if the condition should be ignored when calling the search method.
27
27
  # If the condition is false and the arity is 0, then we skip it all together. Ex:
@@ -37,7 +37,7 @@ module Searchlogic
37
37
  options = named_scope_options(name)
38
38
  options.respond_to?(:arity) ? options.arity : nil
39
39
  end
40
-
40
+
41
41
  # When searchlogic calls a named_scope on a foreigh model it will execute that scope and then call scope(:find).
42
42
  # When we get these options we want this to be in an exclusive scope, especially if we are calling a condition on
43
43
  # the same originating model:
@@ -58,7 +58,7 @@ module Searchlogic
58
58
  with_exclusive_scope(&block)
59
59
  Thread.current["searchlogic_delegation"] = old
60
60
  end
61
-
61
+
62
62
  # A convenience method for creating inner join sql to that your inner joins
63
63
  # are consistent with how Active Record creates them. Basically a tool for
64
64
  # you to use when writing your own named scopes. This way you know for sure
@@ -71,7 +71,7 @@ module Searchlogic
71
71
  def inner_joins(association_name)
72
72
  ::ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, association_name, nil).join_associations.collect { |assoc| assoc.association_join }
73
73
  end
74
-
74
+
75
75
  # A convenience methods to create a join on a polymorphic associations target.
76
76
  # Ex:
77
77
  #
@@ -91,7 +91,7 @@ module Searchlogic
91
91
  "INNER JOIN #{options[:target_table]} ON #{options[:target_table]}.id = #{options[:on_table_name]}.#{options[:as]}_id AND " +
92
92
  "#{options[:on_table_name]}.#{options[:as]}_type = #{postgres ? "E" : ""}'#{target.to_s.camelize}'"
93
93
  end
94
-
94
+
95
95
  # See inner_joins. Does the same thing except creates LEFT OUTER joins.
96
96
  def left_outer_joins(association_name)
97
97
  ::ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, association_name, nil).join_associations.collect { |assoc| assoc.association_join }
@@ -0,0 +1,30 @@
1
+ module Searchlogic
2
+ module ActiveRecord
3
+ # The internals to ActiveRecord like to do scopes.include?(scope_name). And this is how they check for the existence
4
+ # of scopes, which is terrible. The problem is that searchlogic scopes are dynamically created. So the only solution
5
+ # is to override the include? method for the scopes hash, try to create the named scope, and then check it again.
6
+ # This shouldn't effect performance because once its created it never gets called again. I also cache failed names
7
+ # so we don't try to create them again.
8
+ module Scope
9
+ def scopes
10
+ read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {}.tap do |h|
11
+
12
+ class << h
13
+ attr_accessor :active_record_class
14
+ end
15
+ h.active_record_class = self
16
+
17
+ h.instance_eval <<-eval
18
+ def include?(key)
19
+ result = super
20
+ return result if result
21
+ active_record_class.respond_to?(key)
22
+ super
23
+ end
24
+ eval
25
+
26
+ end)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -4,7 +4,7 @@ module Searchlogic
4
4
  def self.included(klass)
5
5
  klass.class_eval do
6
6
  attr_accessor :searchlogic_options
7
-
7
+
8
8
  def searchlogic_options
9
9
  @searchlogic_options ||= {}
10
10
  @searchlogic_options[:type] ||= :string
@@ -8,7 +8,7 @@ module Searchlogic
8
8
  # or represents a named scope procedure. Ex:
9
9
  #
10
10
  # class User
11
- # def teenager
11
+ # def self.teenager
12
12
  # age_gte(13).age_lte(19)
13
13
  # end
14
14
  # end
@@ -33,11 +33,11 @@ module Searchlogic
33
33
  # is a safe method.
34
34
  def alias_scope(name, options = nil)
35
35
  alias_scopes[name.to_sym] = options
36
- (class << self; self end).instance_eval do
36
+ (class << self; self; end).instance_eval do
37
37
  define_method name do |*args|
38
38
  case options
39
39
  when Symbol
40
- send(options)
40
+ send(options, *args)
41
41
  else
42
42
  options.call(*args)
43
43
  end
@@ -45,23 +45,24 @@ module Searchlogic
45
45
  end
46
46
  end
47
47
  alias_method :scope_procedure, :alias_scope
48
-
49
- def alias_scopes # :nodoc:
50
- read_inheritable_attribute(:alias_scopes) || write_inheritable_attribute(:alias_scopes, {})
51
- end
52
-
53
- def alias_scope?(name) # :nodoc:
54
- return false if name.blank?
55
- alias_scopes.key?(name.to_sym)
56
- end
57
-
48
+
58
49
  def condition?(name) # :nodoc:
59
50
  super || alias_scope?(name)
60
51
  end
61
-
52
+
62
53
  def named_scope_options(name) # :nodoc:
63
54
  super || alias_scopes[name.to_sym]
64
55
  end
56
+
57
+ private
58
+ def alias_scopes # :nodoc:
59
+ read_inheritable_attribute(:alias_scopes) || write_inheritable_attribute(:alias_scopes, {})
60
+ end
61
+
62
+ def alias_scope?(name) # :nodoc:
63
+ return false if name.blank?
64
+ alias_scopes.key?(name.to_sym)
65
+ end
65
66
  end
66
67
  end
67
68
  end
@@ -11,12 +11,13 @@ module Searchlogic
11
11
  !association_condition_details(name).nil? unless name.to_s.downcase.match("_or_")
12
12
  end
13
13
 
14
- def method_missing(name, *args, &block)
15
- if !local_condition?(name) && details = association_condition_details(name)
16
- create_association_condition(details[:association], details[:condition], args, details[:poly_class])
17
- send(name, *args)
18
- else
19
- super
14
+ # We need to try and create other conditions first so that we give priority to conflicting names.
15
+ # Such as having a column name with the exact same name as an association condition.
16
+ def create_condition(name)
17
+ if result = super
18
+ result
19
+ elsif details = association_condition_details(name)
20
+ create_association_condition(details[:association], details[:condition], details[:poly_class])
20
21
  end
21
22
  end
22
23
 
@@ -31,7 +32,7 @@ module Searchlogic
31
32
  poly_type = nil
32
33
  condition = nil
33
34
 
34
- if name_with_condition.to_s =~ /^(#{non_poly_assocs.collect(&:name).join("|")})_(\w+)$/
35
+ if name_with_condition.to_s =~ /^(#{non_poly_assocs.collect(&:name).join("|")})_(\w+)$/ && non_poly_assocs.present?
35
36
  association_name = $1
36
37
  condition = $2
37
38
  elsif name_with_condition.to_s =~ /^(#{poly_assocs.collect(&:name).join("|")})_(\w+?)_type_(\w+)$/
@@ -51,27 +52,27 @@ module Searchlogic
51
52
  end
52
53
  end
53
54
 
54
- def create_association_condition(association, condition_name, args, poly_class = nil)
55
+ def create_association_condition(association, condition_name, poly_class = nil)
55
56
  name = [association.name, poly_class && "#{poly_class.name.underscore}_type", condition_name].compact.join("_")
56
- named_scope(name, association_condition_options(association, condition_name, args, poly_class))
57
+ named_scope(name, association_condition_options(association, condition_name, poly_class))
57
58
  end
58
59
 
59
- def association_condition_options(association, association_condition, args, poly_class = nil)
60
+ def association_condition_options(association, association_condition, poly_class = nil)
60
61
  klass = poly_class ? poly_class : association.klass
61
- scope = klass.send(association_condition, *args)
62
- scope_options = klass.named_scope_options(association_condition)
62
+ raise ArgumentError.new("The #{klass} class does not respond to the #{association_condition} scope") if !klass.respond_to?(association_condition)
63
63
  arity = klass.named_scope_arity(association_condition)
64
64
 
65
- if !arity || arity == 0
65
+ if !arity
66
66
  # The underlying condition doesn't require any parameters, so let's just create a simple
67
67
  # named scope that is based on a hash.
68
68
  options = {}
69
- in_searchlogic_delegation { options = scope.scope(:find) }
69
+ in_searchlogic_delegation { options = klass.send(association_condition).scope(:find) }
70
70
  prepare_named_scope_options(options, association, poly_class)
71
71
  options
72
72
  else
73
- proc_args = arity_args(arity)
73
+ scope_options = klass.named_scope_options(association_condition)
74
74
  scope_options = scope_options.respond_to?(:searchlogic_options) ? scope_options.searchlogic_options.clone : {}
75
+ proc_args = arity_args(arity)
75
76
  arg_type = scope_options.delete(:type) || :string
76
77
 
77
78
  eval <<-"end_eval"
@@ -83,7 +84,6 @@ module Searchlogic
83
84
  options = scope.scope(:find) if scope
84
85
  end
85
86
 
86
-
87
87
  prepare_named_scope_options(options, association, poly_class)
88
88
  options
89
89
  }
@@ -13,21 +13,20 @@ module Searchlogic
13
13
  def condition?(name) # :nodoc:
14
14
  super || association_ordering_condition?(name)
15
15
  end
16
-
16
+
17
17
  private
18
18
  def association_ordering_condition?(name)
19
19
  !association_ordering_condition_details(name).nil?
20
20
  end
21
-
22
- def method_missing(name, *args, &block)
21
+
22
+ def create_condition(name)
23
23
  if details = association_ordering_condition_details(name)
24
- create_association_ordering_condition(details[:association], details[:order_as], details[:condition], args)
25
- send(name, *args)
24
+ create_association_ordering_condition(details[:association], details[:order_as], details[:condition])
26
25
  else
27
26
  super
28
27
  end
29
28
  end
30
-
29
+
31
30
  def association_ordering_condition_details(name)
32
31
  associations = reflect_on_all_associations
33
32
  association_names = associations.collect { |assoc| assoc.name }
@@ -35,8 +34,8 @@ module Searchlogic
35
34
  {:order_as => $1, :association => associations.find { |a| a.name == $2.to_sym }, :condition => $3}
36
35
  end
37
36
  end
38
-
39
- def create_association_ordering_condition(association, order_as, condition, args)
37
+
38
+ def create_association_ordering_condition(association, order_as, condition)
40
39
  cond = condition
41
40
  poly_class = nil
42
41
  if condition =~ /^(\w+)_type_(\w+)$/
@@ -44,7 +43,7 @@ module Searchlogic
44
43
  cond = $2
45
44
  poly_class = poly_type.camelcase.constantize if poly_type
46
45
  end
47
- named_scope("#{order_as}_by_#{association.name}_#{condition}", association_condition_options(association, "#{order_as}_by_#{cond}", args, poly_class))
46
+ named_scope("#{order_as}_by_#{association.name}_#{condition}", association_condition_options(association, "#{order_as}_by_#{cond}", poly_class))
48
47
  end
49
48
  end
50
49
  end
@@ -0,0 +1,16 @@
1
+ module Searchlogic
2
+ module NamedScopes
3
+ module Base
4
+ def condition?(name)
5
+ existing_condition?(name)
6
+ end
7
+
8
+ private
9
+ def existing_condition?(name)
10
+ return false if name.blank?
11
+ @valid_scope_names ||= scopes.keys.reject { |k| k == :scoped }
12
+ @valid_scope_names.include?(name.to_sym)
13
+ end
14
+ end
15
+ end
16
+ end