Class: Chanko::Loader::ZeitwerkLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/chanko/loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ZeitwerkLoader

Returns a new instance of ZeitwerkLoader.



58
59
60
# File 'lib/chanko/loader.rb', line 58

def initialize(name)
  @name = name
end

Class Method Details

.add_unit_directory_to_eager_load_pathsObject



50
51
52
53
54
55
56
# File 'lib/chanko/loader.rb', line 50

def self.add_unit_directory_to_eager_load_paths
  path = Chanko::Config.units_directory_path

  unless Rails.configuration.eager_load_paths.include?(path)
    Rails.configuration.eager_load_paths << path
  end
end

.cacheObject



35
36
37
38
# File 'lib/chanko/loader.rb', line 35

def self.cache
  # backward compatibility
  { }
end

.eager_load_units!Object



40
41
42
# File 'lib/chanko/loader.rb', line 40

def self.eager_load_units!
  # Zeitwerk load chanko units as default
end

.load(name) ⇒ Object



31
32
33
# File 'lib/chanko/loader.rb', line 31

def self.load(name)
  self.new(name).load
end

.prepare_eager_loadObject



44
45
46
47
48
# File 'lib/chanko/loader.rb', line 44

def self.prepare_eager_load
  add_unit_directory_to_eager_load_paths
  Rails.autoloaders.main.collapse(Chanko::Config.units_directory_path + '/*')
  Rails.autoloaders.main.ignore(Chanko::Config.units_directory_path + '/*/spec*')
end

Instance Method Details

#constantizeObject



69
70
71
# File 'lib/chanko/loader.rb', line 69

def constantize
  @name.to_s.camelize.constantize
end

#loadObject



62
63
64
65
66
67
# File 'lib/chanko/loader.rb', line 62

def load
  constantize
rescue NameError
  # Chanko never raise error even if the constant fails to reference
  false
end