ransack 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql.yml +72 -0
  3. data/.github/workflows/test.yml +22 -27
  4. data/.rubocop.yml +3 -0
  5. data/CHANGELOG.md +79 -0
  6. data/CONTRIBUTING.md +38 -16
  7. data/Gemfile +10 -10
  8. data/README.md +8 -13
  9. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +4 -0
  10. data/docs/docs/getting-started/advanced-mode.md +1 -1
  11. data/docs/docs/getting-started/search-matches.md +1 -1
  12. data/docs/docs/getting-started/simple-mode.md +30 -26
  13. data/docs/docs/getting-started/sorting.md +1 -1
  14. data/docs/docs/going-further/acts-as-taggable-on.md +10 -10
  15. data/docs/docs/going-further/exporting-to-csv.md +2 -2
  16. data/docs/docs/going-further/form-customisation.md +1 -1
  17. data/docs/docs/going-further/i18n.md +3 -3
  18. data/docs/docs/going-further/other-notes.md +1 -1
  19. data/docs/docs/going-further/saving-queries.md +1 -1
  20. data/docs/docs/going-further/searching-postgres.md +1 -1
  21. data/docs/docs/intro.md +2 -2
  22. data/docs/docusaurus.config.js +14 -1
  23. data/docs/package.json +7 -2
  24. data/docs/yarn.lock +3036 -1917
  25. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -1
  26. data/lib/ransack/adapters/active_record/base.rb +78 -7
  27. data/lib/ransack/adapters/active_record/context.rb +17 -49
  28. data/lib/ransack/configuration.rb +25 -12
  29. data/lib/ransack/constants.rb +125 -3
  30. data/lib/ransack/context.rb +34 -5
  31. data/lib/ransack/helpers/form_builder.rb +3 -3
  32. data/lib/ransack/helpers/form_helper.rb +4 -3
  33. data/lib/ransack/nodes/attribute.rb +2 -2
  34. data/lib/ransack/nodes/condition.rb +80 -7
  35. data/lib/ransack/nodes/grouping.rb +3 -3
  36. data/lib/ransack/nodes/node.rb +1 -1
  37. data/lib/ransack/nodes/value.rb +2 -2
  38. data/lib/ransack/predicate.rb +1 -1
  39. data/lib/ransack/ransacker.rb +1 -1
  40. data/lib/ransack/search.rb +9 -4
  41. data/lib/ransack/translate.rb +2 -2
  42. data/lib/ransack/version.rb +1 -1
  43. data/lib/ransack/visitor.rb +38 -2
  44. data/lib/ransack.rb +3 -6
  45. data/ransack.gemspec +2 -2
  46. data/spec/helpers/polyamorous_helper.rb +2 -8
  47. data/spec/ransack/adapters/active_record/base_spec.rb +73 -0
  48. data/spec/ransack/configuration_spec.rb +9 -9
  49. data/spec/ransack/helpers/form_builder_spec.rb +8 -8
  50. data/spec/ransack/helpers/form_helper_spec.rb +48 -2
  51. data/spec/ransack/nodes/condition_spec.rb +24 -0
  52. data/spec/ransack/nodes/value_spec.rb +115 -0
  53. data/spec/ransack/predicate_spec.rb +36 -1
  54. data/spec/ransack/translate_spec.rb +1 -1
  55. data/spec/support/schema.rb +27 -10
  56. metadata +11 -19
  57. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -20
  58. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -79
  59. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -11
  60. data/lib/polyamorous.rb +0 -1
  61. data/lib/ransack/adapters/active_record/ransack/constants.rb +0 -128
  62. data/lib/ransack/adapters/active_record/ransack/context.rb +0 -56
  63. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +0 -69
  64. data/lib/ransack/adapters/active_record/ransack/translate.rb +0 -8
  65. data/lib/ransack/adapters/active_record/ransack/visitor.rb +0 -47
  66. data/lib/ransack/adapters.rb +0 -64
  67. data/lib/ransack/nodes.rb +0 -8
  68. /data/lib/ransack/{adapters/active_record.rb → active_record.rb} +0 -0
@@ -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'