Class: ActiveModelCachers::CacheServiceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model_cachers/cache_service_factory.rb

Class Method Summary collapse

Class Method Details

.create(cache_key, query) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/active_model_cachers/cache_service_factory.rb', line 20

def create(cache_key, query)
  @key_class_mapping[cache_key] ||= ->{
    klass = Class.new(CacheService)
    klass.cache_key = cache_key
    klass.query = query
    next klass
  }[]
end

.create_for_active_model(attr, query) ⇒ Object


14
15
16
17
18
# File 'lib/active_model_cachers/cache_service_factory.rb', line 14

def create_for_active_model(attr, query)
  cache_key = get_cache_key(attr)
  service_klass = create(cache_key, query)
  return service_klass
end

.has_cacher?(attr) ⇒ Boolean

Returns:

  • (Boolean)

10
11
12
# File 'lib/active_model_cachers/cache_service_factory.rb', line 10

def has_cacher?(attr)
  return (@key_class_mapping[get_cache_key(attr)] != nil)
end