Module: WhereLower::ActiveRecordExtension::ClassMethods

Defined in:
lib/where_lower/active_record_extension.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#where_lower(fields) ⇒ Object

A bit like ‘where`, but only accept hash, with value of `String`, `Array`, `Range`

Examples:

Find user by username case insensitively

User.where_lower(username: param[:name])

Find user by alias case insensitively

User.join(:aliases).where_lower(aliases:{name: param[:name]})

Parameters:

  • fields (Hash)

    the conditions in hash, values will be downcase It could also be a 1 level deep hash so that it can be used in join

Raises:

  • (ArgumentError)

    when fields is not a Hash



28
29
30
31
32
# File 'lib/where_lower/active_record_extension.rb', line 28

def where_lower(fields)
  fail AugumentError, "fields is not a Hash" unless fields.is_a?(Hash)

  WhereLower::Base.spawn_lower_scope(self, fields)
end