binarylogic-searchlogic 2.1.8 → 2.1.9
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/CHANGELOG.rdoc +6 -1
- data/VERSION.yml +1 -1
- data/lib/searchlogic/named_scopes/association_conditions.rb +14 -4
- data/lib/searchlogic/named_scopes/conditions.rb +8 -6
- data/lib/searchlogic/rails_helpers.rb +6 -2
- data/lib/searchlogic/search.rb +2 -2
- data/searchlogic.gemspec +3 -3
- data/spec/named_scopes/association_conditions_spec.rb +6 -2
- data/spec/named_scopes/association_ordering_spec.rb +4 -0
- data/spec/search_spec.rb +11 -1
- data/spec/spec_helper.rb +2 -0
- metadata +4 -3
data/CHANGELOG.rdoc
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
== 2.1.
|
1
|
+
== 2.1.9 released 2009-07-28
|
2
|
+
|
3
|
+
* Fixed bug when cloning with no scope
|
4
|
+
* Allow the call of foreign pre-existing named scopes instead of those generated by searchlogic. Allows you to call named scopes on associations that you define yourself.
|
5
|
+
|
6
|
+
== 2.1.8 released 2009-07-15
|
2
7
|
|
3
8
|
* Added support for not_like, not_begin_with, not_end_with, and not_null
|
4
9
|
|
data/VERSION.yml
CHANGED
@@ -49,14 +49,21 @@ module Searchlogic
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def association_condition_details(name)
|
52
|
-
|
53
|
-
|
52
|
+
regexes = [/^(#{reflect_on_all_associations.collect(&:name).join("|")})_(\w+)_(#{Conditions::PRIMARY_CONDITIONS.join("|")})$/]
|
53
|
+
reflect_on_all_associations.each do |assoc|
|
54
|
+
regexes << /^(#{assoc.name})_(#{assoc.klass.scopes.keys.join("|")})$/
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
if !local_condition?(name) && regexes.any? { |regex| name.to_s =~ regex }
|
54
59
|
{:association => $1, :column => $2, :condition => $3}
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
63
|
def create_association_condition(association_name, column, condition, args)
|
59
|
-
|
64
|
+
name_parts = [column, condition].compact
|
65
|
+
condition_name = name_parts.join("_")
|
66
|
+
named_scope("#{association_name}_#{condition_name}", association_condition_options(association_name, condition_name, args))
|
60
67
|
end
|
61
68
|
|
62
69
|
def association_alias_condition_details(name)
|
@@ -103,8 +110,11 @@ module Searchlogic
|
|
103
110
|
end
|
104
111
|
end
|
105
112
|
end
|
113
|
+
|
114
|
+
arg_type = (scope_options.respond_to?(:searchlogic_arg_type) && scope_options.searchlogic_arg_type) || :string
|
115
|
+
|
106
116
|
eval <<-"end_eval"
|
107
|
-
searchlogic_lambda(:#{
|
117
|
+
searchlogic_lambda(:#{arg_type}) { |#{proc_args.join(",")}|
|
108
118
|
options = association.klass.named_scope_options(association_condition).call(#{proc_args.join(",")})
|
109
119
|
options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
|
110
120
|
options
|
@@ -140,6 +140,8 @@ module Searchlogic
|
|
140
140
|
|
141
141
|
def create_primary_condition(column, condition)
|
142
142
|
column_type = columns_hash[column.to_s].type
|
143
|
+
match_keyword =
|
144
|
+
ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
143
145
|
scope_options = case condition.to_s
|
144
146
|
when /^equals/
|
145
147
|
scope_options(condition, column_type, "#{table_name}.#{column} = ?")
|
@@ -154,17 +156,17 @@ module Searchlogic
|
|
154
156
|
when /^greater_than/
|
155
157
|
scope_options(condition, column_type, "#{table_name}.#{column} > ?")
|
156
158
|
when /^like/
|
157
|
-
scope_options(condition, column_type, "#{table_name}.#{column}
|
159
|
+
scope_options(condition, column_type, "#{table_name}.#{column} #{match_keyword} ?", :like)
|
158
160
|
when /^not_like/
|
159
|
-
scope_options(condition, column_type, "#{table_name}.#{column} NOT
|
161
|
+
scope_options(condition, column_type, "#{table_name}.#{column} NOT #{match_keyword} ?", :like)
|
160
162
|
when /^begins_with/
|
161
|
-
scope_options(condition, column_type, "#{table_name}.#{column}
|
163
|
+
scope_options(condition, column_type, "#{table_name}.#{column} #{match_keyword} ?", :begins_with)
|
162
164
|
when /^not_begin_with/
|
163
|
-
scope_options(condition, column_type, "#{table_name}.#{column} NOT
|
165
|
+
scope_options(condition, column_type, "#{table_name}.#{column} NOT #{match_keyword} ?", :begins_with)
|
164
166
|
when /^ends_with/
|
165
|
-
scope_options(condition, column_type, "#{table_name}.#{column}
|
167
|
+
scope_options(condition, column_type, "#{table_name}.#{column} #{match_keyword} ?", :ends_with)
|
166
168
|
when /^not_end_with/
|
167
|
-
scope_options(condition, column_type, "#{table_name}.#{column} NOT
|
169
|
+
scope_options(condition, column_type, "#{table_name}.#{column} NOT #{match_keyword} ?", :ends_with)
|
168
170
|
when "null"
|
169
171
|
{:conditions => "#{table_name}.#{column} IS NULL"}
|
170
172
|
when "not_null"
|
@@ -17,6 +17,7 @@ module Searchlogic
|
|
17
17
|
# * <tt>:as</tt> - the text used in the link, defaults to whatever is passed to :by
|
18
18
|
# * <tt>:ascend_scope</tt> - what scope to call for ascending the data, defaults to "ascend_by_:by"
|
19
19
|
# * <tt>:descend_scope</tt> - what scope to call for descending the data, defaults to "descend_by_:by"
|
20
|
+
# * <tt>:params</tt> - hash with additional params which will be added to generated url
|
20
21
|
# * <tt>:params_scope</tt> - the name of the params key to scope the order condition by, defaults to :search
|
21
22
|
def order(search, options = {}, html_options = {})
|
22
23
|
options[:params_scope] ||= :search
|
@@ -37,7 +38,10 @@ module Searchlogic
|
|
37
38
|
end
|
38
39
|
html_options[:class] = css_classes.join(" ")
|
39
40
|
end
|
40
|
-
|
41
|
+
url_options = {
|
42
|
+
options[:params_scope] => search.conditions.merge( { :order => new_scope } )
|
43
|
+
}.deep_merge(options[:params] || {})
|
44
|
+
link_to options[:as], url_for(url_options), html_options
|
41
45
|
end
|
42
46
|
|
43
47
|
# Automatically makes the form method :get if a Searchlogic::Search and sets
|
@@ -66,4 +70,4 @@ module Searchlogic
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
end
|
69
|
-
end
|
73
|
+
end
|
data/lib/searchlogic/search.rb
CHANGED
@@ -51,7 +51,7 @@ module Searchlogic
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def clone
|
54
|
-
self.class.new(klass, current_scope.clone, conditions.clone)
|
54
|
+
self.class.new(klass, current_scope && current_scope.clone, conditions.clone)
|
55
55
|
end
|
56
56
|
|
57
57
|
# Returns a hash of the current conditions set.
|
@@ -148,4 +148,4 @@ module Searchlogic
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
151
|
-
end
|
151
|
+
end
|
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.
|
5
|
+
s.version = "2.1.9"
|
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-
|
9
|
+
s.date = %q{2009-07-28}
|
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 = [
|
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
s.rdoc_options = ["--charset=UTF-8"]
|
49
49
|
s.require_paths = ["lib"]
|
50
50
|
s.rubyforge_project = %q{searchlogic}
|
51
|
-
s.rubygems_version = %q{1.3.
|
51
|
+
s.rubygems_version = %q{1.3.5}
|
52
52
|
s.summary = %q{Searchlogic provides common named scopes and object based searching for ActiveRecord.}
|
53
53
|
s.test_files = [
|
54
54
|
"spec/core_ext/object_spec.rb",
|
@@ -9,11 +9,15 @@ describe "Association Conditions" do
|
|
9
9
|
Company.users_orders_total_greater_than(10).proxy_options.should == Order.total_greater_than(10).proxy_options.merge(:joins => {:users => :orders})
|
10
10
|
end
|
11
11
|
|
12
|
-
it "should
|
12
|
+
it "should allow the use of foreign pre-existing named scopes" do
|
13
|
+
Company.users_uname("bjohnson").proxy_options.should == User.uname("bjohnson").proxy_options.merge(:joins => :users)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not allow named scopes on non existent association columns" do
|
13
17
|
lambda { User.users_whatever_like("bjohnson") }.should raise_error(NoMethodError)
|
14
18
|
end
|
15
19
|
|
16
|
-
it "should not
|
20
|
+
it "should not allow named scopes on non existent deep association columns" do
|
17
21
|
lambda { User.users_orders_whatever_like("bjohnson") }.should raise_error(NoMethodError)
|
18
22
|
end
|
19
23
|
|
@@ -16,4 +16,8 @@ describe "Association Ordering" do
|
|
16
16
|
it "should allow deep descending" do
|
17
17
|
Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
18
18
|
end
|
19
|
+
|
20
|
+
it "should ascend with a belongs to" do
|
21
|
+
User.ascend_by_company_name.proxy_options.should == Company.ascend_by_name.proxy_options.merge(:joins => :company)
|
22
|
+
end
|
19
23
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -40,6 +40,16 @@ describe "Search" do
|
|
40
40
|
search1.all.should == [user2]
|
41
41
|
end
|
42
42
|
|
43
|
+
it "should clone properly without scope" do
|
44
|
+
user1 = User.create(:age => 5)
|
45
|
+
user2 = User.create(:age => 25)
|
46
|
+
search1 = User.search(:age_gt => 10)
|
47
|
+
search2 = search1.clone
|
48
|
+
search2.age_gt = 1
|
49
|
+
search2.all.should == User.all
|
50
|
+
search1.all.should == [user2]
|
51
|
+
end
|
52
|
+
|
43
53
|
it "should delete the condition" do
|
44
54
|
search = User.search(:username_like => "bjohnson")
|
45
55
|
search.delete("username_like")
|
@@ -292,4 +302,4 @@ describe "Search" do
|
|
292
302
|
User.search(:order => "ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
|
293
303
|
end
|
294
304
|
end
|
295
|
-
end
|
305
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
14
14
|
create_table :companies do |t|
|
15
15
|
t.datetime :created_at
|
16
16
|
t.datetime :updated_at
|
17
|
+
t.string :name
|
17
18
|
t.integer :users_count, :default => 0
|
18
19
|
end
|
19
20
|
|
@@ -56,6 +57,7 @@ Spec::Runner.configure do |config|
|
|
56
57
|
class User < ActiveRecord::Base
|
57
58
|
belongs_to :company, :counter_cache => true
|
58
59
|
has_many :orders, :dependent => :destroy
|
60
|
+
named_scope :uname, lambda { |value| {:conditions => ["users.username = ?", value]} }
|
59
61
|
alias_scope :username_has, lambda { |value| username_like(value) }
|
60
62
|
end
|
61
63
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binarylogic-searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.9
|
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-
|
12
|
+
date: 2009-07-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- spec/spec_helper.rb
|
64
64
|
has_rdoc: false
|
65
65
|
homepage: http://github.com/binarylogic/searchlogic
|
66
|
+
licenses:
|
66
67
|
post_install_message:
|
67
68
|
rdoc_options:
|
68
69
|
- --charset=UTF-8
|
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
84
|
requirements: []
|
84
85
|
|
85
86
|
rubyforge_project: searchlogic
|
86
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.3.5
|
87
88
|
signing_key:
|
88
89
|
specification_version: 3
|
89
90
|
summary: Searchlogic provides common named scopes and object based searching for ActiveRecord.
|