Module: Autosuggest::Helpers

Included in:
ActionController::Base
Defined in:
lib/autosuggest/helpers.rb

Instance Method Summary collapse

Instance Method Details

#db_store(object) ⇒ Object

Decipher what database implementation the model is using

db_store(:ingredient)
# returns ActiveRecord assuming Ingredient is an AR model


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/autosuggest/helpers.rb', line 44

def db_store(object)
  ancestors = objectify(object).ancestors.map(&:to_s)
  if ancestors.include?('ActiveRecord::Base')
    ActiveRecord
  elsif ancestors.include?('Mongoid::Document')
    Mongoid
  elsif ancestors.include?('MongoMapper::Document')
    MongoMapper
  else
    raise 'Database Store not supported'
  end
end

#objectify(object_sym) ⇒ Object

Returns parameter object_sym as a constant

objectify(:ingredient)
# returns a Ingredient constant supposing it is already defined


36
37
38
# File 'lib/autosuggest/helpers.rb', line 36

def objectify(object_sym)
  object_sym.to_s.camelize.constantize
end

#resolve_like_clauseObject



57
58
59
# File 'lib/autosuggest/helpers.rb', line 57

def resolve_like_clause
  defined?(PGconn) ? 'ILIKE' : 'LIKE'
end