corn_starch 1.1.22 → 1.1.23

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
2
  SHA1:
3
- metadata.gz: 18b3d4331dc97181961b8a00de34881568b7305b
4
- data.tar.gz: 761d747008766ce2060c5ae9ebcbe86a5bdb54d6
3
+ metadata.gz: 79dd6e86400c8a8304ce22a95a1d5215ac3ac781
4
+ data.tar.gz: 6c804297a842534f78a9d9e1b3a001f61a102f9c
5
5
  SHA512:
6
- metadata.gz: e7d74f31cab58e75adb08c8a6efa61c752aec5b1c79359daefd5c597f9cab6bd5519b475ab5f45cb12ecfbb650cd850da0d2ecd36b6f0911f3c6eef25bb33777
7
- data.tar.gz: a7e73920b3e43c54c9ad09bd8906703d2c0a67837462ef55dc89af6c2c11f2d37afcec22c04abe11def006729ef2f6a40bc844fc5f9959f3e42aedd50e2b01c5
6
+ metadata.gz: afd3f3a774e8042740b9169bb4a55a92ad60efab7a270c83ff7c139152070d24cfb84a0300dbc5a9597bd577533837eea6ef1942b9214c2c3e0eceae0a905234
7
+ data.tar.gz: 7397fb82f6630e6db6d032aba2bd41076fa8726b0fd66f8c3dff16e44e9e064bc9366c98f14b0af04de25c93270c5d3c9c0e2a182c5987bc420b9b99b9cb936a
@@ -19,55 +19,6 @@ module CornStarch
19
19
  # Use the Application's Layout
20
20
  layout 'layouts/application'
21
21
 
22
- ####################
23
- # Controller Utils #
24
- ####################
25
-
26
- # Universal Search
27
- def unisearch model, search
28
-
29
- # Check Search
30
- return model unless search
31
-
32
- # Initialize Variables
33
- search_model = model
34
- search_q = ''
35
- search_a = []
36
- search_fields = {}
37
-
38
- # Run through Model's Associations
39
- model.searchable_associations.each do |a|
40
-
41
- # Join into Search Model
42
- search_model = search_model.includes a
43
-
44
- # Acquire Association Target Model
45
- assoc = model.reflect_on_association(a).klass
46
-
47
- # Add Target Model's Search Fields
48
- search_fields[assoc.table_name] = assoc.searchable_attributes
49
- end
50
-
51
- # Add Base Model's Search Fields
52
- search_fields[model.table_name] = []
53
- model.searchable_attributes.each { |a| search_fields[model.table_name] << a }
54
-
55
- # Run through Search Fields Models
56
- search_fields.each do |m|
57
-
58
- # Run through Model's Fields
59
- m.each do |f|
60
-
61
- # Build Search Query & Arguments Array
62
- search_q = search_q + "#{m}.#{f} LIKE ? "
63
- search_a << "%#{search}%"
64
- end
65
- end
66
-
67
- # Perform Search and eliminate doubles
68
- search_model.where(search_q, *search_a).references(model.table_name).uniq
69
- end
70
-
71
22
  # Private
72
23
  private
73
24
 
@@ -140,6 +91,56 @@ module CornStarch
140
91
  params[:id] == current_user.id.to_s
141
92
  end
142
93
 
94
+ # Get Records
95
+ def get_records model, params
96
+ paginate unisearch(model, params[:search]), params
97
+ end
98
+
99
+ # Universal Search
100
+ def unisearch model, search
101
+
102
+ # Check Search
103
+ return model unless search
104
+
105
+ # Initialize Variables
106
+ search_model = model
107
+ search_q = ''
108
+ search_a = []
109
+ search_fields = {}
110
+
111
+ # Run through Model's Associations
112
+ model.searchable_associations.each do |a|
113
+
114
+ # Join into Search Model
115
+ search_model = search_model.includes a
116
+
117
+ # Acquire Association Target Model
118
+ assoc = model.reflect_on_association(a).klass
119
+
120
+ # Add Target Model's Search Fields
121
+ search_fields[assoc.table_name] = assoc.searchable_attributes
122
+ end
123
+
124
+ # Add Base Model's Search Fields
125
+ search_fields[model.table_name] = []
126
+ model.searchable_attributes.each { |a| search_fields[model.table_name] << a }
127
+
128
+ # Run through Search Fields Models
129
+ search_fields.each do |m|
130
+
131
+ # Run through Model's Fields
132
+ m.each do |f|
133
+
134
+ # Build Search Query & Arguments Array
135
+ search_q = search_q + "#{m}.#{f} LIKE ? "
136
+ search_a << "%#{search}%"
137
+ end
138
+ end
139
+
140
+ # Perform Search and eliminate doubles
141
+ search_model.where(search_q, *search_a).references(model.table_name).uniq
142
+ end
143
+
143
144
  # Paginate
144
145
  def paginate collection, params
145
146
 
@@ -1,3 +1,3 @@
1
1
  module CornStarch
2
- VERSION = '1.1.22'
2
+ VERSION = '1.1.23'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corn_starch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.22
4
+ version: 1.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eresse
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler