searchlogic 2.4.19 → 2.4.21
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/searchlogic/named_scopes/alias_scope.rb +1 -1
- data/lib/searchlogic/named_scopes/conditions.rb +30 -27
- data/lib/searchlogic/named_scopes/or_conditions.rb +1 -1
- data/lib/searchlogic/rails_helpers.rb +5 -2
- data/lib/searchlogic/search.rb +4 -0
- data/searchlogic.gemspec +4 -4
- data/spec/searchlogic/named_scopes/alias_scope_spec.rb +5 -1
- data/spec/searchlogic/named_scopes/conditions_spec.rb +1 -1
- data/spec/searchlogic/search_spec.rb +8 -0
- data/spec/spec_helper.rb +11 -11
- metadata +11 -4
data/VERSION.yml
CHANGED
@@ -47,7 +47,7 @@ module Searchlogic
|
|
47
47
|
alias_method :scope_procedure, :alias_scope
|
48
48
|
|
49
49
|
def alias_scopes # :nodoc:
|
50
|
-
|
50
|
+
read_inheritable_attribute(:alias_scopes) || write_inheritable_attribute(:alias_scopes, {})
|
51
51
|
end
|
52
52
|
|
53
53
|
def alias_scope?(name) # :nodoc:
|
@@ -17,7 +17,7 @@ module Searchlogic
|
|
17
17
|
:greater_than => [:gt, :after],
|
18
18
|
:greater_than_or_equal_to => [:gte],
|
19
19
|
}
|
20
|
-
|
20
|
+
|
21
21
|
WILDCARD_CONDITIONS = {
|
22
22
|
:like => [:contains, :includes],
|
23
23
|
:not_like => [:does_not_include],
|
@@ -26,7 +26,7 @@ module Searchlogic
|
|
26
26
|
:ends_with => [:ew],
|
27
27
|
:not_end_with => [:does_not_end_with]
|
28
28
|
}
|
29
|
-
|
29
|
+
|
30
30
|
BOOLEAN_CONDITIONS = {
|
31
31
|
:null => [:nil],
|
32
32
|
:not_null => [:not_nil],
|
@@ -34,41 +34,41 @@ module Searchlogic
|
|
34
34
|
:blank => [],
|
35
35
|
:not_blank => [:present]
|
36
36
|
}
|
37
|
-
|
37
|
+
|
38
38
|
CONDITIONS = {}
|
39
|
-
|
39
|
+
|
40
40
|
# Add any / all variations to every comparison and wildcard condition
|
41
41
|
COMPARISON_CONDITIONS.merge(WILDCARD_CONDITIONS).each do |condition, aliases|
|
42
42
|
CONDITIONS[condition] = aliases
|
43
43
|
CONDITIONS["#{condition}_any".to_sym] = aliases.collect { |a| "#{a}_any".to_sym }
|
44
44
|
CONDITIONS["#{condition}_all".to_sym] = aliases.collect { |a| "#{a}_all".to_sym }
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
CONDITIONS[:equals_any] = CONDITIONS[:equals_any] + [:in]
|
48
48
|
CONDITIONS[:does_not_equal_all] = CONDITIONS[:does_not_equal_all] + [:not_in]
|
49
|
-
|
49
|
+
|
50
50
|
BOOLEAN_CONDITIONS.each { |condition, aliases| CONDITIONS[condition] = aliases }
|
51
|
-
|
51
|
+
|
52
52
|
PRIMARY_CONDITIONS = CONDITIONS.keys
|
53
53
|
ALIAS_CONDITIONS = CONDITIONS.values.flatten
|
54
|
-
|
54
|
+
|
55
55
|
# Is the name of the method a valid condition that can be dynamically created?
|
56
56
|
def condition?(name)
|
57
57
|
local_condition?(name)
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
private
|
61
61
|
def local_condition?(name)
|
62
62
|
return false if name.blank?
|
63
63
|
scope_names = scopes.keys.reject { |k| k == :scoped }
|
64
64
|
scope_names.include?(name.to_sym) || !condition_details(name).nil? || boolean_condition?(name)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def boolean_condition?(name)
|
68
68
|
column = columns_hash[name.to_s] || columns_hash[name.to_s.gsub(/^not_/, "")]
|
69
69
|
column && column.type == :boolean
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def method_missing(name, *args, &block)
|
73
73
|
if details = condition_details(name)
|
74
74
|
create_condition(details[:column], details[:condition], args)
|
@@ -81,8 +81,8 @@ module Searchlogic
|
|
81
81
|
super
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
85
|
-
|
84
|
+
|
85
|
+
|
86
86
|
def condition_details(method_name)
|
87
87
|
column_name_matcher = column_names.join("|")
|
88
88
|
conditions_matcher = (PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")
|
@@ -91,7 +91,7 @@ module Searchlogic
|
|
91
91
|
{:column => $1, :condition => $2}
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def create_condition(column, condition, args)
|
96
96
|
if PRIMARY_CONDITIONS.include?(condition.to_sym)
|
97
97
|
create_primary_condition(column, condition)
|
@@ -99,12 +99,12 @@ module Searchlogic
|
|
99
99
|
create_alias_condition(column, condition, args)
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def create_primary_condition(column, condition)
|
104
104
|
column_type = columns_hash[column.to_s].type
|
105
105
|
skip_conversion = skip_time_zone_conversion_for_attributes.include?(columns_hash[column.to_s].name.to_sym)
|
106
106
|
match_keyword = ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
107
|
-
|
107
|
+
|
108
108
|
scope_options = case condition.to_s
|
109
109
|
when /^equals/
|
110
110
|
scope_options(condition, column_type, lambda { |a| attribute_condition("#{table_name}.#{column}", a) }, :skip_conversion => skip_conversion)
|
@@ -141,10 +141,10 @@ module Searchlogic
|
|
141
141
|
when "not_blank"
|
142
142
|
{:conditions => "#{table_name}.#{column} != '' AND #{table_name}.#{column} IS NOT NULL"}
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
named_scope("#{column}_#{condition}".to_sym, scope_options)
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
# This method helps cut down on defining scope options for conditions that allow *_any or *_all conditions.
|
149
149
|
# Kepp in mind that the lambdas get cached in a method, so you want to keep the contents of the lambdas as
|
150
150
|
# fast as possible, which is why I didn't do the case statement inside of the lambda.
|
@@ -152,15 +152,18 @@ module Searchlogic
|
|
152
152
|
case condition.to_s
|
153
153
|
when /_(any|all)$/
|
154
154
|
searchlogic_lambda(column_type, :skip_conversion => options[:skip_conversion]) { |*values|
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
unless values.empty?
|
156
|
+
values.flatten!
|
157
|
+
values.collect! { |value| value_with_modifier(value, options[:value_modifier]) }
|
158
158
|
|
159
|
-
|
159
|
+
join = $1 == "any" ? " OR " : " AND "
|
160
160
|
|
161
|
-
|
161
|
+
scope_sql = values.collect { |value| sql.is_a?(Proc) ? sql.call(value) : sql }.join(join)
|
162
162
|
|
163
|
-
|
163
|
+
{:conditions => [scope_sql, *expand_range_bind_variables(values)]}
|
164
|
+
else
|
165
|
+
{}
|
166
|
+
end
|
164
167
|
}
|
165
168
|
else
|
166
169
|
searchlogic_lambda(column_type, :skip_conversion => options[:skip_conversion]) { |*values|
|
@@ -172,7 +175,7 @@ module Searchlogic
|
|
172
175
|
}
|
173
176
|
end
|
174
177
|
end
|
175
|
-
|
178
|
+
|
176
179
|
def value_with_modifier(value, modifier)
|
177
180
|
case modifier
|
178
181
|
when :like
|
@@ -185,7 +188,7 @@ module Searchlogic
|
|
185
188
|
value
|
186
189
|
end
|
187
190
|
end
|
188
|
-
|
191
|
+
|
189
192
|
def create_alias_condition(column, condition, args)
|
190
193
|
primary_condition = primary_condition(condition)
|
191
194
|
alias_name = "#{column}_#{condition}"
|
@@ -193,7 +196,7 @@ module Searchlogic
|
|
193
196
|
send(primary_name, *args) # go back to method_missing and make sure we create the method
|
194
197
|
(class << self; self; end).class_eval { alias_method alias_name, primary_name }
|
195
198
|
end
|
196
|
-
|
199
|
+
|
197
200
|
# Returns the primary condition for the given alias. Ex:
|
198
201
|
#
|
199
202
|
# primary_condition(:gt) => :greater_than
|
@@ -44,6 +44,9 @@ module Searchlogic
|
|
44
44
|
url_options = {
|
45
45
|
options[:params_scope] => search.conditions.merge( { :order => new_scope } )
|
46
46
|
}.deep_merge(options[:params] || {})
|
47
|
+
|
48
|
+
options[:as] = raw(options[:as]) if defined?(RailsXss)
|
49
|
+
|
47
50
|
link_to options[:as], url_for(url_options), html_options
|
48
51
|
end
|
49
52
|
|
@@ -60,8 +63,8 @@ module Searchlogic
|
|
60
63
|
end
|
61
64
|
super
|
62
65
|
end
|
63
|
-
|
64
|
-
# Automatically adds an "order" hidden field in your form to preserve how the data
|
66
|
+
|
67
|
+
# Automatically adds an "order" hidden field in your form to preserve how the data
|
65
68
|
# is being ordered.
|
66
69
|
def fields_for(*args, &block)
|
67
70
|
if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
|
data/lib/searchlogic/search.rb
CHANGED
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.4.
|
8
|
+
s.version = "2.4.21"
|
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{2010-
|
12
|
+
s.date = %q{2010-07-25}
|
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,7 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
s.rdoc_options = ["--charset=UTF-8"]
|
57
57
|
s.require_paths = ["lib"]
|
58
58
|
s.rubyforge_project = %q{searchlogic}
|
59
|
-
s.rubygems_version = %q{1.3.
|
59
|
+
s.rubygems_version = %q{1.3.7}
|
60
60
|
s.summary = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
|
61
61
|
s.test_files = [
|
62
62
|
"spec/searchlogic/active_record/association_proxy_spec.rb",
|
@@ -77,7 +77,7 @@ Gem::Specification.new do |s|
|
|
77
77
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
78
78
|
s.specification_version = 3
|
79
79
|
|
80
|
-
if Gem::Version.new(Gem::
|
80
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
81
81
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
82
82
|
else
|
83
83
|
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
@@ -16,4 +16,8 @@ describe Searchlogic::NamedScopes::AliasScope do
|
|
16
16
|
search.username_has = "bjohnson"
|
17
17
|
search.username_has.should == "bjohnson"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
|
+
it "should inherit alias scopes from superclasses" do
|
21
|
+
Class.new(User).alias_scope?("username_has").should be_true
|
22
|
+
end
|
23
|
+
end
|
@@ -115,7 +115,7 @@ describe Searchlogic::NamedScopes::Conditions do
|
|
115
115
|
it "should do nothing if no arguments are passed" do
|
116
116
|
User.username_equals_any.proxy_options.should == {}
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
it "should treat an array and multiple arguments the same" do
|
120
120
|
%w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
|
121
121
|
User.username_like_any("bjohnson", "thunt").should == User.username_like_any(["bjohnson", "thunt"])
|
@@ -102,6 +102,14 @@ describe Searchlogic::Search do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
context "#compact_conditions" do
|
106
|
+
it "should remove conditions with blank values" do
|
107
|
+
search = User.search
|
108
|
+
search.conditions = {"id_equals" => "", "name_equals" => "Ben"}
|
109
|
+
search.compact_conditions.should == {:name_equals => "Ben"}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
105
113
|
context "condition accessors" do
|
106
114
|
it "should allow setting exact columns individually" do
|
107
115
|
search = User.search
|
data/spec/spec_helper.rb
CHANGED
@@ -82,20 +82,20 @@ require 'searchlogic'
|
|
82
82
|
|
83
83
|
Spec::Runner.configure do |config|
|
84
84
|
config.before(:each) do
|
85
|
-
class Audit < ActiveRecord::Base
|
85
|
+
class ::Audit < ActiveRecord::Base
|
86
86
|
belongs_to :auditable, :polymorphic => true
|
87
87
|
end
|
88
88
|
|
89
|
-
class Company < ActiveRecord::Base
|
89
|
+
class ::Company < ActiveRecord::Base
|
90
90
|
has_many :orders, :through => :users
|
91
91
|
has_many :users, :dependent => :destroy
|
92
92
|
end
|
93
93
|
|
94
|
-
class UserGroup < ActiveRecord::Base
|
94
|
+
class ::UserGroup < ActiveRecord::Base
|
95
95
|
has_and_belongs_to_many :users
|
96
96
|
end
|
97
97
|
|
98
|
-
class User < ActiveRecord::Base
|
98
|
+
class ::User < ActiveRecord::Base
|
99
99
|
belongs_to :company, :counter_cache => true
|
100
100
|
has_many :orders, :dependent => :destroy
|
101
101
|
has_many :orders_big, :class_name => 'Order', :conditions => 'total > 100'
|
@@ -104,23 +104,23 @@ Spec::Runner.configure do |config|
|
|
104
104
|
self.skip_time_zone_conversion_for_attributes = [:whatever_at]
|
105
105
|
end
|
106
106
|
|
107
|
-
class Order < ActiveRecord::Base
|
107
|
+
class ::Order < ActiveRecord::Base
|
108
108
|
belongs_to :user
|
109
109
|
has_many :line_items, :dependent => :destroy
|
110
110
|
end
|
111
111
|
|
112
|
-
class Fee < ActiveRecord::Base
|
112
|
+
class ::Fee < ActiveRecord::Base
|
113
113
|
belongs_to :owner, :polymorphic => true
|
114
114
|
end
|
115
115
|
|
116
|
-
class LineItem < ActiveRecord::Base
|
116
|
+
class ::LineItem < ActiveRecord::Base
|
117
117
|
belongs_to :order
|
118
118
|
end
|
119
119
|
|
120
|
-
Company.destroy_all
|
121
|
-
User.destroy_all
|
122
|
-
Order.destroy_all
|
123
|
-
LineItem.destroy_all
|
120
|
+
::Company.destroy_all
|
121
|
+
::User.destroy_all
|
122
|
+
::Order.destroy_all
|
123
|
+
::LineItem.destroy_all
|
124
124
|
end
|
125
125
|
|
126
126
|
config.after(:each) do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 53
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 2
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
version: 2.4.
|
9
|
+
- 21
|
10
|
+
version: 2.4.21
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Ben Johnson of Binary Logic
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-25 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activerecord
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
27
30
|
segments:
|
28
31
|
- 2
|
29
32
|
- 0
|
@@ -85,23 +88,27 @@ rdoc_options:
|
|
85
88
|
require_paths:
|
86
89
|
- lib
|
87
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
88
92
|
requirements:
|
89
93
|
- - ">="
|
90
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
91
96
|
segments:
|
92
97
|
- 0
|
93
98
|
version: "0"
|
94
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
95
101
|
requirements:
|
96
102
|
- - ">="
|
97
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
98
105
|
segments:
|
99
106
|
- 0
|
100
107
|
version: "0"
|
101
108
|
requirements: []
|
102
109
|
|
103
110
|
rubyforge_project: searchlogic
|
104
|
-
rubygems_version: 1.3.
|
111
|
+
rubygems_version: 1.3.7
|
105
112
|
signing_key:
|
106
113
|
specification_version: 3
|
107
114
|
summary: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
|