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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_scaffold/finder.rb', line 43

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



59
60
61
62
63
64
65
66
# File 'lib/active_scaffold/finder.rb', line 59

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