rails-simple-search 1.1.6 → 1.1.8
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 +5 -5
- data/README.rdoc +7 -3
- data/lib/rails-simple-search.rb +24 -2
- data/lib/sql_handler.rb +4 -12
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 25a52a9d4df55218b58ed0bfd14fd26b83d1073a9e7cf595ad43d6614e6b1bb8
|
4
|
+
data.tar.gz: 304a1ac4d8784efa69d5ecaa5f6f16b891b26ab45e01a686684b40a0beac64f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f6efabcecb4eaaddfe0380a56456c9351fdcab77406156e213238a4df1c9cb3e38ca850b91677e3ecba80e4bb245096d293759f02b622055e138f1a1d8319e4
|
7
|
+
data.tar.gz: 879154bc961b75adf9374a199b8403232c5db5601326aa42f49ebfaa119a1e96eafad63b3827bf5f5bc52f74e9dc4b8747c43b09f77fe5e026c6714d0fc94e7b
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
=rails-simple-search
|
2
2
|
|
3
3
|
rails-simple-search is a Ruby gem. It helps you quickly implement searching/filtering function for your web site. This plugin has paginating feature built in. If you're not looking for a full-text searching solution, this plugin will most probably satisfy all your searching requirement.
|
4
4
|
|
@@ -41,7 +41,7 @@ The following is how we implement this searching function with rails-simple-sear
|
|
41
41
|
|
42
42
|
4. Code in views:
|
43
43
|
|
44
|
-
<% form_for @search, url => "/xxxxxx" do |f| %>
|
44
|
+
<% form_for @search, url => "/xxxxxx", data: {turbo: false} do |f| %>
|
45
45
|
|
46
46
|
<%=f.label :email %>
|
47
47
|
<%=f.text_field :email %>
|
@@ -69,7 +69,7 @@ The following is how we implement this searching function with rails-simple-sear
|
|
69
69
|
<% end %>
|
70
70
|
|
71
71
|
5. Add route for the post to url "/xxxxxx" (config/route.rb)
|
72
|
-
|
72
|
+
post "/xxxxxx" => "yyyyyyy#zzzzzz"
|
73
73
|
|
74
74
|
== Note
|
75
75
|
|
@@ -84,8 +84,12 @@ From version 1.1.0 on, we started to support the "or" relation, e.g., we can use
|
|
84
84
|
|
85
85
|
From version 1.1.3 on, we started to support Rails 5.
|
86
86
|
|
87
|
+
For Rails 7, please use version 1.1.7.
|
88
|
+
|
87
89
|
There is a real demo application which you can download and run immediately: https://github.com/yzhanginwa/demo_app_for_rails_simple_search
|
88
90
|
|
91
|
+
For Rails 7 demo, please see here: https://github.com/yzhanginwa/rails_simple_search_demo
|
92
|
+
|
89
93
|
== License
|
90
94
|
|
91
95
|
Copyright (c) 2012 [Yi Zhang], released under the MIT license
|
data/lib/rails-simple-search.rb
CHANGED
@@ -12,6 +12,8 @@ module RailsSimpleSearch
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Base
|
15
|
+
attr_reader :criteria
|
16
|
+
|
15
17
|
def self.inherited(subclass)
|
16
18
|
class << subclass
|
17
19
|
# in rails 3, the call to "form_for" invokes the model_name
|
@@ -24,6 +26,17 @@ module RailsSimpleSearch
|
|
24
26
|
subclass.send(:include, RailsSimpleSearch::FixModelName)
|
25
27
|
end
|
26
28
|
|
29
|
+
def self.pre_process(model_name, &procedure)
|
30
|
+
model_name.each { |internal_model_name| pre_process(internal_model_name, &procedure) } if model_name.is_a?(Array)
|
31
|
+
@pre_processors ||= {}
|
32
|
+
@pre_processors[model_name] = procedure
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.pre_processor(model_name)
|
36
|
+
@pre_processors ||= {}
|
37
|
+
@pre_processors[model_name]
|
38
|
+
end
|
39
|
+
|
27
40
|
def initialize(model_class, criteria={}, config={})
|
28
41
|
@criteria = sanitize_criteria(criteria)
|
29
42
|
@config = DEFAULT_CONFIG.merge(config)
|
@@ -48,9 +61,18 @@ module RailsSimpleSearch
|
|
48
61
|
end
|
49
62
|
|
50
63
|
def add_conditions(h={})
|
51
|
-
@criteria.merge!(h)
|
64
|
+
@criteria.merge!(h.stringify_keys)
|
52
65
|
end
|
53
66
|
|
67
|
+
def remove_criteria(key)
|
68
|
+
key.each { |internal_key| remove_criteria(internal_key) } if key.is_a?(Array)
|
69
|
+
@criteria.delete(key.to_s)
|
70
|
+
end
|
71
|
+
|
72
|
+
def append_criteria(key, value)
|
73
|
+
@criteria[key.to_s] = value
|
74
|
+
end
|
75
|
+
|
54
76
|
private
|
55
77
|
|
56
78
|
def method_missing(method, *args)
|
@@ -88,7 +110,7 @@ module RailsSimpleSearch
|
|
88
110
|
c[key] = value
|
89
111
|
end
|
90
112
|
end
|
91
|
-
c
|
113
|
+
c.stringify_keys
|
92
114
|
end
|
93
115
|
end
|
94
116
|
end
|
data/lib/sql_handler.rb
CHANGED
@@ -6,17 +6,11 @@ module RailsSimpleSearch
|
|
6
6
|
@joins = {}
|
7
7
|
end
|
8
8
|
|
9
|
-
def conditions
|
10
|
-
run_criteria
|
11
|
-
@conditions
|
12
|
-
end
|
13
|
-
|
14
|
-
def joins
|
15
|
-
run_criteria
|
16
|
-
@joins_str
|
17
|
-
end
|
18
|
-
|
19
9
|
def run
|
10
|
+
if pre_processor = self.class.pre_processor(@model_class.to_s)
|
11
|
+
instance_eval(&pre_processor)
|
12
|
+
end
|
13
|
+
|
20
14
|
run_criteria
|
21
15
|
|
22
16
|
query = @model_class.joins(@joins_str)
|
@@ -48,7 +42,6 @@ module RailsSimpleSearch
|
|
48
42
|
end
|
49
43
|
|
50
44
|
def run_criteria
|
51
|
-
return unless @conditions.nil?
|
52
45
|
@condition_group = ConditionGroup.new
|
53
46
|
@condition_group.set_relation(:and)
|
54
47
|
|
@@ -67,7 +60,6 @@ module RailsSimpleSearch
|
|
67
60
|
table = base_class.table_name
|
68
61
|
key = "#{table}.#{field}"
|
69
62
|
|
70
|
-
@conditions ||= []
|
71
63
|
column = base_class.columns_hash[field.to_s]
|
72
64
|
return nil unless column
|
73
65
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-simple-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yi Zhang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: rails-simple-search is a light and easy to use gem. It could help developers
|
14
14
|
quickly build a search page.
|
@@ -39,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
|
-
|
43
|
-
rubygems_version: 2.5.1
|
42
|
+
rubygems_version: 3.3.26
|
44
43
|
signing_key:
|
45
44
|
specification_version: 4
|
46
45
|
summary: A very simple and light gem to quickly build search/filter function in rails
|