Sha256: 25271e0c042ad1bd739c1706a07f315020806f898cc0a8e71ff19c435b3bccd4

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

module Searchlogic
  module Shared
    # = Searchlogic Virtual Classes
    #
    # Creates virtual classes for each model, to implementing a type of caching. So that object instantiation for searchlogic searches is cached. This is lazy, meaning
    # it will only cache when it needs. So the first instantion will be much slow than the following ones. This is cached in the RAM, so if the process is restarted the caching is cleared.
    module VirtualClasses
      def self.included(klass)
        klass.extend ClassMethods
      end
      
      module ClassMethods
        # Creates virtual classes for the class passed to it. This is a neccesity for keeping dynamically created method
        # names specific to models. It provides caching and helps a lot with performance.
        def create_virtual_class(model_class)
          class_search_name = "::Searchlogic::Cache::#{model_class.name}" + name.split(/::/)[1]
  
          begin
            eval(class_search_name)
          rescue NameError
            eval <<-end_eval
              class #{class_search_name} < ::#{name}
                def self.klass
                  #{model_class.name}
                end
        
                def klass
                  #{model_class.name}
                end
              end
      
              #{class_search_name}
            end_eval
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
searchlogic-1.5.6 lib/searchlogic/shared/virtual_classes.rb
searchlogic-1.5.3 lib/searchlogic/shared/virtual_classes.rb
searchlogic-1.5.7 lib/searchlogic/shared/virtual_classes.rb
searchlogic-1.5.4 lib/searchlogic/shared/virtual_classes.rb