refine-rails 2.13.8 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52fd39463e007be7957c4402ac0f1843fdb5012e6dafde1d7c14f15a54b1788a
4
- data.tar.gz: 2de904d1ed64b3183e4c9a2a0a3824495e76e745a24462d08500eb635091dbf8
3
+ metadata.gz: fcaec6a16a7f77268e6af7578a103cd32e51581ff47620a807c8041c41a30f9a
4
+ data.tar.gz: 61346cac343a3e2f434577d68620a62c40ea78d8f43626ba5a29d603901d27c1
5
5
  SHA512:
6
- metadata.gz: 6619108c19f61b0fbf54b488ef0bc9111d009d596b4597d98a03d7647cc1ad1edeb6b817cb544c2bdc60437b4740c237760271088d42b87a4586a8d7e83f1963
7
- data.tar.gz: '08dfb1cb2d1c3a81deb0290b1172b904f1b95529a7ac3dce901f5040f1f6ea74940297f5339be3423f026f8f55bb2d44ef552b2de5371d88ef46ca1248b4301a'
6
+ metadata.gz: fb8afe7f33ae5d300427183fd4d3735bb357666fc01629cf8e6b487bb3c3ea99eb4e257da928612f4276b9b213a536086b53a5845a6323e18d762a7c5206d820
7
+ data.tar.gz: d46eb10e4469431bf3fe4ec603755a84064da55127e4256cb6d2eb5a716730d7f04b603a99cb4b8a854fd5d4a4da18ef72b8b727fe3f9ea80db4761e33017db9
@@ -6,7 +6,6 @@ module Refine
6
6
  include Stabilize
7
7
  include Internationalized
8
8
  include Inspector
9
- include FlatQueryTools
10
9
  # This validation structure sents `initial_query` as the method to validate against
11
10
  define_model_callbacks :initialize, only: [:after]
12
11
  after_initialize :valid?
@@ -92,10 +91,10 @@ module Refine
92
91
 
93
92
  def get_query
94
93
  raise "Initial query must exist" if initial_query.nil?
95
- if blueprint.present?
96
- @relation.where(group(make_sub_query(blueprint)))
94
+ if self.class.included_modules.include?(Refine::FlatQueryTools) && can_use_flat_query?
95
+ get_flat_query
97
96
  else
98
- @relation
97
+ get_complex_query
99
98
  end
100
99
  end
101
100
 
@@ -105,6 +104,14 @@ module Refine
105
104
  result
106
105
  end
107
106
 
107
+ def get_complex_query
108
+ if blueprint.present?
109
+ @relation.where(group(make_sub_query(blueprint)))
110
+ else
111
+ @relation
112
+ end
113
+ end
114
+
108
115
  def add_nodes_to_query(subquery:, nodes:, query_method:)
109
116
  # Apply existing nodes to existing subquery
110
117
  if subquery.present? && nodes.present?
@@ -213,6 +220,7 @@ module Refine
213
220
 
214
221
  def apply_condition(criterion)
215
222
  begin
223
+ condition = get_condition_for_criterion(criterion)
216
224
  get_condition_for_criterion(criterion)&.apply(criterion[:input], table, initial_query, false, nil)
217
225
  rescue Refine::Conditions::Errors::ConditionClauseError => e
218
226
  e.errors.each do |error|
@@ -47,7 +47,16 @@ module Refine
47
47
  else
48
48
  unless condition_already_applied?(criteria_or_conjunction)
49
49
  node = apply_flat_condition(criteria_or_conjunction)
50
- @relation = @relation.where(Arel.sql(node.to_sql))
50
+ if node.is_a?(Arel::Nodes::Grouping)
51
+ @relation = @relation.where(node)
52
+ elsif node.is_a?(Array)
53
+ error = node.filter{ |n| n.is_a?(ActiveModel::Error) }.first
54
+ if error
55
+ filter.errors.add(:base, error.full_message)
56
+ end
57
+ else
58
+ @relation = @relation.where(Arel::Nodes::Grouping.new(node))
59
+ end
51
60
  track_condition_applied(criteria_or_conjunction)
52
61
  end
53
62
  end
@@ -84,7 +93,6 @@ module Refine
84
93
  end
85
94
  join_count += 1
86
95
  end
87
-
88
96
  end
89
97
  end
90
98
 
@@ -100,5 +108,10 @@ module Refine
100
108
  applied_conditions[criterion[:condition_id]] &&
101
109
  applied_conditions[criterion[:condition_id]].include?(criterion[:input])
102
110
  end
111
+
112
+ # Meant to be overridden by Filter classes to add or replace with custom logic
113
+ def can_use_flat_query?
114
+ !uses_or? && !uses_negative_clause? && !has_duplicate_conditions?
115
+ end
103
116
  end
104
117
  end
@@ -1,5 +1,5 @@
1
1
  module Refine
2
2
  module Rails
3
- VERSION = "2.13.8"
3
+ VERSION = "2.14.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refine-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.8
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colleen Schnettler
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-03-28 00:00:00.000000000 Z
12
+ date: 2025-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails