Class: Goldberg::SiteController

Inherits:
ActiveRecord::Base show all
Includes:
Model
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/site_controller.rb

Class Method Summary collapse

Methods included from Model

included

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?

Class Method Details

.classesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/site_controller.rb', line 12

def self.classes
  for path in ActionController::Routing.controller_paths do
    self.load_class_files(path)
  end  

  classes = Hash.new
  
  ObjectSpace.each_object(Class) do |klass|
    if klass.respond_to? :controller_path
      if (klass.to_s != ApplicationController.to_s and
          klass.ancestors.map{|c|c.to_s}.include?(ApplicationController.to_s))
        classes[klass.controller_path] = klass
      end
    end
  end
  
  return classes
end

.load_class_files(path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/site_controller.rb', line 32

def self.load_class_files(path)
  prereqs = []
  files = []
  dirs = []
  for file in Dir.glob("#{path}/*").sort do
    if file.match /_controller\.rb$/
      files << file
    elsif file.match /\.rb$/
      prereqs << file
    elsif File.directory? file
      dirs << file
    end
  end

  (prereqs + files).each do |file|
    begin
      load file
    rescue
      logger.info "Couldn't load file '#{file}' (already loaded?)"
    end
  end

  dirs.each do |dir|
    self.load_class_files(dir)
  end
end