Module: Redrecord::Model::ClassMethods

Defined in:
lib/redrecord.rb

Instance Method Summary collapse

Instance Method Details

#invalidate_cache_on(fieldname) ⇒ Object



56
57
58
# File 'lib/redrecord.rb', line 56

def invalidate_cache_on(fieldname)
  redrecord_invalidation_fields << fieldname.to_sym 
end

#redis_cache(*fields, &bl) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/redrecord.rb', line 40

def redis_cache(*fields, &bl)
  if block_given?
    old_methods = instance_methods
    class_eval(&bl)
    fields.push(*(instance_methods - old_methods))
  end
  redrecord_cached_fields.push(*fields)
  fields.each do |f|
    aliased_target, punctuation = f.to_s.sub(/([?!=])$/, ''), $1
    define_method("#{aliased_target}_with_cache#{punctuation}") do
      cached_method(f)
    end
    alias_method_chain f, :cache
  end
end

#redrecord_cached_fieldsObject



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

def redrecord_cached_fields
  @redrecord_cached_fields ||= []
end

#redrecord_invalidation_fieldsObject



36
37
38
# File 'lib/redrecord.rb', line 36

def redrecord_invalidation_fields
  @redrecord_invalidation_fields ||= []
end