Merb::Cache::CacheMixin::ClassMethods

Public Instance Methods

build_request(path, params = {}, env = {}) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 66
def build_request(path, params = {}, env = {})
  path, params, env = nil, path, params if path.is_a? Hash

  Merb::Cache::CacheRequest.new(path, params, env)
end
build_url(*args) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 72
def build_url(*args)
  Merb::Router.url(*args)
end
cache(*actions) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 12
def cache(*actions)
  if actions.last.is_a? Hash
    cache_action(*actions)
  else
    actions.each {|a| cache_action(*a)}
  end
end
cache!(conditions = {}) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 7
def cache!(conditions = {})
  before(:_cache_before, conditions.only(:if, :unless).merge(:with => conditions))
  after(:_cache_after, conditions.only(:if, :unless).merge(:with => conditions))
end
cache_action(action, conditions = {}) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 20
def cache_action(action, conditions = {})
  before("_cache_#{action}_before", conditions.only(:if, :unless).merge(:with => [conditions], :only => action))
  after("_cache_#{action}_after", conditions.only(:if, :unless).merge(:with => [conditions], :only => action))
  alias_method "_cache_#{action}_before", :_cache_before
  alias_method "_cache_#{action}_after",  :_cache_after
end
eager_cache(trigger_action, target = trigger_action, conditions = {}, &blk) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 27
def eager_cache(trigger_action, target = trigger_action, conditions = {}, &blk)
  target, conditions = trigger_action, target if target.is_a? Hash

  if target.is_a? Array
    target_controller, target_action = *target
  else
    target_controller, target_action = self, target
  end

  after("_eager_cache_#{trigger_action}_to_#{target_controller.name.snake_case}__#{target_action}_after", conditions.only(:if, :unless).merge(:with => [target_controller, target_action, conditions, blk], :only => trigger_action))
  alias_method "_eager_cache_#{trigger_action}_to_#{target_controller.name.snake_case}__#{target_action}_after", :_eager_cache_after
end
eager_dispatch(action, params = {}, env = {}, blk = nil) click to toggle source
# File lib/merb-cache/merb_ext/controller.rb, line 40
def eager_dispatch(action, params = {}, env = {}, blk = nil)
  kontroller = if blk.nil?
    new(Merb::Request.new(env))
  else
    result = case blk.arity
      when 0  then  blk[]
      when 1  then  blk[params]
      else          blk[*[params, env]]
    end

    case result
    when NilClass         then new(Merb::Request.new(env))
    when Hash, Mash       then new(Merb::Request.new(result))
    when Merb::Request    then new(result)
    when Merb::Controller then result
    else raise ArgumentError, "Block to eager_cache must return nil, the env Hash, a Request object, or a Controller object"
    end
  end

  kontroller.force_cache!

  kontroller._dispatch(action)

  kontroller
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.