Class: HerdstWorker::Autoload::Facade
- Inherits:
-
Object
- Object
- HerdstWorker::Autoload::Facade
- Defined in:
- lib/herdst_worker/autoload/facade.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#loaded ⇒ Object
Returns the value of attribute loaded.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
Instance Method Summary collapse
- #<<(path) ⇒ Object
- #has_loaded?(file) ⇒ Boolean
-
#initialize(app) ⇒ Facade
constructor
A new instance of Facade.
- #load_file(file) ⇒ Object
- #reload ⇒ Object
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
#files ⇒ Object
Returns the value of attribute files.
6 7 8 |
# File 'lib/herdst_worker/autoload/facade.rb', line 6 def files @files end |
#loaded ⇒ Object
Returns the value of attribute loaded.
6 7 8 |
# File 'lib/herdst_worker/autoload/facade.rb', line 6 def loaded @loaded end |
#paths ⇒ Object
Returns the value of attribute paths.
6 7 8 |
# File 'lib/herdst_worker/autoload/facade.rb', line 6 def paths @paths end |
#root_path ⇒ Object
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
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 |
#reload ⇒ Object
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 |