Class: Memcacheable::FetchBelongsTo

Inherits:
FetchAssociation show all
Defined in:
lib/memcacheable/fetch_belongs_to.rb

Instance Attribute Summary

Attributes inherited from FetchAssociation

#association, #object

Instance Method Summary collapse

Methods inherited from FetchAssociation

#cache_key, #class_name, #description, #initialize

Methods inherited from Fetcher

#debug, #fetch, #flush

Constructor Details

This class inherits a constructor from Memcacheable::FetchAssociation

Instance Method Details

#fetchable?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/memcacheable/fetch_belongs_to.rb', line 3

def fetchable?
  klass.respond_to?(:fetch)
end

#find_on_cache_missObject



7
8
9
10
# File 'lib/memcacheable/fetch_belongs_to.rb', line 7

def find_on_cache_miss
  id = object.send "#{association}_id"
  fetchable? ? klass.fetch(id) : object.send(association) rescue nil
end

#klassObject



12
13
14
# File 'lib/memcacheable/fetch_belongs_to.rb', line 12

def klass
  @klass ||= association.to_s.camelize.constantize
end