Sha256: 3ed8487700167688c3fec3e89510b6c86c539c5fe000f9dc2e102de6a3b5f4f3

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# -*- encoding : utf-8 -*-
module ThreeD
  module ModelFragments
  
    def self.included(base)
      base.extend ClassMethods
    end  
  
    module ClassMethods
      def model_fragments
        unless has_model_fragments?
          
          if ActionController::Base.cache_store.inspect.match("FileStore")
          
            self.send :include, InstanceMethods
            cattr_accessor :caching_path
      
            self.caching_path = ActionController::Base.cache_store.cache_path
            self.after_save :clear_view_cache
            self.after_destroy :clear_view_cache
          else
            raise "Currently, ModelFragments only support FileStore\nPlease set 'ActionController::Base.cache_store = :file_store, /path/to/cache'"
          end    
        end
      end  
    
      def has_model_fragments?
        self.included_modules.include?(InstanceMethods)
      end
    end  
  
    module InstanceMethods
    
      def cache_name(data, scope_data=nil)  
        data = data.to_s
        x = "#{self.class.name.parameterize}_#{self.id}_cache_#{data}"
        x << "_#{scope_data.to_s}" if scope_data
        return x
      end
    
      def clear_view_cache(data="")
        %x(rm #{self.full_cache_path(data)})
      end
    
      def full_cache_path(data="")
        "#{self.class.caching_path}/views/#{self.class.name.parameterize}_#{self.id}_#{data}*"
      end  
    
    end  
    

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
3d_cache-0.0.01a lib/three_d/model_fragments.rb