Class: HerdstWorker::Autoload::Facade

Inherits:
Object
  • Object
show all
Defined in:
lib/herdst_worker/autoload/facade.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Facade

Returns a new instance of Facade.



9
10
11
12
13
14
15
16
17
# File 'lib/herdst_worker/autoload/facade.rb', line 9

def initialize(app)
    self.root_path = app.config.paths.root
    
    self.loaded = []
    self.files = []
    self.paths = [ "lib" ]
    
    self.reload
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



6
7
8
# File 'lib/herdst_worker/autoload/facade.rb', line 6

def files
  @files
end

#loadedObject

Returns the value of attribute loaded.



6
7
8
# File 'lib/herdst_worker/autoload/facade.rb', line 6

def loaded
  @loaded
end

#pathsObject

Returns the value of attribute paths.



6
7
8
# File 'lib/herdst_worker/autoload/facade.rb', line 6

def paths
  @paths
end

#root_pathObject

Returns the value of attribute root_path.



6
7
8
# File 'lib/herdst_worker/autoload/facade.rb', line 6

def root_path
  @root_path
end

Instance Method Details

#<<(path) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/herdst_worker/autoload/facade.rb', line 20

def <<(path)
    full_path = self.root_path + "/" + path
    
    if File.directory?(full_path)
        self.paths << path
    else
        self.files << path
    end
end

#has_loaded?(file) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/herdst_worker/autoload/facade.rb', line 52

def has_loaded?(file)
    self.loaded.include?(file)
end

#load_file(file) ⇒ Object



57
58
59
60
61
62
# File 'lib/herdst_worker/autoload/facade.rb', line 57

def load_file(file)
    unless has_loaded?(file)
        load file
        self.loaded << file
    end
end

#reloadObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/herdst_worker/autoload/facade.rb', line 31

def reload
    self.files.each do |file|
        self.load_file(self.root_path + "/" + file)
    end
    
    self.paths.each do |folder|
        concern_files = Dir.glob("#{root_path}/#{folder}/concerns/*.rb").sort
        folder_files = Dir.glob("#{root_path}/#{folder}/*.rb").sort
        
        concern_sub_files = Dir.glob("#{self.root_path}/#{folder}/**/concerns/*.rb").sort
        folder_sub_files = Dir.glob("#{self.root_path}/#{folder}/**/*.rb").sort
        
        files = (concern_files + folder_files + concern_sub_files + folder_sub_files).uniq
        
        files.each do |file|
            self.load_file(file)
        end
    end
end