class Dry::DependencyInjection::Importer
Public Class Methods
new(container)
click to toggle source
# File lib/dry/dependency_injection/importer.rb, line 7 def initialize(container) @container = container end
Public Instance Methods
finalize()
click to toggle source
# File lib/dry/dependency_injection/importer.rb, line 30 def finalize @container.finalize if @container.respond_to?(:finalize) end
import(path, prefix = '') { |file| ... }
click to toggle source
# File lib/dry/dependency_injection/importer.rb, line 11 def import(path, prefix = '') unless File.directory?(path) raise ArgumentError.new("path must be directory: #{path}") end full = File.expand_path(path) Dir[File.join(full, prefix, '**', '*.rb')].each do |file| next if block_given? && !yield(file) require file subpath = file.gsub(/#{full}\/|\.rb/, '') class_name = Dry::Core::Inflector.camelize(subpath) clazz = Dry::Core::Inflector.constantize(class_name) if clazz.is_a?(Class) key = subpath.gsub('/', '.') @container.register(key, clazz) end end self end