recordselect 3.8.3 → 3.8.6
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/lib/record_select/actions.rb +6 -4
- data/lib/record_select/conditions.rb +8 -16
- data/lib/record_select/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3ac1254baf6c4a25347fbe76a7a4380769038a0
|
4
|
+
data.tar.gz: c45df6652c0984e1e32209bb75874f433e9d80a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 194ace026298bd24c2b0340ad0f9a887427ef1f33958c1ce652f83a08b5bb8b8494aa23b6979a2dc9959484f6b4fb5036c4d3f6e544aed587fe82db91ea93a31
|
7
|
+
data.tar.gz: 02f1e8f4c554a844d5fd44099d1ab8afc778c3531814a74bfa0802d3f3de9c4808186f66c2da86a74350b153c28b421835337c3bf313bd9985bdf9fbc496c737
|
@@ -5,12 +5,14 @@ module RecordSelect
|
|
5
5
|
def browse
|
6
6
|
conditions = record_select_conditions
|
7
7
|
user_includes = record_select_includes
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
query = conditions.inject(record_select_model.includes(user_includes)) do |query, cond|
|
9
|
+
query.where(cond)
|
10
|
+
end
|
11
|
+
query = query.references(user_includes) if Rails::VERSION::MAJOR >= 4 && user_includes.present?
|
12
|
+
@count = query.count if record_select_config.pagination?
|
11
13
|
@count = @count.length if @count.is_a? Hash
|
12
14
|
pager = ::Paginator.new(@count, record_select_config.per_page) do |offset, per_page|
|
13
|
-
search = record_select_select ?
|
15
|
+
search = record_select_select ? query.select(record_select_select) : query
|
14
16
|
search = search.limit(per_page).offset(offset) if record_select_config.pagination?
|
15
17
|
search.includes(record_select_config.include).order(record_select_config.order_by).to_a
|
16
18
|
end
|
@@ -9,11 +9,11 @@ module RecordSelect
|
|
9
9
|
def record_select_conditions
|
10
10
|
conditions = []
|
11
11
|
|
12
|
-
|
12
|
+
[
|
13
13
|
record_select_conditions_from_search,
|
14
|
-
record_select_conditions_from_params,
|
14
|
+
*record_select_conditions_from_params,
|
15
15
|
record_select_conditions_from_controller
|
16
|
-
|
16
|
+
].compact
|
17
17
|
end
|
18
18
|
|
19
19
|
# an override method.
|
@@ -59,13 +59,10 @@ module RecordSelect
|
|
59
59
|
|
60
60
|
# generate conditions from the url parameters (e.g. users/browse?group_id=5)
|
61
61
|
def record_select_conditions_from_params
|
62
|
-
conditions =
|
62
|
+
conditions = []
|
63
63
|
params.each do |field, value|
|
64
64
|
next unless column = record_select_config.model.columns_hash[field]
|
65
|
-
conditions
|
66
|
-
conditions,
|
67
|
-
record_select_condition_for_column(column, value)
|
68
|
-
)
|
65
|
+
conditions << record_select_condition_for_column(column, value)
|
69
66
|
end
|
70
67
|
conditions
|
71
68
|
end
|
@@ -86,21 +83,16 @@ module RecordSelect
|
|
86
83
|
# generates an SQL condition for the given column/value
|
87
84
|
def record_select_condition_for_column(column, value)
|
88
85
|
model = record_select_config.model
|
89
|
-
column_name = model.quoted_table_name + '.' + model.connection.quote_column_name(column.name)
|
90
86
|
if value.is_a? Array
|
91
87
|
{column.name => value}
|
92
88
|
elsif value.blank? and column.null
|
93
|
-
|
89
|
+
{column.name => nil}
|
94
90
|
elsif [:string, :text].include? column.type
|
91
|
+
column_name = model.quoted_table_name + '.' + model.connection.quote_column_name(column.name)
|
95
92
|
["LOWER(#{column_name}) LIKE ?", value]
|
96
93
|
else
|
97
|
-
|
94
|
+
{column.name => record_select_type_cast(column, value)}
|
98
95
|
end
|
99
96
|
end
|
100
|
-
|
101
|
-
def merge_conditions(*conditions) #:nodoc:
|
102
|
-
c = conditions.find_all {|c| not c.nil? and not c.empty? }
|
103
|
-
c.empty? ? nil : c.collect{|c| record_select_config.model.send(:sanitize_sql, c)}.join(' AND ')
|
104
|
-
end
|
105
97
|
end
|
106
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recordselect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.8.
|
4
|
+
version: 3.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Cambra
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|