Class: Orbit::Loaders::DirectoryLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/orbit/loaders/directory_loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDirectoryLoader

Returns a new instance of DirectoryLoader.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/orbit/loaders/directory_loader.rb', line 6

def initialize
  base_path = "#{Dir.pwd}"
  @files = []

  if Orbit::Config.app_path.is_a?(String)
    @files.push Dir["#{base_path}/#{Orbit::Config.app_path}/**/*.rb"]
  else
    Orbit::Config.app_path.each do |path|
      @files.push Dir["#{base_path}/#{path}/**/*.rb"]
    end
  end

  @retries = 0
  @files = @files.flatten
  @reloader = FileReloader.new(files)
end

Instance Attribute Details

#reloaderObject (readonly)

Returns the value of attribute reloader.



4
5
6
# File 'lib/orbit/loaders/directory_loader.rb', line 4

def reloader
  @reloader
end

Class Method Details

.loadObject



23
24
25
26
27
# File 'lib/orbit/loaders/directory_loader.rb', line 23

def self.load
  new.tap do |instance|
    instance.load
  end
end

Instance Method Details

#loadObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/orbit/loaders/directory_loader.rb', line 29

def load
  files_with_exception = []

  while retries < 3 && files.any?
    @files = load_files
    @retries += 1
  end

  if files.any?
    puts "[Warning] some files could not be loaded:"
    files_with_exception.each { |file| puts "  - #{file}" }
    puts ""
  end
end