ransack 1.7.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.travis.yml +16 -48
  4. data/CHANGELOG.md +409 -26
  5. data/CONTRIBUTING.md +48 -20
  6. data/Gemfile +9 -13
  7. data/README.md +352 -92
  8. data/Rakefile +6 -25
  9. data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +2 -0
  10. data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +2 -0
  11. data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +32 -0
  12. data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +112 -0
  13. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +32 -0
  14. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +113 -0
  15. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +31 -0
  16. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +57 -0
  17. data/lib/polyamorous/join.rb +70 -0
  18. data/lib/polyamorous/swapping_reflection_class.rb +11 -0
  19. data/lib/polyamorous/tree_node.rb +7 -0
  20. data/lib/polyamorous.rb +25 -0
  21. data/lib/ransack/adapters/active_record/base.rb +23 -2
  22. data/lib/ransack/adapters/active_record/context.rb +210 -135
  23. data/lib/ransack/adapters/active_record/ransack/constants.rb +53 -53
  24. data/lib/ransack/adapters/active_record/ransack/context.rb +11 -15
  25. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +33 -30
  26. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  27. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  28. data/lib/ransack/adapters/active_record.rb +11 -10
  29. data/lib/ransack/adapters.rb +45 -23
  30. data/lib/ransack/configuration.rb +91 -4
  31. data/lib/ransack/constants.rb +14 -26
  32. data/lib/ransack/context.rb +29 -18
  33. data/lib/ransack/helpers/form_builder.rb +27 -12
  34. data/lib/ransack/helpers/form_helper.rb +75 -70
  35. data/lib/ransack/locale/ar.yml +70 -0
  36. data/lib/ransack/locale/az.yml +70 -0
  37. data/lib/ransack/locale/bg.yml +70 -0
  38. data/lib/ransack/locale/da.yml +70 -0
  39. data/lib/ransack/locale/el.yml +70 -0
  40. data/lib/ransack/locale/id.yml +70 -0
  41. data/lib/ransack/locale/it.yml +70 -0
  42. data/lib/ransack/locale/ja.yml +70 -0
  43. data/lib/ransack/locale/nl.yml +4 -4
  44. data/lib/ransack/locale/pt-BR.yml +70 -0
  45. data/lib/ransack/locale/ru.yml +70 -0
  46. data/lib/ransack/locale/tr.yml +70 -0
  47. data/lib/ransack/locale/{zh.yml → zh-CN.yml} +13 -13
  48. data/lib/ransack/locale/zh-TW.yml +70 -0
  49. data/lib/ransack/nodes/attribute.rb +5 -2
  50. data/lib/ransack/nodes/bindable.rb +18 -6
  51. data/lib/ransack/nodes/condition.rb +77 -28
  52. data/lib/ransack/nodes/grouping.rb +16 -10
  53. data/lib/ransack/nodes/sort.rb +9 -5
  54. data/lib/ransack/nodes/value.rb +74 -68
  55. data/lib/ransack/nodes.rb +1 -1
  56. data/lib/ransack/predicate.rb +15 -19
  57. data/lib/ransack/search.rb +14 -7
  58. data/lib/ransack/translate.rb +3 -3
  59. data/lib/ransack/version.rb +1 -1
  60. data/lib/ransack/visitor.rb +1 -12
  61. data/lib/ransack.rb +7 -7
  62. data/logo/ransack-h.png +0 -0
  63. data/logo/ransack-h.svg +34 -0
  64. data/logo/ransack-v.png +0 -0
  65. data/logo/ransack-v.svg +34 -0
  66. data/logo/ransack.png +0 -0
  67. data/logo/ransack.svg +21 -0
  68. data/ransack.gemspec +9 -10
  69. data/spec/console.rb +4 -0
  70. data/spec/helpers/polyamorous_helper.rb +24 -0
  71. data/spec/ransack/adapters/active_record/base_spec.rb +365 -74
  72. data/spec/ransack/adapters/active_record/context_spec.rb +14 -19
  73. data/spec/ransack/configuration_spec.rb +87 -14
  74. data/spec/ransack/helpers/form_builder_spec.rb +2 -11
  75. data/spec/ransack/helpers/form_helper_spec.rb +481 -113
  76. data/spec/ransack/join_association_spec.rb +28 -0
  77. data/spec/ransack/join_dependency_spec.rb +86 -0
  78. data/spec/ransack/join_spec.rb +19 -0
  79. data/spec/ransack/nodes/condition_spec.rb +24 -0
  80. data/spec/ransack/nodes/grouping_spec.rb +56 -0
  81. data/spec/ransack/predicate_spec.rb +27 -5
  82. data/spec/ransack/search_spec.rb +84 -70
  83. data/spec/spec_helper.rb +4 -0
  84. data/spec/support/schema.rb +86 -41
  85. metadata +60 -81
  86. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  87. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -201
  88. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -215
  89. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  90. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  91. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  92. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  93. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  94. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  95. data/lib/ransack/adapters/mongoid/base.rb +0 -130
  96. data/lib/ransack/adapters/mongoid/context.rb +0 -208
  97. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  98. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  99. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  100. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  101. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  102. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  103. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  104. data/lib/ransack/adapters/mongoid.rb +0 -13
  105. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -276
  106. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  107. data/spec/mongoid/configuration_spec.rb +0 -102
  108. data/spec/mongoid/dependencies_spec.rb +0 -8
  109. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  110. data/spec/mongoid/nodes/condition_spec.rb +0 -34
  111. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  112. data/spec/mongoid/predicate_spec.rb +0 -155
  113. data/spec/mongoid/search_spec.rb +0 -446
  114. data/spec/mongoid/support/mongoid.yml +0 -6
  115. data/spec/mongoid/support/schema.rb +0 -128
  116. data/spec/mongoid/translate_spec.rb +0 -14
  117. data/spec/mongoid_spec_helper.rb +0 -59
  118. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -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
@@ -1,60 +0,0 @@
1
- require 'ransack/visitor'
2
-
3
- module Ransack
4
- class Context
5
- # attr_reader :arel_visitor
6
-
7
- class << self
8
-
9
- def for_class(klass, options = {})
10
- if klass.ancestors.include?(::Mongoid::Document)
11
- Adapters::Mongoid::Context.new(klass, options)
12
- end
13
- end
14
-
15
- def for_object(object, options = {})
16
- case object
17
- when ActiveRecord::Relation
18
- Adapters::ActiveRecord::Context.new(object.klass, options)
19
- end
20
- end
21
-
22
- end # << self
23
-
24
- def initialize(object, options = {})
25
- @object = relation_for(object)
26
- @klass = @object.klass
27
- # @join_dependency = join_dependency(@object)
28
- # @join_type = options[:join_type] || Arel::OuterJoin
29
- @search_key = options[:search_key] || Ransack.options[:search_key]
30
-
31
- @base = @object.klass
32
- # @engine = @base.arel_engine
33
-
34
- # @default_table = Arel::Table.new(
35
- # @base.table_name, :as => @base.aliased_table_name, :engine => @engine
36
- # )
37
- @bind_pairs = Hash.new do |hash, key|
38
- parent, attr_name = get_parent_and_attribute_name(key.to_s)
39
- if parent && attr_name
40
- hash[key] = [parent, attr_name]
41
- end
42
- end
43
- end
44
-
45
- def klassify(obj)
46
- if Class === obj && ::ActiveRecord::Base > obj
47
- obj
48
- elsif obj.respond_to? :klass
49
- obj.klass
50
- elsif obj.respond_to? :active_record # Rails 3
51
- obj.active_record
52
- elsif obj.respond_to? :base_klass # Rails 4
53
- obj.base_klass
54
- else
55
- raise ArgumentError, "Don't know how to klassify #{obj.inspect}"
56
- end
57
- end
58
-
59
- end
60
- end
@@ -1,27 +0,0 @@
1
- module Ransack
2
- module Nodes
3
- class Condition
4
-
5
- def arel_predicate
6
- predicates = attributes.map do |attr|
7
- attr.attr.send(
8
- arel_predicate_for_attribute(attr),
9
- formatted_values_for_attribute(attr)
10
- )
11
- end
12
-
13
- if predicates.size > 1
14
- case combinator
15
- when 'and'
16
- Arel::Nodes::Grouping.new(Arel::Nodes::And.new(predicates))
17
- when 'or'
18
- predicates.inject(&:or)
19
- end
20
- else
21
- predicates.first
22
- end
23
- end
24
-
25
- end # Condition
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- module Ransack
2
- module Translate
3
-
4
- def self.i18n_key(klass)
5
- # if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
6
- # klass.model_name.i18n_key.to_s.tr('.', '/')
7
- # else
8
- # klass.model_name.i18n_key.to_s
9
- # end
10
- klass.model_name.i18n_key.to_s
11
- end
12
- end
13
- end