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_for_active_model(attr, query) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_model_cachers/cache_service_factory.rb', line 15

def create_for_active_model(attr, query)
  cache_key = get_cache_key(attr)

  klass = @key_class_mapping[cache_key] ||= ->{
    klass = Class.new(CacheService)
    klass.cache_key = cache_key
    klass.query_mapping = {}
    klass.instance_variable_set(:@callbacks_defined, false) # to remove warning: instance variable @callbacks_defined not initialized
    next klass
  }[]

  klass.query_mapping[attr.reflect] = query
  return klass
end

.has_cacher?(attr) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.set_klass_to_mapping(attr, current_klass) ⇒ Object



30
31
32
33
34
35
# File 'lib/active_model_cachers/cache_service_factory.rb', line 30

def set_klass_to_mapping(attr, current_klass)
  cache_key = get_cache_key(attr)
  changed = clean_klass_cache_if_reloaded!(cache_key, current_klass, attr)
  @cache_key_klass_mapping[cache_key] = current_klass
  return changed
end