ransack 2.4.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql.yml +72 -0
  3. data/.github/workflows/cronjob.yml +6 -9
  4. data/.github/workflows/deploy.yml +35 -0
  5. data/.github/workflows/rubocop.yml +1 -1
  6. data/.github/workflows/test-deploy.yml +29 -0
  7. data/.github/workflows/test.yml +22 -48
  8. data/.nojekyll +0 -0
  9. data/.rubocop.yml +3 -0
  10. data/CHANGELOG.md +208 -11
  11. data/CONTRIBUTING.md +41 -18
  12. data/Gemfile +10 -10
  13. data/README.md +44 -977
  14. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +4 -0
  15. data/docs/.gitignore +19 -0
  16. data/docs/.nojekyll +0 -0
  17. data/docs/babel.config.js +3 -0
  18. data/docs/blog/2022-03-27-ransack-3.0.0.md +20 -0
  19. data/docs/docs/getting-started/_category_.json +4 -0
  20. data/docs/docs/getting-started/advanced-mode.md +46 -0
  21. data/docs/docs/getting-started/configuration.md +47 -0
  22. data/docs/docs/getting-started/search-matches.md +67 -0
  23. data/docs/docs/getting-started/simple-mode.md +288 -0
  24. data/docs/docs/getting-started/sorting.md +79 -0
  25. data/docs/docs/getting-started/using-predicates.md +282 -0
  26. data/docs/docs/going-further/_category_.json +4 -0
  27. data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
  28. data/docs/docs/going-further/associations.md +70 -0
  29. data/docs/docs/going-further/custom-predicates.md +52 -0
  30. data/docs/docs/going-further/documentation.md +43 -0
  31. data/docs/docs/going-further/exporting-to-csv.md +49 -0
  32. data/docs/docs/going-further/external-guides.md +57 -0
  33. data/docs/docs/going-further/form-customisation.md +63 -0
  34. data/docs/docs/going-further/i18n.md +53 -0
  35. data/docs/docs/going-further/merging-searches.md +41 -0
  36. data/docs/docs/going-further/other-notes.md +428 -0
  37. data/docs/docs/going-further/polymorphic-search.md +40 -0
  38. data/docs/docs/going-further/ransackers.md +331 -0
  39. data/docs/docs/going-further/release_process.md +36 -0
  40. data/docs/docs/going-further/saving-queries.md +82 -0
  41. data/docs/docs/going-further/searching-postgres.md +57 -0
  42. data/docs/docs/going-further/wiki-contributors.md +82 -0
  43. data/docs/docs/intro.md +99 -0
  44. data/docs/docusaurus.config.js +120 -0
  45. data/docs/package.json +42 -0
  46. data/docs/sidebars.js +31 -0
  47. data/docs/src/components/HomepageFeatures/index.js +64 -0
  48. data/docs/src/components/HomepageFeatures/styles.module.css +11 -0
  49. data/docs/src/css/custom.css +39 -0
  50. data/docs/src/pages/index.module.css +23 -0
  51. data/docs/src/pages/markdown-page.md +7 -0
  52. data/docs/static/.nojekyll +0 -0
  53. data/docs/static/img/docusaurus.png +0 -0
  54. data/docs/static/img/favicon.ico +0 -0
  55. data/docs/static/img/logo.svg +1 -0
  56. data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
  57. data/docs/static/img/tutorial/localeDropdown.png +0 -0
  58. data/docs/static/img/undraw_docusaurus_mountain.svg +171 -0
  59. data/docs/static/img/undraw_docusaurus_react.svg +170 -0
  60. data/docs/static/img/undraw_docusaurus_tree.svg +40 -0
  61. data/docs/yarn.lock +8790 -0
  62. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
  63. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
  64. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -1
  65. data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
  66. data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
  67. data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
  68. data/lib/ransack/adapters/active_record/base.rb +79 -10
  69. data/lib/ransack/adapters/active_record/context.rb +24 -51
  70. data/lib/ransack/configuration.rb +39 -12
  71. data/lib/ransack/constants.rb +125 -3
  72. data/lib/ransack/context.rb +34 -5
  73. data/lib/ransack/helpers/form_builder.rb +3 -3
  74. data/lib/ransack/helpers/form_helper.rb +14 -5
  75. data/lib/ransack/locale/sv.yml +70 -0
  76. data/lib/ransack/nodes/attribute.rb +2 -2
  77. data/lib/ransack/nodes/condition.rb +80 -7
  78. data/lib/ransack/nodes/grouping.rb +3 -3
  79. data/lib/ransack/nodes/node.rb +1 -1
  80. data/lib/ransack/nodes/sort.rb +2 -2
  81. data/lib/ransack/nodes/value.rb +2 -2
  82. data/lib/ransack/predicate.rb +1 -1
  83. data/lib/ransack/ransacker.rb +1 -1
  84. data/lib/ransack/search.rb +13 -7
  85. data/lib/ransack/translate.rb +3 -3
  86. data/lib/ransack/version.rb +1 -1
  87. data/lib/ransack/visitor.rb +38 -2
  88. data/lib/ransack.rb +3 -6
  89. data/ransack.gemspec +5 -5
  90. data/spec/helpers/polyamorous_helper.rb +2 -8
  91. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  92. data/spec/polyamorous/join_association_spec.rb +1 -6
  93. data/spec/polyamorous/join_dependency_spec.rb +0 -16
  94. data/spec/ransack/adapters/active_record/base_spec.rb +101 -11
  95. data/spec/ransack/configuration_spec.rb +23 -9
  96. data/spec/ransack/helpers/form_builder_spec.rb +8 -8
  97. data/spec/ransack/helpers/form_helper_spec.rb +93 -4
  98. data/spec/ransack/nodes/condition_spec.rb +37 -0
  99. data/spec/ransack/nodes/value_spec.rb +115 -0
  100. data/spec/ransack/predicate_spec.rb +36 -1
  101. data/spec/ransack/search_spec.rb +140 -27
  102. data/spec/ransack/translate_spec.rb +1 -1
  103. data/spec/support/schema.rb +75 -9
  104. metadata +83 -37
  105. data/docs/release_process.md +0 -20
  106. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
  107. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
  108. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
  109. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -1
  110. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -80
  111. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -1
  112. data/lib/ransack/adapters/active_record/ransack/constants.rb +0 -128
  113. data/lib/ransack/adapters/active_record/ransack/context.rb +0 -56
  114. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +0 -68
  115. data/lib/ransack/adapters/active_record/ransack/translate.rb +0 -8
  116. data/lib/ransack/adapters/active_record/ransack/visitor.rb +0 -47
  117. data/lib/ransack/adapters.rb +0 -64
  118. data/lib/ransack/nodes.rb +0 -8
  119. /data/docs/{img → docs/going-further/img}/create_release.png +0 -0
  120. /data/{logo → docs/static/logo}/ransack-h.png +0 -0
  121. /data/{logo → docs/static/logo}/ransack-h.svg +0 -0
  122. /data/{logo → docs/static/logo}/ransack-v.png +0 -0
  123. /data/{logo → docs/static/logo}/ransack-v.svg +0 -0
  124. /data/{logo → docs/static/logo}/ransack.png +0 -0
  125. /data/{logo → docs/static/logo}/ransack.svg +0 -0
  126. /data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_association.rb +0 -0
  127. /data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_dependency.rb +0 -0
  128. /data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/reflection.rb +0 -0
  129. /data/lib/ransack/{adapters/active_record.rb → active_record.rb} +0 -0
@@ -1,68 +0,0 @@
1
- module Ransack
2
- module Nodes
3
- class Condition
4
-
5
- def arel_predicate
6
- attributes.map { |attribute|
7
- association = attribute.parent
8
- if negative? && attribute.associated_collection?
9
- query = context.build_correlated_subquery(association)
10
- context.remove_association(association)
11
- if self.predicate_name == 'not_null' && self.value
12
- query.where(format_predicate(attribute))
13
- Arel::Nodes::In.new(context.primary_key, Arel.sql(query.to_sql))
14
- else
15
- query.where(format_predicate(attribute).not)
16
- Arel::Nodes::NotIn.new(context.primary_key, Arel.sql(query.to_sql))
17
- end
18
- else
19
- format_predicate(attribute)
20
- end
21
- }.reduce(combinator_method)
22
- end
23
-
24
- private
25
-
26
- def combinator_method
27
- combinator === Constants::OR ? :or : :and
28
- end
29
-
30
- def format_predicate(attribute)
31
- arel_pred = arel_predicate_for_attribute(attribute)
32
- arel_values = formatted_values_for_attribute(attribute)
33
- predicate = attr_value_for_attribute(attribute).public_send(arel_pred, arel_values)
34
-
35
- if in_predicate?(predicate)
36
- predicate.right = predicate.right.map do |pr|
37
- casted_array?(pr) ? format_values_for(pr) : pr
38
- end
39
- end
40
-
41
- predicate
42
- end
43
-
44
- def in_predicate?(predicate)
45
- return unless defined?(Arel::Nodes::Casted)
46
- predicate.class == Arel::Nodes::In || predicate.class == Arel::Nodes::NotIn
47
- end
48
-
49
- def casted_array?(predicate)
50
- (predicate.respond_to?(:value) && predicate.value.is_a?(Array)) || # Rails 6.1
51
- (predicate.respond_to?(:val) && predicate.val.is_a?(Array)) # Rails 5.2, 6.0
52
- end
53
-
54
- def format_values_for(predicate)
55
- value = if predicate.respond_to?(:value)
56
- predicate.value # Rails 6.1
57
- else
58
- predicate.val # Rails 5.2, 6.0
59
- end
60
-
61
- value.map do |val|
62
- val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
63
- end
64
- end
65
-
66
- end
67
- end
68
- end
@@ -1,8 +0,0 @@
1
- module Ransack
2
- module Translate
3
-
4
- def self.i18n_key(klass)
5
- klass.model_name.i18n_key
6
- end
7
- end
8
- end
@@ -1,47 +0,0 @@
1
- module Ransack
2
- class Visitor
3
- def visit_and(object)
4
- nodes = object.values.map { |o| accept(o) }.compact
5
- return nil unless nodes.size > 0
6
-
7
- if nodes.size > 1
8
- Arel::Nodes::Grouping.new(Arel::Nodes::And.new(nodes))
9
- else
10
- nodes.first
11
- end
12
- end
13
-
14
- def quoted?(object)
15
- case object
16
- when Arel::Nodes::SqlLiteral, Bignum, Fixnum
17
- false
18
- else
19
- true
20
- end
21
- end
22
-
23
- def visit_Ransack_Nodes_Sort(object)
24
- if object.valid?
25
- if object.attr.is_a?(Arel::Attributes::Attribute)
26
- object.attr.send(object.dir)
27
- else
28
- ordered(object)
29
- end
30
- else
31
- scope_name = :"sort_by_#{object.name}_#{object.dir}"
32
- scope_name if object.context.object.respond_to?(scope_name)
33
- end
34
- end
35
-
36
- private
37
-
38
- def ordered(object)
39
- case object.dir
40
- when 'asc'.freeze
41
- Arel::Nodes::Ascending.new(object.attr)
42
- when 'desc'.freeze
43
- Arel::Nodes::Descending.new(object.attr)
44
- end
45
- end
46
- end
47
- end
@@ -1,64 +0,0 @@
1
- module Ransack
2
- module Adapters
3
-
4
- def self.object_mapper
5
- @object_mapper ||= instantiate_object_mapper
6
- end
7
-
8
- def self.instantiate_object_mapper
9
- if defined?(::ActiveRecord::Base)
10
- ActiveRecordAdapter.new
11
- elsif defined?(::Mongoid)
12
- MongoidAdapter.new
13
- else
14
- raise "Unsupported adapter"
15
- end
16
- end
17
-
18
- class ActiveRecordAdapter
19
- def require_constants
20
- require 'ransack/adapters/active_record/ransack/constants'
21
- end
22
-
23
- def require_adapter
24
- require 'ransack/adapters/active_record/ransack/translate'
25
- require 'ransack/adapters/active_record'
26
- end
27
-
28
- def require_context
29
- require 'ransack/adapters/active_record/ransack/visitor'
30
- end
31
-
32
- def require_nodes
33
- require 'ransack/adapters/active_record/ransack/nodes/condition'
34
- end
35
-
36
- def require_search
37
- require 'ransack/adapters/active_record/ransack/context'
38
- end
39
- end
40
-
41
- class MongoidAdapter
42
- def require_constants
43
- require 'ransack/adapters/mongoid/ransack/constants'
44
- end
45
-
46
- def require_adapter
47
- require 'ransack/adapters/mongoid/ransack/translate'
48
- require 'ransack/adapters/mongoid'
49
- end
50
-
51
- def require_context
52
- require 'ransack/adapters/mongoid/ransack/visitor'
53
- end
54
-
55
- def require_nodes
56
- require 'ransack/adapters/mongoid/ransack/nodes/condition'
57
- end
58
-
59
- def require_search
60
- require 'ransack/adapters/mongoid/ransack/context'
61
- end
62
- end
63
- end
64
- end
data/lib/ransack/nodes.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'ransack/nodes/bindable'
2
- require 'ransack/nodes/node'
3
- require 'ransack/nodes/attribute'
4
- require 'ransack/nodes/value'
5
- require 'ransack/nodes/condition'
6
- Ransack::Adapters.object_mapper.require_nodes
7
- require 'ransack/nodes/sort'
8
- require 'ransack/nodes/grouping'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes