Module: CacheBack::ConfigurationMixin

Defined in:
lib/cache_back/configuration_mixin.rb

Instance Method Summary collapse

Instance Method Details

#cache_back_indicesObject



22
23
24
25
26
# File 'lib/cache_back/configuration_mixin.rb', line 22

def cache_back_indices
  result = @cache_back_indices || []
  result += superclass.cache_back_indices unless self == ActiveRecord::Base
  result.uniq
end

#cache_back_key_for(attribute_value_pairs) ⇒ Object



14
15
16
# File 'lib/cache_back/configuration_mixin.rb', line 14

def cache_back_key_for(attribute_value_pairs)
  cache_back_key_prefix + attribute_value_pairs.map {|attribute, value| attribute.to_s + '=' + value.to_s}.join('/')
end

#cache_back_key_for_id(id) ⇒ Object



18
19
20
# File 'lib/cache_back/configuration_mixin.rb', line 18

def cache_back_key_for_id(id)
  cache_back_key_for([['id', id]])
end

#cache_back_key_prefixObject



10
11
12
# File 'lib/cache_back/configuration_mixin.rb', line 10

def cache_back_key_prefix
  @cache_back_key_prefix ||= "cache_back/#{table_name}/version=#{Zlib.crc32(column_names.sort.join)}/"
end

#has_cache_back(options = {}) ⇒ Object



32
33
34
# File 'lib/cache_back/configuration_mixin.rb', line 32

def has_cache_back(options = {})
  has_cache_back_on :id
end

#has_cache_back_index_on?(sorted_attributes) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cache_back/configuration_mixin.rb', line 28

def has_cache_back_index_on?(sorted_attributes)
  cache_back_indices.include?(sorted_attributes)
end

#has_cache_back_on(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cache_back/configuration_mixin.rb', line 36

def has_cache_back_on(*args)
  attributes = args.sort! { |x, y| x.to_s <=> y.to_s }
  if attributes != [:id] && !cache_back_indices.include?([:id])
    has_cache_back_on(:id)
  end

  @cache_back_indices ||= []
  @cache_back_indices << attributes unless @cache_back_indices.include?(attributes)

  include WriteMixin unless instance_methods.include?('store_in_cache_back')
  extend ReadMixin unless methods.include?('without_cache_back')
  extend DirtyMixin unless methods.include?('cache_back_dirty_methods')
end