rails-simple-search 1.1.6 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 488dab542ff2bca0321fe73926c608d634a90b91
4
- data.tar.gz: f38088dc455a4c4ad6080904863f6bc501f6f0e0
2
+ SHA256:
3
+ metadata.gz: 25a52a9d4df55218b58ed0bfd14fd26b83d1073a9e7cf595ad43d6614e6b1bb8
4
+ data.tar.gz: 304a1ac4d8784efa69d5ecaa5f6f16b891b26ab45e01a686684b40a0beac64f8
5
5
  SHA512:
6
- metadata.gz: 2bd662eb8cc806a48768eaeb3e6a230fad92ebbc1367edf7dbda840aff12726bc8b23f0b5c12bb027889dbba2119b569db00a868a1c11340973cd09e67fd85e1
7
- data.tar.gz: a1e4694ff5e1404eaf0b58a63bf7864641df43fabd202cbc58348d2335f1596df9cac2db3e24fdc7be29efb05dd40385b57474f9dbce1aea8df83bf054ed49e9
6
+ metadata.gz: 4f6efabcecb4eaaddfe0380a56456c9351fdcab77406156e213238a4df1c9cb3e38ca850b91677e3ecba80e4bb245096d293759f02b622055e138f1a1d8319e4
7
+ data.tar.gz: 879154bc961b75adf9374a199b8403232c5db5601326aa42f49ebfaa119a1e96eafad63b3827bf5f5bc52f74e9dc4b8747c43b09f77fe5e026c6714d0fc94e7b
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = rails-simple-search
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
- match "/xxxxxx" => "yyyyyyy#zzzzzz"
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
@@ -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.6
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: 2017-08-28 00:00:00.000000000 Z
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
- rubyforge_project:
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