ransack 1.7.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/test.yml +120 -0
  5. data/.gitignore +3 -0
  6. data/CHANGELOG.md +463 -27
  7. data/CONTRIBUTING.md +52 -22
  8. data/Gemfile +24 -24
  9. data/README.md +453 -126
  10. data/Rakefile +6 -25
  11. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +24 -0
  12. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +79 -0
  13. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  15. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
  16. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  18. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  19. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
  20. data/lib/polyamorous/join.rb +70 -0
  21. data/lib/polyamorous/polyamorous.rb +24 -0
  22. data/lib/polyamorous/swapping_reflection_class.rb +11 -0
  23. data/lib/polyamorous/tree_node.rb +7 -0
  24. data/lib/ransack/adapters/active_record/base.rb +27 -2
  25. data/lib/ransack/adapters/active_record/context.rb +213 -139
  26. data/lib/ransack/adapters/active_record/ransack/constants.rb +70 -55
  27. data/lib/ransack/adapters/active_record/ransack/context.rb +10 -18
  28. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +42 -32
  29. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  30. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  31. data/lib/ransack/adapters/active_record.rb +11 -10
  32. data/lib/ransack/adapters.rb +45 -23
  33. data/lib/ransack/configuration.rb +107 -4
  34. data/lib/ransack/constants.rb +13 -26
  35. data/lib/ransack/context.rb +45 -33
  36. data/lib/ransack/helpers/form_builder.rb +21 -12
  37. data/lib/ransack/helpers/form_helper.rb +75 -70
  38. data/lib/ransack/locale/ar.yml +70 -0
  39. data/lib/ransack/locale/az.yml +70 -0
  40. data/lib/ransack/locale/bg.yml +70 -0
  41. data/lib/ransack/locale/ca.yml +70 -0
  42. data/lib/ransack/locale/da.yml +70 -0
  43. data/lib/ransack/locale/el.yml +70 -0
  44. data/lib/ransack/locale/es.yml +22 -22
  45. data/lib/ransack/locale/fa.yml +70 -0
  46. data/lib/ransack/locale/fi.yml +71 -0
  47. data/lib/ransack/locale/id.yml +70 -0
  48. data/lib/ransack/locale/it.yml +70 -0
  49. data/lib/ransack/locale/ja.yml +70 -0
  50. data/lib/ransack/locale/nl.yml +4 -4
  51. data/lib/ransack/locale/pt-BR.yml +70 -0
  52. data/lib/ransack/locale/ru.yml +70 -0
  53. data/lib/ransack/locale/sk.yml +70 -0
  54. data/lib/ransack/locale/tr.yml +70 -0
  55. data/lib/ransack/locale/{zh.yml → zh-CN.yml} +13 -13
  56. data/lib/ransack/locale/zh-TW.yml +70 -0
  57. data/lib/ransack/nodes/attribute.rb +5 -2
  58. data/lib/ransack/nodes/bindable.rb +18 -6
  59. data/lib/ransack/nodes/condition.rb +85 -28
  60. data/lib/ransack/nodes/grouping.rb +17 -11
  61. data/lib/ransack/nodes/sort.rb +9 -5
  62. data/lib/ransack/nodes/value.rb +74 -68
  63. data/lib/ransack/nodes.rb +1 -1
  64. data/lib/ransack/predicate.rb +17 -20
  65. data/lib/ransack/search.rb +17 -8
  66. data/lib/ransack/translate.rb +115 -115
  67. data/lib/ransack/version.rb +1 -1
  68. data/lib/ransack/visitor.rb +1 -12
  69. data/lib/ransack.rb +9 -9
  70. data/logo/ransack-h.png +0 -0
  71. data/logo/ransack-h.svg +34 -0
  72. data/logo/ransack-v.png +0 -0
  73. data/logo/ransack-v.svg +34 -0
  74. data/logo/ransack.png +0 -0
  75. data/logo/ransack.svg +21 -0
  76. data/ransack.gemspec +7 -24
  77. data/spec/console.rb +4 -0
  78. data/spec/helpers/polyamorous_helper.rb +19 -0
  79. data/spec/polyamorous/join_association_spec.rb +35 -0
  80. data/spec/polyamorous/join_dependency_spec.rb +97 -0
  81. data/spec/polyamorous/join_spec.rb +19 -0
  82. data/spec/ransack/adapters/active_record/base_spec.rb +370 -75
  83. data/spec/ransack/adapters/active_record/context_spec.rb +72 -34
  84. data/spec/ransack/configuration_spec.rb +97 -14
  85. data/spec/ransack/helpers/form_builder_spec.rb +2 -11
  86. data/spec/ransack/helpers/form_helper_spec.rb +481 -113
  87. data/spec/ransack/nodes/condition_spec.rb +24 -0
  88. data/spec/ransack/nodes/grouping_spec.rb +56 -0
  89. data/spec/ransack/predicate_spec.rb +79 -5
  90. data/spec/ransack/search_spec.rb +207 -81
  91. data/spec/spec_helper.rb +8 -0
  92. data/spec/support/schema.rb +100 -42
  93. metadata +57 -184
  94. data/.travis.yml +0 -69
  95. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  96. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -201
  97. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -215
  98. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  99. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  100. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  101. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  102. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  103. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  104. data/lib/ransack/adapters/mongoid/base.rb +0 -130
  105. data/lib/ransack/adapters/mongoid/context.rb +0 -208
  106. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  107. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  108. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  109. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  110. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  111. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  112. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  113. data/lib/ransack/adapters/mongoid.rb +0 -13
  114. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -276
  115. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  116. data/spec/mongoid/configuration_spec.rb +0 -102
  117. data/spec/mongoid/dependencies_spec.rb +0 -8
  118. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  119. data/spec/mongoid/nodes/condition_spec.rb +0 -34
  120. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  121. data/spec/mongoid/predicate_spec.rb +0 -155
  122. data/spec/mongoid/search_spec.rb +0 -446
  123. data/spec/mongoid/support/mongoid.yml +0 -6
  124. data/spec/mongoid/support/schema.rb +0 -128
  125. data/spec/mongoid/translate_spec.rb +0 -14
  126. data/spec/mongoid_spec_helper.rb +0 -59
  127. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,14 +0,0 @@
1
- module Arel
2
-
3
- module Visitors
4
-
5
- class DepthFirst < Visitor
6
-
7
- unless method_defined?(:visit_Arel_Nodes_InfixOperation)
8
- alias :visit_Arel_Nodes_InfixOperation :binary
9
- end
10
-
11
- end
12
-
13
- end
14
- end
File without changes
@@ -1,37 +0,0 @@
1
- require 'ransack/adapters/mongoid/attributes/predications'
2
- require 'ransack/adapters/mongoid/attributes/order_predications'
3
-
4
- module Ransack
5
- module Adapters
6
- module Mongoid
7
- module Attributes
8
- class Attribute < Struct.new :relation, :name
9
- # include Arel::Expressions
10
- # include Arel::Predications
11
- # include Arel::AliasPredication
12
- # include Arel::OrderPredications
13
- # include Arel::Math
14
-
15
- include ::Ransack::Adapters::Mongoid::Attributes::Predications
16
- include ::Ransack::Adapters::Mongoid::Attributes::OrderPredications
17
-
18
- ###
19
- # Create a node for lowering this attribute
20
- def lower
21
- relation.lower self
22
- end
23
- end
24
-
25
- class String < Attribute; end
26
- class Time < Attribute; end
27
- class Boolean < Attribute; end
28
- class Decimal < Attribute; end
29
- class Float < Attribute; end
30
- class Integer < Attribute; end
31
- class Undefined < Attribute; end
32
- end
33
-
34
- Attribute = Attributes::Attribute
35
- end # Attributes
36
- end
37
- end
@@ -1,17 +0,0 @@
1
- module Ransack
2
- module Adapters
3
- module Mongoid
4
- module Attributes
5
- module OrderPredications
6
- def asc
7
- { name => :asc }
8
- end
9
-
10
- def desc
11
- { name => :desc }
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,141 +0,0 @@
1
- module Ransack
2
- module Adapters
3
- module Mongoid
4
- module Attributes
5
- module Predications
6
- def not_eq(other)
7
- { name => { '$ne' => other } }.to_inquiry
8
- end
9
-
10
- def not_eq_any(others)
11
- grouping_any :not_eq, others
12
- end
13
-
14
- def not_eq_all(others)
15
- grouping_all :not_eq, others
16
- end
17
-
18
- def eq(other)
19
- { name => other }.to_inquiry
20
- end
21
-
22
- def eq_any(others)
23
- grouping_any :eq, others
24
- end
25
-
26
- def eq_all(others)
27
- grouping_all :eq, others
28
- end
29
-
30
- def in(other)
31
- { name => { "$in" => other } }.to_inquiry
32
- end
33
-
34
- def in_any(others)
35
- grouping_any :in, others
36
- end
37
-
38
- def in_all(others)
39
- grouping_all :in, others
40
- end
41
-
42
- def not_in(other)
43
- { "$not" => { name => { "$in" => other } } }.to_inquiry
44
- end
45
-
46
- def not_in_any(others)
47
- grouping_any :not_in, others
48
- end
49
-
50
- def not_in_all(others)
51
- grouping_all :not_in, others
52
- end
53
-
54
- def matches(other)
55
- { name => /#{other}/i }.to_inquiry
56
- end
57
-
58
- def matches_any(others)
59
- grouping_any :matches, others
60
- end
61
-
62
- def matches_all(others)
63
- grouping_all :matches, others
64
- end
65
-
66
- def does_not_match(other)
67
- { "$not" => { name => /#{other}/i } }.to_inquiry
68
- end
69
-
70
- def does_not_match_any(others)
71
- grouping_any :does_not_match, others
72
- end
73
-
74
- def does_not_match_all(others)
75
- grouping_all :does_not_match, others
76
- end
77
-
78
- def gteq(right)
79
- { name => { '$gte' => right } }.to_inquiry
80
- end
81
-
82
- def gteq_any(others)
83
- grouping_any :gteq, others
84
- end
85
-
86
- def gteq_all(others)
87
- grouping_all :gteq, others
88
- end
89
-
90
- def gt(right)
91
- { name => { '$gt' => right } }.to_inquiry
92
- end
93
-
94
- def gt_any(others)
95
- grouping_any :gt, others
96
- end
97
-
98
- def gt_all(others)
99
- grouping_all :gt, others
100
- end
101
-
102
- def lt(right)
103
- { name => { '$lt' => right } }.to_inquiry
104
- end
105
-
106
- def lt_any(others)
107
- grouping_any :lt, others
108
- end
109
-
110
- def lt_all(others)
111
- grouping_all :lt, others
112
- end
113
-
114
- def lteq(right)
115
- { name => { '$lte' => right } }.to_inquiry
116
- end
117
-
118
- def lteq_any(others)
119
- grouping_any :lteq, others
120
- end
121
-
122
- def lteq_all(others)
123
- grouping_all :lteq, others
124
- end
125
-
126
- private
127
-
128
- def grouping_any(method_id, others)
129
- nodes = others.map { |e| send(method_id, e) }
130
- { "$or" => nodes }.to_inquiry
131
- end
132
-
133
- def grouping_all(method_id, others)
134
- nodes = others.map { |e| send(method_id, e) }
135
- { "$and" => nodes }.to_inquiry
136
- end
137
- end
138
- end
139
- end
140
- end
141
- end
@@ -1,130 +0,0 @@
1
- require 'delegate'
2
-
3
- module Ransack
4
- module Adapters
5
- module Mongoid
6
- module Base
7
-
8
- extend ActiveSupport::Concern
9
-
10
- included do
11
- end
12
-
13
- class ColumnWrapper < SimpleDelegator
14
- def type
15
- _super = super
16
- case _super
17
- when BSON::ObjectId, Object
18
- :string
19
- else
20
- _super.name.underscore.to_sym
21
- end
22
- end
23
- end
24
-
25
- class Connection
26
- def initialize model
27
- @model = model
28
- end
29
-
30
- def quote_column_name name
31
- name
32
- end
33
- end
34
-
35
- module ClassMethods
36
- def _ransackers
37
- @_ransackers ||= {}
38
- end
39
-
40
- def _ransackers=(value)
41
- @_ransackers = value
42
- end
43
-
44
- def ransack(params = {}, options = {})
45
- params = params.presence || {}
46
- Search.new(self, params ? params.delete_if {
47
- |k, v| v.blank? && v != false } : params, options)
48
- end
49
-
50
- alias_method :search, :ransack
51
-
52
- def ransacker(name, opts = {}, &block)
53
- self._ransackers = _ransackers.merge name.to_s => Ransacker
54
- .new(self, name, opts, &block)
55
- end
56
-
57
- def all_ransackable_attributes
58
- ['id'] + column_names.select { |c| c != '_id' } + _ransackers.keys
59
- end
60
-
61
- def ransackable_attributes(auth_object = nil)
62
- all_ransackable_attributes
63
- end
64
-
65
- def ransortable_attributes(auth_object = nil)
66
- # Here so users can overwrite the attributes
67
- # that show up in the sort_select
68
- ransackable_attributes(auth_object)
69
- end
70
-
71
- def ransackable_associations(auth_object = nil)
72
- reflect_on_all_associations_all.map { |a| a.name.to_s }
73
- end
74
-
75
- def reflect_on_all_associations_all
76
- reflect_on_all_associations(:belongs_to, :has_one, :has_many, :embeds_many, :embedded_in)
77
- end
78
-
79
- # For overriding with a whitelist of symbols
80
- def ransackable_scopes(auth_object = nil)
81
- []
82
- end
83
-
84
- # imitating active record
85
-
86
- def joins_values *args
87
- []
88
- end
89
-
90
- def custom_join_ast *args
91
- []
92
- end
93
-
94
- def first(*args)
95
- if args.size == 0
96
- super
97
- else
98
- self.criteria.limit(args.first)
99
- end
100
- end
101
-
102
- # def group_by *args, &block
103
- # criteria
104
- # end
105
-
106
- def columns
107
- @columns ||= fields.map(&:second).map{ |c| ColumnWrapper.new(c) }
108
- end
109
-
110
- def column_names
111
- @column_names ||= fields.map(&:first)
112
- end
113
-
114
- def columns_hash
115
- columns.index_by(&:name)
116
- end
117
-
118
- def table
119
- name = ::Ransack::Adapters::Mongoid::Attributes::Attribute.new(self.criteria, :name)
120
- {
121
- :name => name
122
- }
123
- end
124
-
125
- end
126
-
127
- end # Base
128
- end
129
- end
130
- end
@@ -1,208 +0,0 @@
1
- require 'ransack/context'
2
- require 'polyamorous'
3
-
4
- module Ransack
5
- module Adapters
6
- module Mongoid
7
- class Context < ::Ransack::Context
8
-
9
- # Because the AR::Associations namespace is insane
10
- # JoinDependency = ::Mongoid::Associations::JoinDependency
11
- # JoinPart = JoinDependency::JoinPart
12
-
13
- def initialize(object, options = {})
14
- super
15
- # @arel_visitor = @engine.connection.visitor
16
- end
17
-
18
- def relation_for(object)
19
- object.all
20
- end
21
-
22
- def type_for(attr)
23
- return nil unless attr && attr.valid?
24
- name = attr.arel_attribute.name.to_s.split('.').last
25
- # table = attr.arel_attribute.relation.table_name
26
-
27
- # schema_cache = @engine.connection.schema_cache
28
- # raise "No table named #{table} exists" unless schema_cache.table_exists?(table)
29
- # schema_cache.columns_hash(table)[name].type
30
-
31
- # when :date
32
- # when :datetime, :timestamp, :time
33
- # when :boolean
34
- # when :integer
35
- # when :float
36
- # when :decimal
37
- # else # :string
38
-
39
- name = '_id' if name == 'id'
40
-
41
- t = object.klass.fields[name].try(:type) || @bind_pairs[attr.name].first.fields[name].type
42
-
43
- t.to_s.demodulize.underscore.to_sym
44
- end
45
-
46
- def evaluate(search, opts = {})
47
- viz = Visitor.new
48
- relation = @object.where(viz.accept(search.base))
49
- if search.sorts.any?
50
- ary_sorting = viz.accept(search.sorts)
51
- sorting = {}
52
- ary_sorting.each do |s|
53
- sorting.merge! Hash[s.map { |k, d| [k.to_s == 'id' ? '_id' : k, d] }]
54
- end
55
- relation = relation.order_by(sorting)
56
- # relation = relation.except(:order)
57
- # .reorder(viz.accept(search.sorts))
58
- end
59
- # -- mongoid has different distinct method
60
- # opts[:distinct] ? relation.distinct : relation
61
- relation
62
- end
63
-
64
- def attribute_method?(str, klass = @klass)
65
- exists = false
66
- if ransackable_attribute?(str, klass)
67
- exists = true
68
- elsif (segments = str.split(/_/)).size > 1
69
- remainder = []
70
- found_assoc = nil
71
- while !found_assoc && remainder.unshift(
72
- segments.pop) && segments.size > 0 do
73
- assoc, poly_class = unpolymorphize_association(
74
- segments.join('_')
75
- )
76
- if found_assoc = get_association(assoc, klass)
77
- exists = attribute_method?(remainder.join('_'),
78
- poly_class || found_assoc.klass
79
- )
80
- end
81
- end
82
- end
83
- exists
84
- end
85
-
86
- def table_for(parent)
87
- # parent.table
88
- Ransack::Adapters::Mongoid::Table.new(parent)
89
- end
90
-
91
- def klassify(obj)
92
- if Class === obj && obj.ancestors.include?(::Mongoid::Document)
93
- obj
94
- elsif obj.respond_to? :klass
95
- obj.klass
96
- elsif obj.respond_to? :base_klass
97
- obj.base_klass
98
- else
99
- raise ArgumentError, "Don't know how to klassify #{obj}"
100
- end
101
- end
102
-
103
- private
104
-
105
- def get_parent_and_attribute_name(str, parent = @base)
106
- attr_name = nil
107
-
108
- if ransackable_attribute?(str, klassify(parent))
109
- attr_name = str
110
- elsif (segments = str.split(/_/)).size > 1
111
- remainder = []
112
- found_assoc = nil
113
- while remainder.unshift(
114
- segments.pop) && segments.size > 0 && !found_assoc do
115
- assoc, klass = unpolymorphize_association(segments.join('_'))
116
- if found_assoc = get_association(assoc, parent)
117
- parent, attr_name = get_parent_and_attribute_name(
118
- remainder.join('_'), found_assoc.klass
119
- )
120
- attr_name = "#{segments.join('_')}.#{attr_name}"
121
- end
122
- end
123
- end
124
-
125
- [parent, attr_name]
126
- end
127
-
128
- def get_association(str, parent = @base)
129
- klass = klassify parent
130
- ransackable_association?(str, klass) &&
131
- klass.reflect_on_all_associations_all.detect { |a| a.name.to_s == str }
132
- end
133
-
134
- def join_dependency(relation)
135
- if relation.respond_to?(:join_dependency) # Squeel will enable this
136
- relation.join_dependency
137
- else
138
- build_join_dependency(relation)
139
- end
140
- end
141
-
142
- # Checkout active_record/relation/query_methods.rb +build_joins+ for
143
- # reference. Lots of duplicated code maybe we can avoid it
144
- def build_join_dependency(relation)
145
- buckets = relation.joins_values.group_by do |join|
146
- case join
147
- when String
148
- Constants::STRING_JOIN
149
- when Hash, Symbol, Array
150
- Constants::ASSOCIATION_JOIN
151
- when JoinDependency, JoinDependency::JoinAssociation
152
- Constants::STASHED_JOIN
153
- when Arel::Nodes::Join
154
- Constants::JOIN_NODE
155
- else
156
- raise 'unknown class: %s' % join.class.name
157
- end
158
- end
159
-
160
- association_joins = buckets[Constants::ASSOCIATION_JOIN] || []
161
-
162
- stashed_association_joins = buckets[Constants::STASHED_JOIN] || []
163
-
164
- join_nodes = buckets[Constants::JOIN_NODE] || []
165
-
166
- string_joins = (buckets[Constants::STRING_JOIN] || [])
167
- .map { |x| x.strip }
168
- .uniq
169
-
170
- join_list = relation.send :custom_join_ast,
171
- relation.table.from(relation.table), string_joins
172
-
173
- join_dependency = JoinDependency.new(
174
- relation.klass, association_joins, join_list
175
- )
176
-
177
- join_nodes.each do |join|
178
- join_dependency.alias_tracker.aliases[join.left.name.downcase] = 1
179
- end
180
-
181
- join_dependency # ActiveRecord::Associations::JoinDependency
182
- end
183
-
184
- # ActiveRecord method
185
- def build_or_find_association(name, parent = @base, klass = nil)
186
- found_association = @join_dependency.join_associations
187
- .detect do |assoc|
188
- assoc.reflection.name == name &&
189
- assoc.parent == parent &&
190
- (!klass || assoc.reflection.klass == klass)
191
- end
192
- unless found_association
193
- @join_dependency.send(
194
- :build,
195
- Polyamorous::Join.new(name, @join_type, klass),
196
- parent
197
- )
198
- found_association = @join_dependency.join_associations.last
199
- # Leverage the stashed association functionality in AR
200
- @object = @object.joins(found_association)
201
- end
202
- found_association
203
- end
204
-
205
- end
206
- end
207
- end
208
- end
@@ -1,23 +0,0 @@
1
- module Ransack
2
- module Adapters
3
- module Mongoid
4
- class InquiryHash < Hash
5
-
6
- def or(other)
7
- { '$or' => [ self, other] }.to_inquiry
8
- end
9
-
10
- def and(other)
11
- { '$and' => [ self, other] }.to_inquiry
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
18
-
19
- class Hash
20
- def to_inquiry
21
- ::Ransack::Adapters::Mongoid::InquiryHash[self]
22
- end
23
- end
@@ -1,88 +0,0 @@
1
- module Ransack
2
- module Constants
3
- DERIVED_PREDICATES = [
4
- [CONT, {
5
- :arel_predicate => 'matches',
6
- :formatter => proc { |v| "#{escape_regex(v)}" }
7
- }
8
- ],
9
- ['not_cont', {
10
- :arel_predicate => 'does_not_match',
11
- :formatter => proc { |v| "#{escape_regex(v)}" }
12
- }
13
- ],
14
- ['start', {
15
- :arel_predicate => 'matches',
16
- :formatter => proc { |v| "\\A#{escape_regex(v)}" }
17
- }
18
- ],
19
- ['not_start', {
20
- :arel_predicate => 'does_not_match',
21
- :formatter => proc { |v| "\\A#{escape_regex(v)}" }
22
- }
23
- ],
24
- ['end', {
25
- :arel_predicate => 'matches',
26
- :formatter => proc { |v| "#{escape_regex(v)}\\Z" }
27
- }
28
- ],
29
- ['not_end', {
30
- :arel_predicate => 'does_not_match',
31
- :formatter => proc { |v| "#{escape_regex(v)}\\Z" }
32
- }
33
- ],
34
- ['true', {
35
- :arel_predicate => 'eq',
36
- :compounds => false,
37
- :type => :boolean,
38
- :validator => proc { |v| TRUE_VALUES.include?(v) }
39
- }
40
- ],
41
- ['false', {
42
- :arel_predicate => 'eq',
43
- :compounds => false,
44
- :type => :boolean,
45
- :validator => proc { |v| TRUE_VALUES.include?(v) },
46
- :formatter => proc { |v| !v }
47
- }
48
- ],
49
- ['present', {
50
- :arel_predicate => proc { |v| v ? 'not_eq_all' : 'eq_any' },
51
- :compounds => false,
52
- :type => :boolean,
53
- :validator => proc { |v| BOOLEAN_VALUES.include?(v) },
54
- :formatter => proc { |v| [nil, ''] }
55
- }
56
- ],
57
- ['blank', {
58
- :arel_predicate => proc { |v| v ? 'eq_any' : 'not_eq_all' },
59
- :compounds => false,
60
- :type => :boolean,
61
- :validator => proc { |v| BOOLEAN_VALUES.include?(v) },
62
- :formatter => proc { |v| [nil, ''] }
63
- }
64
- ],
65
- ['null', {
66
- :arel_predicate => proc { |v| v ? 'eq' : 'not_eq' },
67
- :compounds => false,
68
- :type => :boolean,
69
- :validator => proc { |v| BOOLEAN_VALUES.include?(v)},
70
- :formatter => proc { |v| nil }
71
- }
72
- ],
73
- ['not_null', {
74
- :arel_predicate => proc { |v| v ? 'not_eq' : 'eq' },
75
- :compounds => false,
76
- :type => :boolean,
77
- :validator => proc { |v| BOOLEAN_VALUES.include?(v) },
78
- :formatter => proc { |v| nil } }
79
- ]
80
- ]
81
-
82
- module_function
83
- # does nothing
84
- def escape_regex(unescaped)
85
- Regexp.escape(unescaped)
86
- end
87
- end
88
- end