class RailsAdmin::AbstractModel::StatementBuilder
Public Class Methods
new(column, type, value, operator)
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 135 def initialize(column, type, value, operator) @column = column @type = type @value = value @operator = operator end
Public Instance Methods
to_statement()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 142 def to_statement return if [@operator, @value].any? { |v| v == '_discard' } unary_operators[@operator] || unary_operators[@value] || build_statement_for_type_generic end
Protected Instance Methods
build_statement_for_date()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 191 def build_statement_for_date start_date, end_date = get_filtering_duration if start_date start_date = begin start_date.to_date rescue StandardError nil end end if end_date end_date = begin end_date.to_date rescue StandardError nil end end range_filter(start_date, end_date) end
build_statement_for_datetime_or_timestamp()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 210 def build_statement_for_datetime_or_timestamp start_date, end_date = get_filtering_duration start_date = start_date.beginning_of_day if start_date.is_a?(Date) end_date = end_date.end_of_day if end_date.is_a?(Date) range_filter(start_date, end_date) end
build_statement_for_integer_decimal_or_float()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 170 def build_statement_for_integer_decimal_or_float case @value when Array val, range_begin, range_end = *@value.collect do |v| next unless v.to_i.to_s == v || v.to_f.to_s == v @type == :integer ? v.to_i : v.to_f end case @operator when 'between' range_filter(range_begin, range_end) else column_for_value(val) if val end else if @value.to_i.to_s == @value || @value.to_f.to_s == @value @type == :integer ? column_for_value(@value.to_i) : column_for_value(@value.to_f) end end end
build_statement_for_type()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 166 def build_statement_for_type raise 'You must override build_statement_for_type in your StatementBuilder' end
build_statement_for_type_generic()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 155 def build_statement_for_type_generic build_statement_for_type || begin case @type when :date build_statement_for_date when :datetime, :timestamp, :time build_statement_for_datetime_or_timestamp end end end
get_filtering_duration()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 151 def get_filtering_duration FilteringDuration.new(@operator, @value).get_duration end
range_filter(_min, _max)
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 221 def range_filter(_min, _max) raise 'You must override range_filter in your StatementBuilder' end
unary_operators()
click to toggle source
# File lib/rails_admin/abstract_model.rb, line 217 def unary_operators raise 'You must override unary_operators in your StatementBuilder' end