kazjote-searchlogic 2.3.5 → 2.3.6
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 +1 -1
- data/kazjote-searchlogic.gemspec +84 -0
- data/lib/searchlogic/named_scopes/conditions.rb +25 -24
- data/spec/named_scopes/or_conditions_spec.rb +16 -16
- metadata +3 -2
data/VERSION.yml
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{kazjote-searchlogic}
|
8
|
+
s.version = "2.3.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ben Johnson of Binary Logic"]
|
12
|
+
s.date = %q{2009-10-09}
|
13
|
+
s.description = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
|
14
|
+
s.email = %q{bjohnson@binarylogic.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"CHANGELOG.rdoc",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"init.rb",
|
27
|
+
"kazjote-searchlogic.gemspec",
|
28
|
+
"lib/searchlogic.rb",
|
29
|
+
"lib/searchlogic/active_record/consistency.rb",
|
30
|
+
"lib/searchlogic/active_record/named_scopes.rb",
|
31
|
+
"lib/searchlogic/core_ext/object.rb",
|
32
|
+
"lib/searchlogic/core_ext/proc.rb",
|
33
|
+
"lib/searchlogic/named_scopes/alias_scope.rb",
|
34
|
+
"lib/searchlogic/named_scopes/association_conditions.rb",
|
35
|
+
"lib/searchlogic/named_scopes/association_ordering.rb",
|
36
|
+
"lib/searchlogic/named_scopes/conditions.rb",
|
37
|
+
"lib/searchlogic/named_scopes/or_conditions.rb",
|
38
|
+
"lib/searchlogic/named_scopes/ordering.rb",
|
39
|
+
"lib/searchlogic/rails_helpers.rb",
|
40
|
+
"lib/searchlogic/search.rb",
|
41
|
+
"rails/init.rb",
|
42
|
+
"spec/core_ext/object_spec.rb",
|
43
|
+
"spec/core_ext/proc_spec.rb",
|
44
|
+
"spec/named_scopes/alias_scope_spec.rb",
|
45
|
+
"spec/named_scopes/association_conditions_spec.rb",
|
46
|
+
"spec/named_scopes/association_ordering_spec.rb",
|
47
|
+
"spec/named_scopes/conditions_spec.rb",
|
48
|
+
"spec/named_scopes/or_conditions_spec.rb",
|
49
|
+
"spec/named_scopes/ordering_spec.rb",
|
50
|
+
"spec/search_spec.rb",
|
51
|
+
"spec/spec_helper.rb"
|
52
|
+
]
|
53
|
+
s.homepage = %q{http://github.com/binarylogic/searchlogic}
|
54
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
55
|
+
s.require_paths = ["lib"]
|
56
|
+
s.rubyforge_project = %q{searchlogic}
|
57
|
+
s.rubygems_version = %q{1.3.5}
|
58
|
+
s.summary = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
|
59
|
+
s.test_files = [
|
60
|
+
"spec/core_ext/object_spec.rb",
|
61
|
+
"spec/core_ext/proc_spec.rb",
|
62
|
+
"spec/named_scopes/alias_scope_spec.rb",
|
63
|
+
"spec/named_scopes/association_conditions_spec.rb",
|
64
|
+
"spec/named_scopes/association_ordering_spec.rb",
|
65
|
+
"spec/named_scopes/conditions_spec.rb",
|
66
|
+
"spec/named_scopes/or_conditions_spec.rb",
|
67
|
+
"spec/named_scopes/ordering_spec.rb",
|
68
|
+
"spec/search_spec.rb",
|
69
|
+
"spec/spec_helper.rb"
|
70
|
+
]
|
71
|
+
|
72
|
+
if s.respond_to? :specification_version then
|
73
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
74
|
+
s.specification_version = 3
|
75
|
+
|
76
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
77
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
78
|
+
else
|
79
|
+
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
80
|
+
end
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
83
|
+
end
|
84
|
+
end
|
@@ -60,7 +60,7 @@ module Searchlogic
|
|
60
60
|
scope_names = scopes.keys.reject { |k| k == :scoped }
|
61
61
|
scope_names.include?(name.to_sym) || !condition_details(name).nil?
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def method_missing(name, *args, &block)
|
65
65
|
if details = condition_details(name)
|
66
66
|
create_condition(details[:column], details[:condition], args)
|
@@ -83,46 +83,47 @@ module Searchlogic
|
|
83
83
|
create_alias_condition(column, condition, args)
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def create_primary_condition(column, condition)
|
88
88
|
column_type = columns_hash[column.to_s].type
|
89
89
|
match_keyword = ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
90
|
-
|
90
|
+
quoted_column = ::ActiveRecord::Base.connection.quote_column_name(column.to_s)
|
91
|
+
|
91
92
|
scope_options = case condition.to_s
|
92
93
|
when /^equals/
|
93
|
-
scope_options(condition, column_type, lambda { |a| attribute_condition("#{
|
94
|
+
scope_options(condition, column_type, lambda { |a| attribute_condition("#{quoted_table_name}.#{quoted_column}", a) })
|
94
95
|
when /^does_not_equal/
|
95
|
-
scope_options(condition, column_type, "#{
|
96
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} != ?")
|
96
97
|
when /^less_than_or_equal_to/
|
97
|
-
scope_options(condition, column_type, "#{
|
98
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} <= ?")
|
98
99
|
when /^less_than/
|
99
|
-
scope_options(condition, column_type, "#{
|
100
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} < ?")
|
100
101
|
when /^greater_than_or_equal_to/
|
101
|
-
scope_options(condition, column_type, "#{
|
102
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} >= ?")
|
102
103
|
when /^greater_than/
|
103
|
-
scope_options(condition, column_type, "#{
|
104
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} > ?")
|
104
105
|
when /^like/
|
105
|
-
scope_options(condition, column_type, "#{
|
106
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} #{match_keyword} ?", :like)
|
106
107
|
when /^not_like/
|
107
|
-
scope_options(condition, column_type, "#{
|
108
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} NOT #{match_keyword} ?", :like)
|
108
109
|
when /^begins_with/
|
109
|
-
scope_options(condition, column_type, "#{
|
110
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} #{match_keyword} ?", :begins_with)
|
110
111
|
when /^not_begin_with/
|
111
|
-
scope_options(condition, column_type, "#{
|
112
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} NOT #{match_keyword} ?", :begins_with)
|
112
113
|
when /^ends_with/
|
113
|
-
scope_options(condition, column_type, "#{
|
114
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} #{match_keyword} ?", :ends_with)
|
114
115
|
when /^not_end_with/
|
115
|
-
scope_options(condition, column_type, "#{
|
116
|
+
scope_options(condition, column_type, "#{quoted_table_name}.#{quoted_column} NOT #{match_keyword} ?", :ends_with)
|
116
117
|
when "null"
|
117
|
-
{:conditions => "#{
|
118
|
+
{:conditions => "#{quoted_table_name}.#{quoted_column} IS NULL"}
|
118
119
|
when "not_null"
|
119
|
-
{:conditions => "#{
|
120
|
+
{:conditions => "#{quoted_table_name}.#{quoted_column} IS NOT NULL"}
|
120
121
|
when "empty"
|
121
|
-
{:conditions => "#{
|
122
|
+
{:conditions => "#{quoted_table_name}.#{quoted_column} = ''"}
|
122
123
|
when "blank"
|
123
|
-
{:conditions => "#{
|
124
|
+
{:conditions => "#{quoted_table_name}.#{quoted_column} = '' OR #{quoted_table_name}.#{quoted_column} IS NULL"}
|
124
125
|
when "not_blank"
|
125
|
-
{:conditions => "#{
|
126
|
+
{:conditions => "#{quoted_table_name}.#{quoted_column} != '' AND #{quoted_table_name}.#{quoted_column} IS NOT NULL"}
|
126
127
|
end
|
127
128
|
|
128
129
|
named_scope("#{column}_#{condition}".to_sym, scope_options)
|
@@ -141,15 +142,15 @@ module Searchlogic
|
|
141
142
|
|
142
143
|
join = $1 == "any" ? " OR " : " AND "
|
143
144
|
scope_sql = values.collect { |value| sql.is_a?(Proc) ? sql.call(value) : sql }.join(join)
|
144
|
-
|
145
|
+
|
145
146
|
{:conditions => [scope_sql, *expand_range_bind_variables(values)]}
|
146
147
|
}
|
147
148
|
else
|
148
149
|
searchlogic_lambda(column_type) { |*values|
|
149
150
|
values.collect! { |value| value_with_modifier(value, value_modifier) }
|
150
|
-
|
151
|
+
|
151
152
|
scope_sql = sql.is_a?(Proc) ? sql.call(*values) : sql
|
152
|
-
|
153
|
+
|
153
154
|
{:conditions => [scope_sql, *expand_range_bind_variables(values)]}
|
154
155
|
}
|
155
156
|
end
|
@@ -175,7 +176,7 @@ module Searchlogic
|
|
175
176
|
send(primary_name, *args) # go back to method_missing and make sure we create the method
|
176
177
|
(class << self; self; end).class_eval { alias_method alias_name, primary_name }
|
177
178
|
end
|
178
|
-
|
179
|
+
|
179
180
|
# Returns the primary condition for the given alias. Ex:
|
180
181
|
#
|
181
182
|
# primary_condition(:gt) => :greater_than
|
@@ -5,37 +5,37 @@ describe "Or conditions" do
|
|
5
5
|
User.name_or_username_like('Test')
|
6
6
|
User.respond_to?(:name_or_username_like).should be_true
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should match username or name" do
|
10
|
-
User.username_or_name_like("ben").proxy_options.should == {:conditions => "(users
|
10
|
+
User.username_or_name_like("ben").proxy_options.should == {:conditions => "(\"users\".\"username\" LIKE '%ben%') OR (\"users\".\"name\" LIKE '%ben%')"}
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should use the specified condition" do
|
14
|
-
User.username_begins_with_or_name_like("ben").proxy_options.should == {:conditions => "(users
|
14
|
+
User.username_begins_with_or_name_like("ben").proxy_options.should == {:conditions => "(\"users\".\"username\" LIKE 'ben%') OR (\"users\".\"name\" LIKE '%ben%')"}
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should use the last specified condition" do
|
18
|
-
User.username_or_name_like_or_id_or_age_lt(10).proxy_options.should == {:conditions => "(users
|
18
|
+
User.username_or_name_like_or_id_or_age_lt(10).proxy_options.should == {:conditions => "(\"users\".\"username\" LIKE '%10%') OR (\"users\".\"name\" LIKE '%10%') OR (\"users\".\"id\" < 10) OR (\"users\".\"age\" < 10)"}
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should raise an error on unknown conditions" do
|
22
22
|
lambda { User.usernme_begins_with_or_name_like("ben") }.should raise_error(Searchlogic::NamedScopes::OrConditions::UnknownConditionError)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "should work well with _or_equal_to" do
|
26
|
-
User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(users
|
26
|
+
User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(\"users\".\"id\" <= 10) OR (\"users\".\"age\" > 10)"}
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should work well with _or_equal_to_any" do
|
30
|
-
User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(users
|
30
|
+
User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(\"users\".\"id\" <= 10) OR (\"users\".\"age\" > 10)"}
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should work well with _or_equal_to_all" do
|
34
|
-
User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(users
|
34
|
+
User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(\"users\".\"id\" <= 10) OR (\"users\".\"age\" > 10)"}
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should play nice with other scopes" do
|
38
38
|
User.username_begins_with("ben").id_gt(10).age_not_nil.username_or_name_ends_with("ben").scope(:find).should ==
|
39
|
-
{:conditions => "((users
|
39
|
+
{:conditions => "((\"users\".\"username\" LIKE '%ben') OR (\"users\".\"name\" LIKE '%ben')) AND ((\"users\".\"age\" IS NOT NULL) AND ((\"users\".\"id\" > 10) AND (\"users\".\"username\" LIKE 'ben%')))"}
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kazjote-searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.6
|
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-10-
|
12
|
+
date: 2009-10-09 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- VERSION.yml
|
41
41
|
- init.rb
|
42
|
+
- kazjote-searchlogic.gemspec
|
42
43
|
- lib/searchlogic.rb
|
43
44
|
- lib/searchlogic/active_record/consistency.rb
|
44
45
|
- lib/searchlogic/active_record/named_scopes.rb
|