Module: ActiveScaffold::Finder::ClassMethods::Mongoid

Defined in:
lib/active_scaffold/finder.rb

Instance Method Summary collapse

Instance Method Details

#create_conditions_for_columns(tokens, columns) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/active_scaffold/finder.rb', line 65

def create_conditions_for_columns(tokens, columns)
  conditions = tokens.map do |columns_token|
    token_conditions = columns.map do |column|
      value = columns_token[column.name]
      value = /#{value}/ if column.text?
      column.search_sql.map do |search_sql|
        # call .to_s so String is returned from CowProxy::String in threadsafe mode
        # in other case, or method from Mongoid would fail
        {search_sql.to_s => value}
      end
    end.flatten
    active_scaffold_config.model.or(token_conditions).selector
  end
  [active_scaffold_config.model.and(conditions).selector]
end

#like_pattern(text_search) ⇒ Object


81
82
83
84
85
86
87
88
# File 'lib/active_scaffold/finder.rb', line 81

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