Module: Autocompl::Base

Included in:
ActionController::Base
Defined in:
lib/autocompl/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(target) ⇒ Object



5
6
7
8
# File 'lib/autocompl/base.rb', line 5

def self.included(target)
  target.extend Autocompl::Base::ClassMethods
  target.send :include, Autocompl::Repository
end

Instance Method Details

#cache_expireObject



41
42
43
# File 'lib/autocompl/base.rb', line 41

def cache_expire
  Rails.application.config.autocomplete_cache_expire
end

#cacheable?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/autocompl/base.rb', line 37

def cacheable?
  Rails.application.config.cache_store.present? && Rails.application.config.cache_autocomplete
end

#get_cache_key(options) ⇒ Object



45
46
47
# File 'lib/autocompl/base.rb', line 45

def get_cache_key(options)
  ClassMethods::BASE_CACHE_KEY + ':' + get_model_cache_key(options)
end

#get_items(options) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/autocompl/base.rb', line 27

def get_items(options)
  klasses = options.keys
  items = []
  for klass in klasses
    columns = options[klass].instance_of?(Array) ? options[klass] : [] << options[klass]
    items.concat(get_collection(klass, columns))
  end
  items
end

#get_model_cache_key(options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/autocompl/base.rb', line 49

def get_model_cache_key(options)
  klasses = options.keys
  cache_key = ''
  klasses.each_with_index do |klass, index|
    cache_key.concat('_and_') if index > 0
    cache_key.concat(klass.to_s)
    columns = options[klass].instance_of?(Array) ? options[klass] : [] << options[klass]
    for column in columns
      cache_key.concat('_' + column.to_s)
    end
  end
  cache_key
end