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
- #cache_expire ⇒ Object
- #cacheable? ⇒ Boolean
- #get_cache_key(options) ⇒ Object
- #get_items(options) ⇒ Object
- #get_model_cache_key(options) ⇒ Object
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_expire ⇒ Object
41 42 43 |
# File 'lib/autocompl/base.rb', line 41 def cache_expire Rails.application.config.autocomplete_cache_expire end |
#cacheable? ⇒ 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() ClassMethods::BASE_CACHE_KEY + ':' + get_model_cache_key() end |
#get_items(options) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/autocompl/base.rb', line 27 def get_items() klasses = .keys items = [] for klass in klasses columns = [klass].instance_of?(Array) ? [klass] : [] << [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() klasses = .keys cache_key = '' klasses.each_with_index do |klass, index| cache_key.concat('_and_') if index > 0 cache_key.concat(klass.to_s) columns = [klass].instance_of?(Array) ? [klass] : [] << [klass] for column in columns cache_key.concat('_' + column.to_s) end end cache_key end |