Module: Autocompl::Base
- Included in:
- ActionController::Base
- Defined in:
- lib/autocompl/base.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- BASE_CACHE_KEY =
'autocomplete_cache'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #cache_expire ⇒ Object
- #cacheable? ⇒ Boolean
- #get_cache_key(options) ⇒ Object
- #get_items(options, params) ⇒ Object
- #get_limit(params) ⇒ Object
- #get_model_cache_key(options) ⇒ Object
Class Method Details
.included(target) ⇒ Object
7 8 9 10 |
# File 'lib/autocompl/base.rb', line 7 def self.included(target) target.extend Autocompl::Base::ClassMethods target.send :include, Autocompl::Repository end |
Instance Method Details
#cache_expire ⇒ Object
45 46 47 |
# File 'lib/autocompl/base.rb', line 45 def cache_expire Rails.application.config.autocomplete_cache_expire end |
#cacheable? ⇒ Boolean
41 42 43 |
# File 'lib/autocompl/base.rb', line 41 def cacheable? Rails.application.config.cache_store.present? && Rails.application.config.cache_autocomplete end |
#get_cache_key(options) ⇒ Object
49 50 51 |
# File 'lib/autocompl/base.rb', line 49 def get_cache_key() BASE_CACHE_KEY + ':' + get_model_cache_key() end |
#get_items(options, params) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/autocompl/base.rb', line 27 def get_items(, params) klasses = .keys items = [] for klass in klasses columns = [klass].instance_of?(Array) ? [klass] : [] << [klass] items.concat(get_collection(klass, columns, term: params[:term], limit: get_limit(params))) end items end |
#get_limit(params) ⇒ Object
37 38 39 |
# File 'lib/autocompl/base.rb', line 37 def get_limit(params) params[:limit] ||= 20 end |
#get_model_cache_key(options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/autocompl/base.rb', line 53 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 |