module RecordSelect::Conditions

Protected Instance Methods

record_select_condition_for_column(column, value) click to toggle source

generates an SQL condition for the given column/value

# File lib/record_select/conditions.rb, line 85
def record_select_condition_for_column(column, value)
  if value.blank? and column.null
    "#{column.name} IS NULL"
  elsif column.text?
    ["LOWER(#{column.name}) LIKE ?", value]
  else
    ["#{column.name} = ?", column.type_cast(value)]
  end
end
record_select_conditions() click to toggle source

returns the combination of all conditions. conditions come from:

  • current search (params)

  • intelligent url params (e.g. params if first_name is a model column)

  • specific conditions supplied by the developer

# File lib/record_select/conditions.rb, line 9
def record_select_conditions
  conditions = []

  merge_conditions(
    record_select_conditions_from_search,
    record_select_conditions_from_params,
    record_select_conditions_from_controller
  )
end
record_select_conditions_from_controller() click to toggle source

an override method. here you can provide custom conditions to define the selectable records. useful for situational restrictions.

# File lib/record_select/conditions.rb, line 21
def record_select_conditions_from_controller; end
record_select_conditions_from_params() click to toggle source

generate conditions from the url parameters (e.g. users/browse?group_id=5)

# File lib/record_select/conditions.rb, line 72
def record_select_conditions_from_params
  conditions = nil
  params.each do |field, value|
    next unless column = record_select_config.model.columns_hash[field]
    conditions = merge_conditions(
      conditions,
      record_select_condition_for_column(column, value)
    )
  end
  conditions
end
record_select_includes() click to toggle source

another override method. define any association includes you want for the finder search.

# File lib/record_select/conditions.rb, line 25
def record_select_includes; end
record_select_like_operator() click to toggle source
# File lib/record_select/conditions.rb, line 27
def record_select_like_operator
  @like_operator ||= ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
end
record_select_select() click to toggle source

define special list of selected fields, mainly to define extra fields that can be used for specialized sorting.

# File lib/record_select/conditions.rb, line 34
def record_select_select; end