searchlogic 2.3.9 → 2.3.10
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.
- data/VERSION.yml +2 -2
- data/lib/searchlogic/named_scopes/conditions.rb +5 -7
- data/lib/searchlogic/named_scopes/or_conditions.rb +10 -2
- data/lib/searchlogic/rails_helpers.rb +1 -1
- data/lib/searchlogic/search.rb +6 -6
- data/searchlogic.gemspec +2 -2
- data/spec/named_scopes/or_conditions_spec.rb +7 -0
- data/spec/search_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -89,13 +89,11 @@ module Searchlogic
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
def condition_details(
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
{:column => $1, :condition => $2}
|
98
|
-
elsif name.to_s =~ /^(#{column_names.join("|")})_(#{(PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")})$/
|
92
|
+
def condition_details(method_name)
|
93
|
+
column_name_matcher = column_names.join("|")
|
94
|
+
conditions_matcher = (PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")
|
95
|
+
|
96
|
+
if method_name.to_s =~ /^(#{column_name_matcher})_(#{conditions_matcher})$/
|
99
97
|
{:column => $1, :condition => $2}
|
100
98
|
end
|
101
99
|
end
|
@@ -10,6 +10,10 @@ module Searchlogic
|
|
10
10
|
super || or_condition?(name)
|
11
11
|
end
|
12
12
|
|
13
|
+
def named_scope_options(name) # :nodoc:
|
14
|
+
super || super(or_conditions(name).join("_or_"))
|
15
|
+
end
|
16
|
+
|
13
17
|
private
|
14
18
|
def or_condition?(name)
|
15
19
|
!or_conditions(name).nil?
|
@@ -106,7 +110,7 @@ module Searchlogic
|
|
106
110
|
path << details[:association]
|
107
111
|
part = details[:condition]
|
108
112
|
given_assoc = details[:association]
|
109
|
-
elsif details = klass.send(:condition_details, part
|
113
|
+
elsif details = klass.send(:condition_details, part)
|
110
114
|
return { :path => path, :column => details[:column], :condition => details[:condition] }
|
111
115
|
end
|
112
116
|
end
|
@@ -114,7 +118,11 @@ module Searchlogic
|
|
114
118
|
end
|
115
119
|
|
116
120
|
def create_or_condition(scopes, args)
|
117
|
-
|
121
|
+
scopes_options = scopes.collect { |scope, *args| send(scope, *args).proxy_options }
|
122
|
+
# We're using first scope to determine column's type
|
123
|
+
scope = named_scope_options(scopes.first)
|
124
|
+
column_type = scope.respond_to?(:searchlogic_arg_type) ? scope.searchlogic_arg_type : :string
|
125
|
+
named_scope scopes.join("_or_"), searchlogic_lambda(column_type) { |*args|
|
118
126
|
merge_scopes_with_or(scopes.collect { |scope| [scope, *args] })
|
119
127
|
}
|
120
128
|
end
|
@@ -66,7 +66,7 @@ module Searchlogic
|
|
66
66
|
def fields_for(*args, &block)
|
67
67
|
if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
|
68
68
|
args.unshift(:search) if args.first == search_obj
|
69
|
-
concat(content_tag("div", hidden_field_tag("#{args.first}[order]", search_obj.order))
|
69
|
+
concat(content_tag("div", hidden_field_tag("#{args.first}[order]", search_obj.order)))
|
70
70
|
super
|
71
71
|
else
|
72
72
|
super
|
data/lib/searchlogic/search.rb
CHANGED
@@ -84,7 +84,11 @@ module Searchlogic
|
|
84
84
|
|
85
85
|
if setter?(name)
|
86
86
|
if scope?(scope_name)
|
87
|
-
|
87
|
+
if args.size == 1
|
88
|
+
conditions[condition_name] = type_cast(args.first, cast_type(scope_name))
|
89
|
+
else
|
90
|
+
conditions[condition_name] = args
|
91
|
+
end
|
88
92
|
else
|
89
93
|
raise UnknownConditionError.new(condition_name)
|
90
94
|
end
|
@@ -109,11 +113,7 @@ module Searchlogic
|
|
109
113
|
scope
|
110
114
|
end
|
111
115
|
else
|
112
|
-
|
113
|
-
scope.send(scope_name, *value)
|
114
|
-
else
|
115
|
-
scope.send(scope_name, value)
|
116
|
-
end
|
116
|
+
scope.send(scope_name, *value)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
scope.send(name, *args, &block)
|
data/searchlogic.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{searchlogic}
|
8
|
-
s.version = "2.3.
|
8
|
+
s.version = "2.3.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Johnson of Binary Logic"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-14}
|
13
13
|
s.description = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
|
14
14
|
s.email = %q{bjohnson@binarylogic.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -56,4 +56,11 @@ describe "Or conditions" do
|
|
56
56
|
User.find_or_create_by_name_and_username("Fred", "fredb").should be_a_kind_of User
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should work with User.search(conditions) method" do
|
60
|
+
User.search(:username_or_name_like => 'ben').proxy_options.should == {:conditions => "(users.username LIKE '%ben%') OR (users.name LIKE '%ben%')"}
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should convert types properly when used with User.search(conditions) method" do
|
64
|
+
User.search(:id_or_age_lte => '10').proxy_options.should == {:conditions => "(users.id <= 10) OR (users.age <= 10)"}
|
65
|
+
end
|
59
66
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -365,5 +365,13 @@ describe "Search" do
|
|
365
365
|
search1.empty?.should == false
|
366
366
|
search2.empty?.should == true
|
367
367
|
end
|
368
|
+
|
369
|
+
it "should delegate to named scopes with arity > 1" do
|
370
|
+
User.named_scope :paged, lambda {|start, limit| { :limit => limit, :offset => start }}
|
371
|
+
User.create(:username => "bjohnson")
|
372
|
+
search = User.search(:username => "bjohnson")
|
373
|
+
search.paged(0, 1).count.should == 1
|
374
|
+
search.paged(0, 0).count.should == 0
|
375
|
+
end
|
368
376
|
end
|
369
377
|
end
|
data/spec/spec_helper.rb
CHANGED
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.3.
|
4
|
+
version: 2.3.10
|
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:
|
12
|
+
date: 2010-01-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|