simple_column_search 1.0.0 → 1.0.1

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 CHANGED
@@ -1,3 +1,5 @@
1
+ v1.0.1. Rails 3 compatibility, thanks Tom Wilson [twilson63]
2
+
1
3
  v1.0.0. PostgreSQL support, Rit Li [rit]
2
4
 
3
5
  v0.1.2. Fixed initialization when used as a plugin.
data/README.rdoc CHANGED
@@ -31,10 +31,13 @@ As a Rails plugin.
31
31
 
32
32
  Prefer gems? Add this to your environment.rb and run the following command.
33
33
 
34
- config.gem 'simple_column_search', :source => 'http://gemcutter.org'
34
+ config.gem 'simple_column_search'
35
35
 
36
36
  $ rake gems:install
37
37
 
38
+ == Docs
38
39
 
39
- Homepage:: http://github.com/jqr/simple_column_search/tree/master
40
+ http://rdoc.info/projects/jqr/simple_column_search
41
+
42
+ Homepage:: http://github.com/jqr/simple_column_search
40
43
  License:: Copyright (c) 2008 Elijah Miller <mailto:elijah.miller@gmail.com>, released under the MIT license.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require 'spec/rake/spectask'
1
+ #require 'spec/rake/spectask'
2
2
 
3
3
  require 'echoe'
4
4
  Echoe.new 'simple_column_search' do |p|
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'activerecord'
2
+ require 'active_record'
3
3
 
4
4
  module SimpleColumnSearch
5
5
  # Adds a Model.search('term1 term2') method that searches across SEARCH_COLUMNS
@@ -23,27 +23,43 @@ 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")
28
+ scope options[:name], lambda { |terms|
29
+ conditions = terms.split.inject([]) do |acc, term|
30
+ pattern = get_simple_column_pattern options[:match], term
31
+ acc << columns.collect { |column| "#{table_name}.#{column} #{like} '#{pattern}'" }
32
+
33
+ end
34
+
35
+ where conditions.map { |c| "(" + c.join(' or ') + ")" }.join(' and ')
36
+ }
37
+ else
38
+ named_scope options[:name], lambda { |terms|
39
+ conditions = terms.split.inject(nil) do |acc, term|
40
+ pattern = get_simple_column_pattern options[:match], term
41
+ merge_conditions acc, [columns.collect { |column| "#{table_name}.#{column} #{like} :pattern" }.join(' OR '), { :pattern => pattern }]
42
+ end
43
+ { :conditions => conditions }
44
+ }
45
+ end
26
46
 
27
- named_scope options[:name], lambda { |terms|
28
- conditions = terms.split.inject(nil) do |acc, term|
29
- pattern =
30
- case(options[:match])
31
- when :exact
32
- term
33
- when :start
34
- term + '%'
35
- when :middle
36
- '%' + term + '%'
37
- when :end
38
- '%' + term
39
- else
40
- raise "Unexpected match type: #{options[:match]}"
41
- end
42
- merge_conditions acc, [columns.collect { |column| "#{table_name}.#{column} #{like} :pattern" }.join(' OR '), { :pattern => pattern }]
43
- end
44
-
45
- { :conditions => conditions }
46
- }
47
47
  end
48
48
 
49
+ def get_simple_column_pattern(match, term)
50
+ case(match)
51
+ when :exact
52
+ term
53
+ when :start
54
+ term + '%'
55
+ when :middle
56
+ '%' + term + '%'
57
+ when :end
58
+ '%' + term
59
+ else
60
+ raise "Unexpected match type: #{options[:match]}"
61
+ end
62
+ end
63
+
64
+
49
65
  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.0"
5
+ s.version = "1.0.1"
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{2009-12-03}
9
+ s.date = %q{2010-07-14}
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"]
@@ -15,14 +15,14 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Simple_column_search", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{simple_column_search}
18
- s.rubygems_version = %q{1.3.5}
18
+ s.rubygems_version = %q{1.3.7}
19
19
  s.summary = %q{Quick and dirty multi column LIKE searches.}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
23
  s.specification_version = 3
24
24
 
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
26
  else
27
27
  end
28
28
  else
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_column_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Elijah Miller
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-03 00:00:00 -05:00
18
+ date: 2010-07-14 00:00:00 -04:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -48,21 +54,28 @@ rdoc_options:
48
54
  require_paths:
49
55
  - lib
50
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ">="
53
60
  - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
54
64
  version: "0"
55
- version:
56
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
57
67
  requirements:
58
68
  - - ">="
59
69
  - !ruby/object:Gem::Version
70
+ hash: 11
71
+ segments:
72
+ - 1
73
+ - 2
60
74
  version: "1.2"
61
- version:
62
75
  requirements: []
63
76
 
64
77
  rubyforge_project: simple_column_search
65
- rubygems_version: 1.3.5
78
+ rubygems_version: 1.3.7
66
79
  signing_key:
67
80
  specification_version: 3
68
81
  summary: Quick and dirty multi column LIKE searches.