simple_column_search 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v1.0.2. Fixed SQL injection on Rails 3, and Rails 3 compatibility on Ruby 1.9.2.
2
+
1
3
  v1.0.1. Rails 3 compatibility, thanks Tom Wilson [twilson63]
2
4
 
3
5
  v1.0.0. PostgreSQL support, Rit Li [rit]
@@ -4,11 +4,11 @@ require 'active_record'
4
4
  module SimpleColumnSearch
5
5
  # Adds a Model.search('term1 term2') method that searches across SEARCH_COLUMNS
6
6
  # for ANDed TERMS ORed across columns.
7
- #
7
+ #
8
8
  # class User
9
9
  # simple_column_search :first_name, :last_name
10
10
  # end
11
- #
11
+ #
12
12
  # User.search('elijah') # => anyone with first or last name elijah
13
13
  # User.search('miller') # => anyone with first or last name miller
14
14
  # User.search('elijah miller')
@@ -23,29 +23,26 @@ module SimpleColumnSearch
23
23
 
24
24
  # PostgreSQL LIKE is case-sensitive, use ILIKE for case-insensitive
25
25
  like = connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
26
- # Determin if ActiveRecord 3 or ActiveRecord 2.3 - probaly beter way to do it!
27
- if self.methods.include?("where")
26
+ # Determine if ActiveRecord 3 or ActiveRecord 2.3 - probaly beter way to do it!
27
+ if self.respond_to?(:where)
28
28
  scope options[:name], lambda { |terms|
29
- conditions = terms.split.inject([]) do |acc, term|
29
+ conditions = terms.split.inject(where(nil)) do |acc, term|
30
30
  pattern = get_simple_column_pattern options[:match], term
31
- acc << columns.collect { |column| "#{table_name}.#{column} #{like} '#{pattern}'" }
32
-
31
+ acc.where(columns.collect { |column| "#{table_name}.#{column} #{like} :pattern" }.join(' OR '), { :pattern => pattern })
33
32
  end
34
-
35
- where conditions.map { |c| "(" + c.join(' or ') + ")" }.join(' and ')
36
- }
33
+ }
37
34
  else
38
35
  named_scope options[:name], lambda { |terms|
39
36
  conditions = terms.split.inject(nil) do |acc, term|
40
37
  pattern = get_simple_column_pattern options[:match], term
41
- merge_conditions acc, [columns.collect { |column| "#{table_name}.#{column} #{like} :pattern" }.join(' OR '), { :pattern => pattern }]
38
+ merge_conditions acc, [columns.collect { |column| "#{table_name}.#{column} #{like} :pattern" }.join(' OR '), { :pattern => pattern }]
42
39
  end
43
40
  { :conditions => conditions }
44
- }
41
+ }
45
42
  end
46
-
43
+
47
44
  end
48
-
45
+
49
46
  def get_simple_column_pattern(match, term)
50
47
  case(match)
51
48
  when :exact
@@ -58,8 +55,8 @@ module SimpleColumnSearch
58
55
  '%' + term
59
56
  else
60
57
  raise "Unexpected match type: #{options[:match]}"
61
- end
58
+ end
62
59
  end
63
-
64
-
60
+
61
+
65
62
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{simple_column_search}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Elijah Miller"]
9
- s.date = %q{2010-07-14}
9
+ s.date = %q{2010-08-29}
10
10
  s.description = %q{Quick and dirty multi column LIKE searches.}
11
11
  s.email = %q{elijah.miller@gmail.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/simple_column_search.rb", "README.rdoc"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_column_search
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Elijah Miller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-14 00:00:00 -04:00
18
+ date: 2010-08-29 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21