Sha256: 593de919d1b0a19b91d04dc6d2a3fb31fd4f39ddf9d52dbed687e966d6b47fce

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Catche
  module Controller
    module Base

      extend ActiveSupport::Concern

      module ClassMethods

        # Caches a controller action by tagging it.
        # Supports any option parameters caches_action supports.
        #
        #   catche Project, :index
        #   catche Task, :through => :project
        def catche(model, *args)
          options = args.extract_options!
          tag     = Proc.new { |controller| Catche::Tag::Object.for(model, controller.class, options) }

          # Use Rails caches_action to pass along the tag
          caches_action(*args, { :tag => tag }.merge(options))
        end

      end

      def _save_fragment(name, options={})
        key     = fragment_cache_key(name)
        object  = options[:tag]
        tags    = []

        if object.present?
          if object.respond_to?(:call)
            object = self.instance_exec(self, &object)

            if object.respond_to?(:tags)
              tags = object.tags(self)
            else
              tags = Array.new(object)
            end
          else
            tags = Array.new(object)
          end

          Catche::Tag.tag! key, *tags

          # Store for future reference
          @catche_cache_object = object
        end

        super
      end

    end
  end
end

ActionController::Base.send :include, Catche::Controller::Base

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
catche-0.1.0 lib/catche/controller/base.rb