searchlogic 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 2.3.1 released 2009-08-24
2
+
3
+ * Added blank and not_blank conditions.
4
+ * Made User.whatever_like_any("val1", "val2") consistent with User.whatever_like_any(["val1", "val2"])
5
+
1
6
  == 2.3.0 released 2009-08-22
2
7
 
3
8
  * Thanks to laserlemon for support of ranges and arrays in the equals condition.
@@ -1,6 +1,6 @@
1
1
  = Searchlogic
2
2
 
3
- Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive. It helps keep your code DRY, clean, and simple.
3
+ Searchlogic makes using ActiveRecord named scopes easier and less repetitive. It helps keep your code DRY, clean, and simple.
4
4
 
5
5
  == Helpful links
6
6
 
@@ -71,17 +71,19 @@ For a complete list of conditions please see the constants in Searchlogic::Named
71
71
 
72
72
  Typing out 'greater_than_or_equal_to' is not fun. Instead Searchlogic provides various aliases for the conditions. For a complete list please see Searchlogic::NamedScopes::Conditions. But they are pretty straightforward:
73
73
 
74
- User.username_is(10)
75
- User.username_eq(10)
76
- User.id_lt(10)
77
- User.id_lte(10)
74
+ User.username_is(10) # equals
75
+ User.username_eq(10) # equals
76
+ User.id_lt(10) # less than
77
+ User.id_lte(10) # less than or equal to
78
+ User.id_gt(10) # greater than
79
+ User.id_gte(10) # greater than or equal to
78
80
  # etc...
79
81
 
80
82
  == Search using scopes in associated classes
81
83
 
82
84
  This is my favorite part of Searchlogic. You can dynamically call scopes on associated classes and Searchlogic will take care of creating the necessary joins for you. This is REALY nice for keeping your code DRY. The best way to explain this is to show you:
83
85
 
84
- Let's take some basic scopes that Searchlogic provides:
86
+ Let's take some basic scopes that Searchlogic provides for every model:
85
87
 
86
88
  # We have the following relationships
87
89
  User.has_many :orders
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "searchlogic"
8
- gem.summary = "Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive."
9
- gem.description = "Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive."
8
+ gem.summary = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
9
+ gem.description = "Searchlogic makes using ActiveRecord named scopes easier and less repetitive."
10
10
  gem.email = "bjohnson@binarylogic.com"
11
11
  gem.homepage = "http://github.com/binarylogic/searchlogic"
12
12
  gem.authors = ["Ben Johnson of Binary Logic"]
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 3
3
- :patch: 0
3
+ :patch: 1
4
4
  :major: 2
@@ -30,7 +30,9 @@ module Searchlogic
30
30
  BOOLEAN_CONDITIONS = {
31
31
  :null => [:nil],
32
32
  :not_null => [:not_nil],
33
- :empty => []
33
+ :empty => [],
34
+ :blank => [],
35
+ :not_blank => [:present]
34
36
  }
35
37
 
36
38
  CONDITIONS = {}
@@ -117,6 +119,10 @@ module Searchlogic
117
119
  {:conditions => "#{table_name}.#{column} IS NOT NULL"}
118
120
  when "empty"
119
121
  {:conditions => "#{table_name}.#{column} = ''"}
122
+ when "blank"
123
+ {:conditions => "#{table_name}.#{column} = '' OR #{table_name}.#{column} IS NULL"}
124
+ when "not_blank"
125
+ {:conditions => "#{table_name}.#{column} != '' OR #{table_name}.#{column} IS NOT NULL"}
120
126
  end
121
127
 
122
128
  named_scope("#{column}_#{condition}".to_sym, scope_options)
@@ -130,7 +136,7 @@ module Searchlogic
130
136
  when /_(any|all)$/
131
137
  searchlogic_lambda(column_type) { |*values|
132
138
  return {} if values.empty?
133
-
139
+ values.flatten!
134
140
  values.collect! { |value| value_with_modifier(value, value_modifier) }
135
141
 
136
142
  join = $1 == "any" ? " OR " : " AND "
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{searchlogic}
8
- s.version = "2.3.0"
8
+ s.version = "2.3.1"
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{2009-08-22}
13
- s.description = %q{Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive.}
12
+ s.date = %q{2009-08-24}
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 = [
16
16
  "LICENSE",
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
55
55
  s.require_paths = ["lib"]
56
56
  s.rubyforge_project = %q{searchlogic}
57
57
  s.rubygems_version = %q{1.3.5}
58
- s.summary = %q{Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive.}
58
+ s.summary = %q{Searchlogic makes using ActiveRecord named scopes easier and less repetitive.}
59
59
  s.test_files = [
60
60
  "spec/core_ext/object_spec.rb",
61
61
  "spec/core_ext/proc_spec.rb",
@@ -93,6 +93,16 @@ describe "Conditions" do
93
93
  ["bjohnson", ""].each { |username| User.create(:username => username) }
94
94
  User.username_empty.all.should == User.find_all_by_username("")
95
95
  end
96
+
97
+ it "should have blank" do
98
+ ["bjohnson", "", nil].each { |username| User.create(:username => username) }
99
+ User.username_blank.all.should == User.all(:conditions => "username IS NULL OR username = ''")
100
+ end
101
+
102
+ it "should have not blank" do
103
+ ["bjohnson", "", nil].each { |username| User.create(:username => username) }
104
+ User.username_not_blank.all.should == User.all(:conditions => "username IS NOT NULL OR username != ''")
105
+ end
96
106
  end
97
107
 
98
108
  context "any and all conditions" do
@@ -100,6 +110,11 @@ describe "Conditions" do
100
110
  User.username_equals_any.proxy_options.should == {}
101
111
  end
102
112
 
113
+ it "should treat an array and multiple arguments the same" do
114
+ %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
115
+ User.username_like_any("bjohnson", "thunt").should == User.username_like_any(["bjohnson", "thunt"])
116
+ end
117
+
103
118
  it "should have equals any" do
104
119
  %w(bjohnson thunt dgainor).each { |username| User.create(:username => username) }
105
120
  User.username_equals_any("bjohnson", "thunt").all == User.find_all_by_username(["bjohnson", "thunt"])
@@ -17,6 +17,18 @@ describe "Or conditions" do
17
17
  lambda { User.usernme_begins_with_or_name_like("ben") }.should raise_error(Searchlogic::NamedScopes::OrConditions::UnknownConditionError)
18
18
  end
19
19
 
20
+ it "should work well with _or_equal_to" do
21
+ User.id_less_than_or_equal_to_or_age_gt(10).proxy_options.should == {:conditions => "(users.age > 10) OR (users.id <= 10)"}
22
+ end
23
+
24
+ it "should work well with _or_equal_to_any" do
25
+ User.id_less_than_or_equal_to_all_or_age_gt(10).proxy_options.should == {:conditions => "(users.age > 10) OR (users.id <= 10)"}
26
+ end
27
+
28
+ it "should work well with _or_equal_to_all" do
29
+ User.id_less_than_or_equal_to_any_or_age_gt(10).proxy_options.should == {:conditions => "(users.age > 10) OR (users.id <= 10)"}
30
+ end
31
+
20
32
  it "should play nice with other scopes" do
21
33
  User.username_begins_with("ben").id_gt(10).age_not_nil.username_or_name_ends_with("ben").scope(:find).should ==
22
34
  {:conditions => "((users.name LIKE '%ben') OR (users.username LIKE '%ben')) AND ((users.age IS NOT NULL) AND ((users.id > 10) AND (users.username LIKE 'ben%')))"}
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.0
4
+ version: 2.3.1
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-08-22 00:00:00 -04:00
12
+ date: 2009-08-24 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.0.0
24
24
  version:
25
- description: Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive.
25
+ description: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
26
26
  email: bjohnson@binarylogic.com
27
27
  executables: []
28
28
 
@@ -91,7 +91,7 @@ rubyforge_project: searchlogic
91
91
  rubygems_version: 1.3.5
92
92
  signing_key:
93
93
  specification_version: 3
94
- summary: Searchlogic provides tools that make using ActiveRecord named scopes easier and less repetitive.
94
+ summary: Searchlogic makes using ActiveRecord named scopes easier and less repetitive.
95
95
  test_files:
96
96
  - spec/core_ext/object_spec.rb
97
97
  - spec/core_ext/proc_spec.rb