Sha256: 2e4a51dde701ccbebccb6e74b8a95242c2ba1462dd27a409346646c7379d0b0c

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

module CachedResource
  # The Model module is included in ActiveResource::Base and
  # provides methods to enable caching and manipulate the caching
  # configuration
  module Model
    extend ActiveSupport::Concern

    included do
      class << self
        attr_accessor :cached_resource

        # Initialize cached resource or retrieve the current cached resource configuration.
        def cached_resource(options={})
          defined?(@cached_resource) && @cached_resource || setup_cached_resource!(options)
        end

        # Set up cached resource for this class by creating a new configuration
        # and establishing the necessary methods.
        def setup_cached_resource!(options)
          @cached_resource = CachedResource::Configuration.new(options)
          send :include, CachedResource::Caching
          @cached_resource
        end
      end
    end

    module ClassMethods
      # Copy a superclass's cached resource configuration if
      # it's defined.  Unfortunately, this means that any subclass
      # that wants an independent configuration will need to execute:
      # self.cached_resource = CachedResource::Configuration.new(options={})
      def inherited(child)
        child.cached_resource = self.cached_resource if defined?(@cached_resource)
        super
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cached_resource-7.2.0 lib/cached_resource/cached_resource.rb
cached_resource-7.1.0 lib/cached_resource/cached_resource.rb
cached_resource-7.0.0 lib/cached_resource/cached_resource.rb
cached_resource-6.0.0 lib/cached_resource/cached_resource.rb
cached_resource-5.3.0 lib/cached_resource/cached_resource.rb
cached_resource-5.2.0 lib/cached_resource/cached_resource.rb
cached_resource-5.1.3 lib/cached_resource/cached_resource.rb
cached_resource-5.1.2 lib/cached_resource/cached_resource.rb
cached_resource-5.1.1 lib/cached_resource/cached_resource.rb
cached_resource-5.1.0 lib/cached_resource/cached_resource.rb
cached_resource-5.0.1 lib/cached_resource/cached_resource.rb