Skip to content

Commit 721ca89

Browse files
committed
Merge branch '4-2-stable'
2 parents ab97103 + c270dbd commit 721ca89

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

CHANGELOG.rdoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
- Use :subform_columns option in :horizontal and :vertical show_ui too
44
- Add layout multiple support to ActionColumns, so forms can have columns
55

6+
= 4.2.3 (unreleased)
7+
- Make simplified searches on LogicalQueryParser bridge working with upstream gem, no need for my fork
8+
69
= 4.2.2
710
- Support setting form_ui_options with nil, for subforms
811
- Support saving when embedded on through singular association, as it's supported for nested too

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PATH
1010
active_scaffold (4.2.2)
1111
dartsass-sprockets (~> 3.2.0)
1212
ice_nine (~> 0.11)
13+
method_source (~> 1.1)
1314
rails (>= 7.2.0)
1415
request_store (~> 1.3)
1516

@@ -168,6 +169,7 @@ GEM
168169
net-pop
169170
net-smtp
170171
marcel (1.1.0)
172+
method_source (1.1.0)
171173
mime-types (3.7.0)
172174
logger
173175
mime-types-data (~> 3.2025, >= 3.2025.0507)

active_scaffold.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ Gem::Specification.new do |s|
2727
s.add_dependency('ice_nine', '~> 0.11') # Deep Freeze Ruby Objects
2828
s.add_dependency('rails', '>= 7.2.0')
2929
s.add_dependency('request_store', '~> 1.3')
30+
s.add_dependency('method_source', '~> 1.1')
3031
s.metadata['rubygems_mfa_required'] = 'true'
3132
end
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# frozen_string_literal: true
22

33
class ActiveScaffold::Bridges::LogicalQueryParser < ActiveScaffold::DataStructures::Bridge
4+
autoload :TokensGrammar, 'active_scaffold/bridges/logical_query_parser/tokens_grammar'
5+
autoload :KeywordQueryParser, 'active_scaffold/bridges/logical_query_parser/keyword_query_parser'
6+
47
def self.install
5-
require File.join(File.dirname(__FILE__), 'logical_query_parser/tokens_grammar')
6-
ActiveScaffold::Finder.send(:remove_const, :LOGICAL_COMPARATORS)
78
ActiveScaffold::Finder.const_set :LOGICAL_COMPARATORS, %w[all_tokens any_token logical].freeze
89
end
910
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require 'method_source'
4+
5+
class ActiveScaffold::Bridges::LogicalQueryParser
6+
class KeywordQueryParser
7+
LogicalQueryParser.singleton_methods.each do |method_name|
8+
method = LogicalQueryParser.method(method_name)
9+
define_method(method_name, &method)
10+
end
11+
12+
# Define a new method with the same source code
13+
class_eval <<-RUBY
14+
#{LogicalQueryParser.method(:search).source}
15+
RUBY
16+
17+
def initialize(operator)
18+
@operator = operator
19+
end
20+
21+
def new
22+
ActiveScaffold::Bridges::LogicalQueryParser::TokensGrammar::Parser.new(@operator)
23+
end
24+
end
25+
end

lib/active_scaffold/data_structures/column.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def search_sql
346346
end
347347

348348
def searchable?
349-
search_sql.present? || (logical_search.present? && ActiveScaffold::Finder::LOGICAL_COMPARATORS.present?)
349+
search_sql.present? || (logical_search.present? && ActiveScaffold::Finder.logical_comparators.present?)
350350
end
351351

352352
def link

lib/active_scaffold/finder.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ def self.like_operator
66
@@like_operator ||= ::ActiveRecord::Base.connection.adapter_name.in?(%w[PostgreSQL PostGIS]) ? 'ILIKE' : 'LIKE'
77
end
88

9+
def self.logical_comparators
10+
ActiveScaffold::Finder::LOGICAL_COMPARATORS if ActiveScaffold::Finder.const_defined? :LOGICAL_COMPARATORS
11+
end
12+
913
module ClassMethods
1014
def self.extended(klass)
1115
return unless klass.active_scaffold_config
@@ -231,21 +235,21 @@ def condition_for_range(column, value, like_pattern = nil)
231235
['(%<search_sql>s BETWEEN ? AND ?)', value[:from], value[:to]]
232236
elsif ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(value[:opt])
233237
["%<search_sql>s #{value[:opt]} ?", value[:from]]
234-
elsif ActiveScaffold::Finder::LOGICAL_COMPARATORS.include?(value[:opt])
238+
elsif ActiveScaffold::Finder.logical_comparators&.include?(value[:opt])
235239
operator =
236240
case value[:opt]
237241
when 'all_tokens' then 'AND'
238242
when 'any_token' then 'OR'
239243
end
240-
parser = ActiveScaffold::Bridges::LogicalQueryParser::TokensGrammar::Parser.new(operator) if operator
241-
[logical_search_condition(column, value[:from], parser)]
244+
parser = ActiveScaffold::Bridges::LogicalQueryParser::KeywordQueryParser.new(operator) if operator
245+
[logical_search_condition(column, value[:from], parser || ::LogicalQueryParser)]
242246
end
243247
end
244248

245-
def logical_search_condition(column, search, parser = nil)
249+
def logical_search_condition(column, search, parser)
246250
model = column.active_record_class
247251
subquery = alias_query_for_same_table_exists(model.all) if column.logical_search.any?(Hash)
248-
query = ::LogicalQueryParser.search(search, subquery || model, column.logical_search, parser: parser)
252+
query = parser.search(search, subquery || model, column.logical_search)
249253
if subquery
250254
model.where(same_table_exists_subquery(query))
251255
else
@@ -526,7 +530,6 @@ def condition_for_null_type(column, value, like_pattern = nil)
526530
doesnt_begin_with: 'not_?%',
527531
doesnt_end_with: 'not_%?'
528532
}.freeze
529-
LOGICAL_COMPARATORS = [].freeze
530533
NULL_COMPARATORS = %w[null not_null].freeze
531534
DATE_COMPARATORS = %w[PAST FUTURE RANGE].freeze
532535
DATE_UNITS = %w[DAYS WEEKS MONTHS YEARS].freeze

lib/active_scaffold/helpers/search_column_helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def active_scaffold_search_range_comparator_options(column, ui_options: column.o
213213
if column.search_sql.present?
214214
select_options.concat(ActiveScaffold::Finder::STRING_COMPARATORS.collect { |title, comp| [as_(title), comp] })
215215
end
216-
if ActiveScaffold::Finder::LOGICAL_COMPARATORS.present? && column.logical_search.present?
217-
select_options.concat(ActiveScaffold::Finder::LOGICAL_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] })
216+
if ActiveScaffold::Finder.logical_comparators.present? && column.logical_search.present?
217+
select_options.concat(ActiveScaffold::Finder.logical_comparators.collect { |comp| [as_(comp.downcase.to_sym), comp] })
218218
end
219219
end
220220
if column.search_sql.present?

0 commit comments

Comments
 (0)