Module: Searchgasm::Shared::VirtualClasses::ClassMethods

Defined in:
lib/searchgasm/shared/virtual_classes.rb

Instance Method Summary collapse

Instance Method Details

#create_virtual_class(model_class) ⇒ Object

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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/searchgasm/shared/virtual_classes.rb', line 15

def create_virtual_class(model_class)
  class_search_name = "::Searchgasm::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