Module: Ultracache::Macro::ClassMethods

Defined in:
lib/ultracache/macro.rb

Instance Method Summary collapse

Instance Method Details

#cached_queue_in(another, options = {}, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ultracache/macro.rb', line 6

def cached_queue_in(another, options={}, &block)
  name = options[:as] ? options[:as] : self.to_s.underscore
  relationship = BelongsAsCachedQueue.new name, block, :self_class => self,
    :need_update => options[:need_update], :unless => options[:unless],
    :associated_class => another

  self.relationships(:strict => true).add(relationship)
end

#has_cached_attribute(name, options = {}, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/ultracache/macro.rb', line 26

def has_cached_attribute(name, options={}, &block)
  relationship = HasCachedAttribute.new name, block, :self_class => self,
    :serializer => options[:serializer]

  self.relationships(:strict => true).add(relationship)

  define_method name do |*options|
    read_cache(name, options.first || {})
  end
end

#has_cached_queue(another, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/ultracache/macro.rb', line 15

def has_cached_queue(another, options={})
  relationship = HasCachedQueue.new another, :self_class => self,
    :associated_class => options[:class] ? options[:class] : another

  self.relationships(:strict => true).add(relationship)

  define_method another do |*options|
    read_cache(another, options.first || {})
  end
end