Module: WCC::Contentful::ActiveRecordShim

Extended by:
ActiveSupport::Concern
Defined in:
lib/wcc/contentful/active_record_shim.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



6
7
8
# File 'lib/wcc/contentful/active_record_shim.rb', line 6

def attributes
  @attributes ||= to_h['fields'].tap { |fields| fields['id'] = id }
end

#cache_keyObject



10
11
12
13
14
# File 'lib/wcc/contentful/active_record_shim.rb', line 10

def cache_key
  return cache_key_with_version unless ActiveRecord::Base.try(:cache_versioning) == true

  "#{self.class.model_name}/#{id}"
end

#cache_key_with_versionObject



16
17
18
# File 'lib/wcc/contentful/active_record_shim.rb', line 16

def cache_key_with_version
  "#{cache_key_without_version}-#{cache_version}"
end

#cache_key_without_versionObject



20
21
22
# File 'lib/wcc/contentful/active_record_shim.rb', line 20

def cache_key_without_version
  "#{self.class.model_name}/#{id}"
end

#cache_versionObject



24
25
26
# File 'lib/wcc/contentful/active_record_shim.rb', line 24

def cache_version
  sys.revision.to_s
end