recordselect 3.8.3 → 3.8.6

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: 4a314fc5f315d44bd180f8ad7012d4dea78aa340
4
- data.tar.gz: 4ef4a5f928851ff3d0c932f54f55bc171195513c
3
+ metadata.gz: e3ac1254baf6c4a25347fbe76a7a4380769038a0
4
+ data.tar.gz: c45df6652c0984e1e32209bb75874f433e9d80a0
5
5
  SHA512:
6
- metadata.gz: 70f9bf5371ded6366b81fc7493ea47769237625f013ba40fbb1385acba9b20eeb45baf2020a4e575a24f17921a3ea3fcaee1ecf6d2120a0eb25f915dec1fea0f
7
- data.tar.gz: fc625d76a9060475b527a06ef1e320fb948be7a70366c0391ffebaaefcb96c8e0b57857a04cb685122569df2b065494b5e44eb4d4a6c489dd848ca8a79548d0f
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
- klass = record_select_model.where(conditions).includes(user_includes)
9
- klass = klass.references(user_includes) if Rails::VERSION::MAJOR >= 4 && user_includes.present?
10
- @count = klass.count if record_select_config.pagination?
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 ? klass.select(record_select_select) : klass
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
- merge_conditions(
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 = nil
62
+ conditions = []
63
63
  params.each do |field, value|
64
64
  next unless column = record_select_config.model.columns_hash[field]
65
- conditions = merge_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
- "#{column_name} IS NULL"
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
- ["#{column_name} = ?", record_select_type_cast(column, value)]
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
@@ -2,7 +2,7 @@ module RecordSelect
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 8
5
- PATCH = 3
5
+ PATCH = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  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.3
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-06-29 00:00:00.000000000 Z
13
+ date: 2017-08-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler