Class: RailsConnector::Meta::EagerLoader

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rails_connector/meta/eager_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEagerLoader

Returns a new instance of EagerLoader.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_connector/meta/eager_loader.rb', line 11

def initialize
  # Rails.logger.debug "EagerLoader: I am eager to start working"
  @obj_classes = {}
  # Rails 3.1 contains a bug that screws attribute loading
  # attributes are set to assigned classes
  if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 1
    RailsConnector::ObjClass.all.each do |obj_class|
      obj_class.custom_attributes
      @obj_classes[obj_class.name] = obj_class
    end
  else
    RailsConnector::ObjClass.includes(:custom_attributes_raw).all.each do |obj_class|
      @obj_classes[obj_class.name] = obj_class
    end
    preload_attribute_blobs
  end
end

Instance Attribute Details

#obj_classesObject (readonly)

Returns the value of attribute obj_classes.



9
10
11
# File 'lib/rails_connector/meta/eager_loader.rb', line 9

def obj_classes
  @obj_classes
end

Instance Method Details

#forget_obj_class(name) ⇒ Object



39
40
41
# File 'lib/rails_connector/meta/eager_loader.rb', line 39

def forget_obj_class(name)
  @obj_classes.delete(name.to_s)
end

#obj_class(name) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/rails_connector/meta/eager_loader.rb', line 29

def obj_class(name)
  name = name.to_s
  if !@obj_classes.fetch(name, nil).nil?
    @obj_classes[name]
  else
    # TODO: preload_attribute_blobs for obj_class
    @obj_classes[name] ||= RailsConnector::ObjClass.find_by_obj_class_name(name)
  end
end