class RailsAdmin::Adapters::Mongoid::StatementBuilder

Protected Instance Methods

unary_operators() click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 230
def unary_operators
  {
    '_blank' => {@column => {'$in' => [nil, '']}},
    '_present' => {@column => {'$nin' => [nil, '']}},
    '_null' => {@column => nil},
    '_not_null' => {@column => {'$ne' => nil}},
    '_empty' => {@column => ''},
    '_not_empty' => {@column => {'$ne' => ''}},
  }
end

Private Instance Methods

build_statement_for_belongs_to_association_or_bson_object_id() click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 294
def build_statement_for_belongs_to_association_or_bson_object_id
  {@column => @value} if @value
end
build_statement_for_boolean() click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 253
def build_statement_for_boolean
  case @value
  when 'false', 'f', '0'
    {@column => false}
  when 'true', 't', '1'
    {@column => true}
  end
end
build_statement_for_enum() click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 288
def build_statement_for_enum
  return if @value.blank?

  {@column => {'$in' => Array.wrap(@value)}}
end
build_statement_for_string_or_text() click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 266
def build_statement_for_string_or_text
  return if @value.blank?

  @value =
    case @operator
    when 'not_like'
      Regexp.compile("^((?!#{Regexp.escape(@value)}).)*$", Regexp::IGNORECASE)
    when 'default', 'like'
      Regexp.compile(Regexp.escape(@value), Regexp::IGNORECASE)
    when 'starts_with'
      Regexp.compile("^#{Regexp.escape(@value)}", Regexp::IGNORECASE)
    when 'ends_with'
      Regexp.compile("#{Regexp.escape(@value)}$", Regexp::IGNORECASE)
    when 'is', '='
      @value.to_s
    else
      return
    end

  {@column => @value}
end
build_statement_for_type() click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 243
def build_statement_for_type
  case @type
  when :boolean                   then build_statement_for_boolean
  when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
  when :string, :text             then build_statement_for_string_or_text
  when :enum                      then build_statement_for_enum
  when :belongs_to_association, :bson_object_id then build_statement_for_belongs_to_association_or_bson_object_id
  end
end
column_for_value(value) click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 262
def column_for_value(value)
  {@column => value}
end
range_filter(min, max) click to toggle source
# File lib/rails_admin/adapters/mongoid.rb, line 298
def range_filter(min, max)
  if min && max && min == max
    {@column => min}
  elsif min && max
    {@column => {'$gte' => min, '$lte' => max}}
  elsif min
    {@column => {'$gte' => min}}
  elsif max
    {@column => {'$lte' => max}}
  end
end