Module: SearchFu::ClassMethods

Defined in:
lib/search_fu/model_additions.rb

Instance Method Summary collapse

Instance Method Details

#eval_text(text, *term) ⇒ Object



29
30
31
32
33
# File 'lib/search_fu/model_additions.rb', line 29

def eval_text text, *term
  op_text = replace_operator_tag_with_sql_operator(text, term.join)
  op_val_text = replace_value_tag_with_eval_text(op_text, term.join)
  class_eval op_val_text
end

#search(params = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/search_fu/model_additions.rb', line 16

def search params={}
  output = respond_to?(:search_fu_before) ? search_fu_before : where(nil)
  params.each do |k, v|
    query = search_fu_query(v[:name]).call(v[:value])
    output = output.nil? ? query : output.merge(query)
  end if params
  output
end

#search_fu(name, view_name = nil, query = nil) ⇒ Object



11
12
13
14
# File 'lib/search_fu/model_additions.rb', line 11

def search_fu name, view_name=nil, query=nil
  @search_fu_attrs ||= SearchFuAttributes.new
  @search_fu_attrs << SearchFuAttribute.new(name, view_name, query)
end

#search_fu_view_namesObject



25
26
27
# File 'lib/search_fu/model_additions.rb', line 25

def search_fu_view_names
  @search_fu_attrs.view_names
end

#where(sql, *term) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/search_fu/model_additions.rb', line 35

def where sql, *term
  if use_fu_where? sql
    op_sql = replace_operator_tag_with_sql_operator(sql, term.join)
    op_val_sql = replace_value_tag_with_sql_value(op_sql, term.join)
    super op_val_sql
  else
    super
  end
end