easy_search_form 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/easy_search.rb +51 -3
- data/lib/easy_search/version.rb +1 -1
- metadata +1 -2
- data/lib/easy_search/acts_as_searchable.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29af1d7870bf16aeb753be33d4ffb1a55488a292
|
4
|
+
data.tar.gz: 9dbf02675b8c1a16ae978080889dd23ef66b4cd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cd571857217907433f33e304046fff19356746adc3a3ca0ac9a8b35b18faaa3f09711dee47e825dd2a91caa9846f700442c763232727df8681ae0de9b6ec3a3
|
7
|
+
data.tar.gz: caa9c8d142fc13824629c9a1b1d25b01cd3c2086c06d74e6ccbb649d1a88eb4fe46db5fac273b4e2705afd593af09972564014b81cd3665cb2cf5ed182c6c36f
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# EasySearchForm
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
|
@@ -9,7 +9,7 @@
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem 'easy_search_form'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -18,7 +18,7 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install
|
21
|
+
$ gem install easy_search_form
|
22
22
|
|
23
23
|
## Example
|
24
24
|
|
data/lib/easy_search.rb
CHANGED
@@ -1,9 +1,57 @@
|
|
1
1
|
require "easy_search/version"
|
2
|
-
require 'easy_search/acts_as_searchable'
|
3
2
|
require 'easy_search/easysearch_helper'
|
4
3
|
|
5
4
|
module EasySearch
|
6
|
-
|
5
|
+
def self.included(base)
|
6
|
+
base.send :extend, ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def acts_as_searchable(*args)
|
11
|
+
@search_options = args
|
12
|
+
self.send :extend, SearchClassMethods
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module SearchClassMethods
|
17
|
+
def search(search)
|
18
|
+
if search
|
19
|
+
query = []
|
20
|
+
values = []
|
21
|
+
@search_options.each do |opt|
|
22
|
+
condition_type = nil
|
23
|
+
|
24
|
+
if opt.instance_of?(Hash)
|
25
|
+
debugger
|
26
|
+
case opt[opt.keys.first]
|
27
|
+
when :equals
|
28
|
+
condition_type = "="
|
29
|
+
else
|
30
|
+
condition_type = "LIKE"
|
31
|
+
end
|
32
|
+
|
33
|
+
query << "#{opt.keys.first} #{condition_type} ?"
|
34
|
+
else
|
35
|
+
query << "#{opt} LIKE ?"
|
36
|
+
end
|
37
|
+
|
38
|
+
if condition_type.nil? or condition_type == "LIKE"
|
39
|
+
values << "%#{search}%"
|
40
|
+
else
|
41
|
+
values << search
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
conditions = [query.join(" OR ")]
|
46
|
+
conditions += values
|
47
|
+
|
48
|
+
find(:all, :conditions => conditions)
|
49
|
+
else
|
50
|
+
all
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
7
54
|
end
|
8
55
|
|
9
|
-
ActionView::Base.send :include, EasySearchHelper
|
56
|
+
ActionView::Base.send :include, EasySearchHelper
|
57
|
+
ActiveRecord::Base.send :include, EasySearch
|
data/lib/easy_search/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_search_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Cordeiro
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- bin/setup
|
70
70
|
- easy_search.gemspec
|
71
71
|
- lib/easy_search.rb
|
72
|
-
- lib/easy_search/acts_as_searchable.rb
|
73
72
|
- lib/easy_search/easysearch_helper.rb
|
74
73
|
- lib/easy_search/version.rb
|
75
74
|
- lib/easy_search/views/_search_form.html.erb
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module EasySearch
|
2
|
-
def self.included(base)
|
3
|
-
base.send :extend, ClassMethods
|
4
|
-
end
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def acts_as_searchable(*args)
|
8
|
-
@search_options = args
|
9
|
-
self.send :extend, SearchClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module SearchClassMethods
|
14
|
-
def search(search)
|
15
|
-
if search
|
16
|
-
query = []
|
17
|
-
values = []
|
18
|
-
@search_options.each do |opt|
|
19
|
-
condition_type = nil
|
20
|
-
|
21
|
-
if opt.instance_of?(Hash)
|
22
|
-
debugger
|
23
|
-
case opt[opt.keys.first]
|
24
|
-
when :equals
|
25
|
-
condition_type = "="
|
26
|
-
else
|
27
|
-
condition_type = "LIKE"
|
28
|
-
end
|
29
|
-
|
30
|
-
query << "#{opt.keys.first} #{condition_type} ?"
|
31
|
-
else
|
32
|
-
query << "#{opt} LIKE ?"
|
33
|
-
end
|
34
|
-
|
35
|
-
if condition_type.nil? or condition_type == "LIKE"
|
36
|
-
values << "%#{search}%"
|
37
|
-
else
|
38
|
-
values << search
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
conditions = [query.join(" OR ")]
|
43
|
-
conditions += values
|
44
|
-
|
45
|
-
find(:all, :conditions => conditions)
|
46
|
-
else
|
47
|
-
all
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
ActiveRecord::Base.send :include, EasySearch
|