will_filter 5.1.0 → 5.1.1

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: 3792795c59de11d775d37d03afb2d497d9e845d2
4
- data.tar.gz: 743f32488e08caf6d106f197132e7af9427b8c8f
3
+ metadata.gz: 9fe8cebd409b2e307d3720d1073ea9d6bd5f79d2
4
+ data.tar.gz: ae57f12d3fff3f71bfeb92fb6c2117e4fe314878
5
5
  SHA512:
6
- metadata.gz: e53d62aa1a2dc8211b65a0bc41b77c9b35cc6935121621be0e8a5a56fd90786a376cffbed1566e9dac432c9e8301e03d1fe9a124319e76157f1fb767e515a084
7
- data.tar.gz: '092323c5f9888b9f1878c56652917284594fbfaf2a248665ab71fbab769a3831aba1e9d21340708613f8f79edae16b77fd43cda807f249bfb42b8b2768a73997'
6
+ metadata.gz: 11dc83721d03a91f5c5c5b271850fd0714d96cf7b7c662969d3fd4819603cdcda8c3b64535d7229a3ef9e0a781e06bed62afa1be3ff946f43a2e2fe214b4a264
7
+ data.tar.gz: f266ee2c9b40ce0239792a014cc556237e687c8c6868ce31d10a8b15ca1ba43c5d187041ed2eec7e739ca1adfbc75cdd16cf8f6a89ce377174588e92dec823bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- will_filter (5.1.0)
4
+ will_filter (5.1.1)
5
5
  kaminari (~> 1.1)
6
6
  rails (~> 5.1)
7
7
  sass (~> 3.5)
@@ -213,4 +213,4 @@ DEPENDENCIES
213
213
  will_filter!
214
214
 
215
215
  BUNDLED WITH
216
- 1.15.3
216
+ 1.15.4
@@ -33,20 +33,20 @@
33
33
  module WillFilter
34
34
  module Containers
35
35
  class Boolean < WillFilter::FilterContainer
36
-
36
+
37
37
  def self.operators
38
38
  [:is]
39
39
  end
40
-
40
+
41
41
  def selected?
42
- value == "1"
42
+ value.to_s == '1'
43
43
  end
44
-
44
+
45
45
  def sql_condition
46
46
  return [" #{condition.full_key} = ? ", (selected? ? true : false)] if operator == :is
47
47
  end
48
-
49
- end
48
+
49
+ end
50
50
  end
51
51
  end
52
52
 
@@ -36,19 +36,19 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is, :is_not, :is_after, :is_before]
38
38
  end
39
-
39
+
40
40
  def validate
41
- return "Value must be provided" if value.blank?
42
- return "Value must be a valid date (2008-01-01)" if date.nil?
41
+ return 'Value must be provided' if value.blank?
42
+ return 'Value must be a valid date (2008-01-01)' if date.nil?
43
43
  end
44
-
44
+
45
45
  def sql_condition
46
- return [" #{condition.full_key} = ? ", date] if operator == :is
47
- return [" #{condition.full_key} <> ? ", date] if operator == :is_not
48
- return [" #{condition.full_key} > ? ", date] if operator == :is_after
49
- return [" #{condition.full_key} < ? ", date] if operator == :is_before
46
+ return [" #{condition.full_key} = ? ", date] if operator == :is
47
+ return [" #{condition.full_key} <> ? ", date] if operator == :is_not
48
+ return [" #{condition.full_key} > ? ", date] if operator == :is_after
49
+ return [" #{condition.full_key} < ? ", date] if operator == :is_before
50
50
  end
51
-
51
+
52
52
  end
53
53
  end
54
54
  end
@@ -36,24 +36,24 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is_in_the_range]
38
38
  end
39
-
39
+
40
40
  def initialize(filter, criteria_key, operator, values)
41
41
  super(filter, criteria_key, operator, values)
42
42
  @start_date = values[0]
43
43
  @end_date = values[1] if values.size > 1
44
44
  end
45
-
45
+
46
46
  def validate
47
47
  return "Start value must be provided" if @start_date.blank?
48
48
  return "Start value must be a valid date (2008-01-01)" if date(@start_date).nil?
49
49
  return "End value must be provided" if @end_date.blank?
50
50
  return "End value must be a valid date (2008-01-01)" if date(@end_date).nil?
51
51
  end
52
-
52
+
53
53
  def sql_condition
54
54
  return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", date(@start_date), date(@end_date)] if operator == :is_in_the_range
55
55
  end
56
-
56
+
57
57
  end
58
58
  end
59
59
  end
@@ -36,17 +36,17 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is, :is_not, :is_after, :is_before]
38
38
  end
39
-
39
+
40
40
  def validate
41
- return "Value must be provided" if value.blank?
42
- return "Value must be a valid date/time (2008-01-01 14:30:00)" if time.nil?
41
+ return 'Value must be provided' if value.blank?
42
+ return 'Value must be a valid date/time (2008-01-01 14:30:00)' if time.nil?
43
43
  end
44
-
44
+
45
45
  def sql_condition
46
- return [" #{condition.full_key} = ? ", time] if operator == :is
47
- return [" #{condition.full_key} <> ? ", time] if operator == :is_not
48
- return [" #{condition.full_key} > ? ", time] if operator == :is_after
49
- return [" #{condition.full_key} < ? ", time] if operator == :is_before
46
+ return [" #{condition.full_key} = ? ", time] if operator == :is
47
+ return [" #{condition.full_key} <> ? ", time] if operator == :is_not
48
+ return [" #{condition.full_key} > ? ", time] if operator == :is_after
49
+ return [" #{condition.full_key} < ? ", time] if operator == :is_before
50
50
  end
51
51
  end
52
52
  end
@@ -34,28 +34,28 @@ module WillFilter
34
34
  module Containers
35
35
  class DateTimeRange < WillFilter::FilterContainer
36
36
  attr_accessor :start_value, :end_value
37
-
37
+
38
38
  def self.operators
39
39
  [:is_in_the_range]
40
40
  end
41
-
41
+
42
42
  def initialize(filter, criteria_key, operator, values)
43
43
  super(filter, criteria_key, operator, values)
44
-
44
+
45
45
  @start_value = values[0]
46
46
  @end_value = values[1] if values.size > 1
47
47
  end
48
-
48
+
49
49
  def validate
50
50
  return "Start value must be provided" if start_value.blank?
51
51
  return "Start value must be a valid date/time (2008-01-01 14:30:00)" if time(start_value).nil?
52
52
  return "End value must be provided" if end_value.blank?
53
53
  return "End value must be a valid date/time (2008-01-01 14:30:00)" if time(end_value).nil?
54
54
  end
55
-
55
+
56
56
  def sql_condition
57
57
  return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", time(start_value), time(end_value)] if operator == :is_in_the_range
58
58
  end
59
59
  end
60
- end
60
+ end
61
61
  end
@@ -36,25 +36,25 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is, :is_not, :is_less_than, :is_greater_than]
38
38
  end
39
-
39
+
40
40
  def template_name
41
41
  'text'
42
42
  end
43
-
43
+
44
44
  def numeric_value
45
45
  value.to_f
46
46
  end
47
-
47
+
48
48
  def validate
49
49
  return "Value must be provided" if value.blank?
50
50
  return "Value must be a valid floating point number" unless is_floating_point?(value)
51
51
  end
52
-
52
+
53
53
  def sql_condition
54
- return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
55
- return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
56
- return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
57
- return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
54
+ return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
55
+ return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
56
+ return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
57
+ return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
58
58
  end
59
59
  end
60
60
  end
@@ -33,24 +33,24 @@
33
33
  module WillFilter
34
34
  module Containers
35
35
  class DoubleDelimited < WillFilter::FilterContainer
36
- NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
37
-
36
+ NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
37
+
38
38
  def self.operators
39
39
  [:is_in]
40
40
  end
41
-
41
+
42
42
  def template_name
43
43
  'text'
44
44
  end
45
-
45
+
46
46
  def validate
47
47
  return "Values must be provided. Separate values with '#{NUMERIC_DELIMITER}'" if value.blank?
48
48
  end
49
-
49
+
50
50
  def split_values
51
- value.split(NUMERIC_DELIMITER).collect{|v| v.strip.to_f}
51
+ value.split(NUMERIC_DELIMITER).collect {|v| v.strip.to_f}
52
52
  end
53
-
53
+
54
54
  def sql_condition
55
55
  return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
56
56
  end
@@ -30,29 +30,30 @@
30
30
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
31
  #++
32
32
 
33
+
33
34
  module WillFilter
34
35
  module Containers
35
36
  class DoubleRange < WillFilter::FilterContainer
36
37
  attr_accessor :start_value, :end_value
37
-
38
+
38
39
  def self.operators
39
40
  [:is_in_the_range]
40
41
  end
41
-
42
+
42
43
  def initialize(filter, criteria_key, operator, values)
43
44
  super(filter, criteria_key, operator, values)
44
-
45
+
45
46
  @start_value = values[0]
46
47
  @end_value = values[1] if values.size > 1
47
48
  end
48
-
49
+
49
50
  def validate
50
- return "Start value must be provided" if start_value.blank?
51
- return "Start value must be a floating point number" unless is_floating_point?(start_value)
52
- return "End value must be provided" if end_value.blank?
53
- return "End value must be a floating point number" unless is_floating_point?(end_value)
51
+ return "Start value must be provided" if start_value.blank?
52
+ return "Start value must be a floating point number" unless is_floating_point?(start_value)
53
+ return "End value must be provided" if end_value.blank?
54
+ return "End value must be a floating point number" unless is_floating_point?(end_value)
54
55
  end
55
-
56
+
56
57
  def template_name
57
58
  'numeric_range'
58
59
  end
@@ -60,11 +61,11 @@ module WillFilter
60
61
  def numeric_start_value
61
62
  start_value.to_f
62
63
  end
63
-
64
+
64
65
  def numeric_end_value
65
66
  end_value.to_f
66
67
  end
67
-
68
+
68
69
  def sql_condition
69
70
  return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
70
71
  end
@@ -36,39 +36,34 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is_filtered_by]
38
38
  end
39
-
39
+
40
40
  def validate
41
41
  return "Value must be provided" if value.blank?
42
42
  end
43
-
43
+
44
44
  def template_name
45
45
  'list'
46
46
  end
47
47
 
48
48
  def linked_filter
49
49
  @linked_filter ||= begin
50
- model_class = filter.model_class_for_column_key(condition.key)
51
-
52
- if model_class
53
- model_class_name = model_class.name
54
- elsif condition.key == :id
50
+ if condition.key == :id
55
51
  model_class_name = filter.model_class_name
56
52
  else
57
53
  model_class_name = condition.key.to_s[0..-4].camelcase
58
54
  end
59
-
60
55
  WillFilter::Filter.new(model_class_name)
61
56
  end
62
57
  end
63
-
58
+
64
59
  def options
65
60
  linked_filter.saved_filters(false)
66
61
  end
67
-
62
+
68
63
  def sql_condition
69
64
  return nil unless operator == :is_filtered_by
70
65
  sub_filter = WillFilter::Filter.find_by_id(value) || linked_filter.user_filters.first
71
- return [""] unless sub_filter
66
+ return [''] unless sub_filter
72
67
 
73
68
  sub_conds = sub_filter.sql_conditions
74
69
 
@@ -76,7 +71,7 @@ module WillFilter
76
71
  sub_conds[0] = " #{condition.full_key} IN (SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name}) "
77
72
  else
78
73
  sub_conds[0] = " #{condition.full_key} IN (SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name} WHERE #{sub_conds[0]}) "
79
- end
74
+ end
80
75
 
81
76
  sub_conds
82
77
  end
@@ -36,7 +36,7 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is, :is_not, :contains, :does_not_contain]
38
38
  end
39
-
39
+
40
40
  def options
41
41
  opts = []
42
42
  filter.value_options_for(condition.key).each do |item|
@@ -52,14 +52,15 @@ module WillFilter
52
52
  end
53
53
  opts
54
54
  end
55
-
55
+
56
56
  def sql_condition
57
- return [" #{condition.full_key} = ? ", value] if operator == :is
58
- return [" #{condition.full_key} <> ? ", value] if operator == :is_not
59
- return [" #{condition.full_key} like ? ", "%#{value}%"] if operator == :contains
60
- return [" #{condition.full_key} not like ? ", "%#{value}%"] if operator == :does_not_cotain
57
+ sanitized_value = value.to_s.downcase
58
+ return [" lower(#{condition.full_key}) = ? ", sanitized_value] if operator == :is
59
+ return [" lower(#{condition.full_key}) <> ? ", sanitized_value] if operator == :is_not
60
+ return [" lower(#{condition.full_key}) like ? ", "%#{sanitized_value}%"] if operator == :contains
61
+ return [" lower(#{condition.full_key}) not like ? ", "%#{sanitized_value}%"] if operator == :does_not_cotain
61
62
  end
62
-
63
+
63
64
  end
64
65
  end
65
66
  end
@@ -36,18 +36,18 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is_provided, :is_not_provided]
38
38
  end
39
-
39
+
40
40
  def template_name
41
41
  'blank'
42
42
  end
43
-
43
+
44
44
  def validate
45
45
  # no validation is necessary
46
46
  end
47
-
47
+
48
48
  def sql_condition
49
- return [" #{condition.full_key} is not null "] if operator == :is_provided
50
- return [" #{condition.full_key} is null "] if operator == :is_not_provided
49
+ return [" #{condition.full_key} is not null "] if operator == :is_provided
50
+ return [" #{condition.full_key} is null "] if operator == :is_not_provided
51
51
  end
52
52
  end
53
53
  end
@@ -36,25 +36,25 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is, :is_not, :is_less_than, :is_greater_than]
38
38
  end
39
-
39
+
40
40
  def template_name
41
41
  'text'
42
42
  end
43
-
43
+
44
44
  def numeric_value
45
45
  value.to_i
46
46
  end
47
-
47
+
48
48
  def validate
49
49
  return "Value must be provided" if value.blank?
50
50
  return "Value must be numeric" unless is_numeric?(value)
51
51
  end
52
-
52
+
53
53
  def sql_condition
54
- return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
55
- return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
56
- return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
57
- return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
54
+ return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
55
+ return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
56
+ return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
57
+ return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
58
58
  end
59
59
  end
60
60
  end
@@ -33,24 +33,24 @@
33
33
  module WillFilter
34
34
  module Containers
35
35
  class NumericDelimited < WillFilter::FilterContainer
36
- NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
37
-
36
+ NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
37
+
38
38
  def self.operators
39
39
  [:is_in]
40
40
  end
41
-
41
+
42
42
  def template_name
43
43
  'text'
44
44
  end
45
-
45
+
46
46
  def validate
47
47
  return "Values must be provided. Separate values with '#{NUMERIC_DELIMITER}'" if value.blank?
48
48
  end
49
-
49
+
50
50
  def split_values
51
- value.split(NUMERIC_DELIMITER).collect{|v| v.strip.to_i}
51
+ value.split(NUMERIC_DELIMITER).collect {|v| v.strip.to_i}
52
52
  end
53
-
53
+
54
54
  def sql_condition
55
55
  return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
56
56
  end
@@ -34,33 +34,33 @@ module WillFilter
34
34
  module Containers
35
35
  class NumericRange < WillFilter::FilterContainer
36
36
  attr_accessor :start_value, :end_value
37
-
37
+
38
38
  def self.operators
39
39
  [:is_in_the_range]
40
40
  end
41
-
41
+
42
42
  def initialize(filter, criteria_key, operator, values)
43
43
  super(filter, criteria_key, operator, values)
44
-
44
+
45
45
  @start_value = values[0]
46
46
  @end_value = values[1] if values.size > 1
47
47
  end
48
-
48
+
49
49
  def validate
50
50
  return "Start value must be provided" if start_value.blank?
51
- return "Start value must be numeric" unless is_numeric?(start_value)
52
- return "End value must be provided" if end_value.blank?
53
- return "End value must be numeric" unless is_numeric?(end_value)
51
+ return "Start value must be numeric" unless is_numeric?(start_value)
52
+ return "End value must be provided" if end_value.blank?
53
+ return "End value must be numeric" unless is_numeric?(end_value)
54
54
  end
55
-
55
+
56
56
  def numeric_start_value
57
57
  start_value.to_i
58
58
  end
59
-
59
+
60
60
  def numeric_end_value
61
61
  end_value.to_i
62
62
  end
63
-
63
+
64
64
  def sql_condition
65
65
  return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
66
66
  end
@@ -36,32 +36,31 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is_on, :is_not_on]
38
38
  end
39
-
39
+
40
40
  def template_name
41
41
  'date'
42
42
  end
43
-
43
+
44
44
  def validate
45
45
  return "Value must be provided" if value.blank?
46
46
  return "Value must be a valid date (2008-01-01)" if start_date_time == nil
47
47
  end
48
-
48
+
49
49
  def start_date_time
50
50
  @start_date_time ||= Time.parse(value)
51
51
  rescue ArgumentError
52
52
  nil
53
53
  end
54
-
54
+
55
55
  def end_date_time
56
56
  (start_date_time + 1.day)
57
57
  rescue ArgumentError
58
58
  nil
59
59
  end
60
-
60
+
61
61
  def sql_condition
62
- return [' 1 = 0'] if time.nil?
63
- return [" #{condition.full_key} >= ? and #{condition.full_key} < ? ", time, time + 1.day] if operator == :is_on
64
- return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ", time, time + 1.day] if operator == :is_not_on
62
+ return [" #{condition.full_key} >= ? and #{condition.full_key} < ? ", time, time + 1.day] if operator == :is_on
63
+ return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ", time, time + 1.day] if operator == :is_not_on
65
64
  end
66
65
  end
67
66
  end
@@ -36,18 +36,19 @@ module WillFilter
36
36
  def self.operators
37
37
  [:is, :is_not, :contains, :does_not_contain, :starts_with, :ends_with]
38
38
  end
39
-
39
+
40
40
  def validate
41
41
  # always valid, even when it is empty
42
42
  end
43
-
43
+
44
44
  def sql_condition
45
- return [" #{condition.full_key} = ? ", value] if operator == :is
46
- return [" #{condition.full_key} <> ? ", value] if operator == :is_not
47
- return [" #{condition.full_key} like ? ", "%#{value}%"] if operator == :contains
48
- return [" #{condition.full_key} not like ? ", "%#{value}%"] if operator == :does_not_contain
49
- return [" #{condition.full_key} like ? ", "#{value}%"] if operator == :starts_with
50
- return [" #{condition.full_key} like ? ", "%#{value}"] if operator == :ends_with
45
+ sanitized_value = value.to_s.downcase
46
+ return [" lower(#{condition.full_key}) = ? ", sanitized_value] if operator == :is
47
+ return [" lower(#{condition.full_key}) <> ? ", sanitized_value] if operator == :is_not
48
+ return [" lower(#{condition.full_key}) like ? ", "%#{sanitized_value}%"] if operator == :contains
49
+ return [" lower(#{condition.full_key}) not like ? ", "%#{sanitized_value}%"] if operator == :does_not_contain
50
+ return [" lower(#{condition.full_key}) like ? ", "#{sanitized_value}%"] if operator == :starts_with
51
+ return [" lower(#{condition.full_key}) like ? ", "%#{sanitized_value}"] if operator == :ends_with
51
52
  end
52
53
  end
53
54
  end
@@ -33,27 +33,28 @@
33
33
  module WillFilter
34
34
  module Containers
35
35
  class TextDelimited < WillFilter::FilterContainer
36
- TEXT_DELIMITER = "," unless defined?(TEXT_DELIMITER)
37
-
36
+ TEXT_DELIMITER = "," unless defined?(TEXT_DELIMITER)
37
+
38
38
  def self.operators
39
39
  [:is_in, :is_not_in]
40
40
  end
41
-
41
+
42
42
  def template_name
43
43
  'text'
44
44
  end
45
-
45
+
46
46
  def validate
47
47
  return "Values must be provided. Separate values with '#{TEXT_DELIMITER}'" if value.blank?
48
48
  end
49
-
49
+
50
50
  def split_values
51
- value.to_s.split(TEXT_DELIMITER)
51
+ value.split(TEXT_DELIMITER)
52
52
  end
53
-
53
+
54
54
  def sql_condition
55
- return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
56
- return [" #{condition.full_key} not in (?) ", split_values] if operator == :is_not_in
55
+ sanitized_values = split_values.collect {|val| val.to_s.downcase}
56
+ return [" lower(#{condition.full_key}) in (?) ", sanitized_values] if operator == :is_in
57
+ return [" lower(#{condition.full_key}) not in (?) ", sanitized_values] if operator == :is_not_in
57
58
  end
58
59
  end
59
60
  end
@@ -31,5 +31,5 @@
31
31
  #++
32
32
 
33
33
  module WillFilter
34
- VERSION = '5.1.0'
34
+ VERSION = '5.1.1'
35
35
  end