Module: ActiveScaffold::Finder::ClassMethods::ActiveRecord

Defined in:
lib/active_scaffold/finder.rb

Instance Method Summary collapse

Instance Method Details

#create_conditions_for_columns(tokens, columns) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_scaffold/finder.rb', line 38

def create_conditions_for_columns(tokens, columns)
  where_clauses = []
  columns.each do |column|
    column.search_sql.each do |search_sql|
      where_clauses << "#{search_sql} #{column.text? ? ActiveScaffold::Finder.like_operator : '='} ?"
    end
  end
  phrase = where_clauses.join(' OR ')

  tokens.map do |columns_token|
    columns.each_with_object([phrase]) do |column, condition|
      condition.concat([columns_token[column.name]] * column.search_sql.size)
    end
  end
end

#like_pattern(text_search) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/active_scaffold/finder.rb', line 54

def like_pattern(text_search)
  case text_search
  when :full then '%?%'
  when :start then '?%'
  when :end then '%?'
  else '?'
  end
end