Class: IronAdmin::Filters::BaseQueryBuilder
- Inherits:
-
Object
- Object
- IronAdmin::Filters::BaseQueryBuilder
- Defined in:
- lib/iron_admin/filters/base_query_builder.rb
Overview
Abstract base class for operator-based filter query builders.
Subclasses implement the adapter-specific query building for string and number filter operators. ActiveRecord uses SQL LIKE/ILIKE, Mongoid uses $regex and comparison operators.
Direct Known Subclasses
ActiveRecordQueryBuilder, HttpQueryBuilder, MongoidQueryBuilder
Constant Summary collapse
- STRING_OPS =
%w[contains equals starts_with ends_with].freeze
- NUMBER_OPS =
%w[equals greater_than less_than between].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(scope, filter, params_hash) ⇒ BaseQueryBuilder
constructor
A new instance of BaseQueryBuilder.
Constructor Details
#initialize(scope, filter, params_hash) ⇒ BaseQueryBuilder
Returns a new instance of BaseQueryBuilder.
18 19 20 21 22 23 24 |
# File 'lib/iron_admin/filters/base_query_builder.rb', line 18 def initialize(scope, filter, params_hash) @scope = scope @filter = filter @op = params_hash["op"].to_s @value = params_hash["value"].to_s.strip @upper_value = params_hash["value_2"].to_s.strip end |
Class Method Details
.call(scope, filter, params_hash) ⇒ Object
14 15 16 |
# File 'lib/iron_admin/filters/base_query_builder.rb', line 14 def self.call(scope, filter, params_hash) new(scope, filter, params_hash).call end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/iron_admin/filters/base_query_builder.rb', line 26 def call return @scope if @value.blank? case @filter[:type] when :string then apply_string_filter when :number then apply_number_filter else @scope end end |