class Rodakase::Container
Public Class Methods
auto_register!(dir) { |constant| ... }
click to toggle source
# File lib/rodakase/container.rb, line 59 def self.auto_register!(dir, &block) dir_root = root.join(dir.to_s.split('/')[0]) Dir["#{root}/#{dir}/**/*.rb"].each do |path| component_path = path.to_s.gsub("#{dir_root}/", '').gsub('.rb', '') component = Rodakase.Component(component_path) next if key?(component.identifier) Kernel.require component.path if block register(component.identifier, yield(component.constant)) else register(component.identifier) { component.instance } end end self end
boot!(name)
click to toggle source
# File lib/rodakase/container.rb, line 80 def self.boot!(name) require "core/boot/#{name}.rb" end
configure(env = config.env) { |self| ... }
click to toggle source
Calls superclass method
# File lib/rodakase/container.rb, line 17 def self.configure(env = config.env, &block) if !configured? super() do |config| app_config = Config.load(root, env) config.app = app_config if app_config end load_paths!('core') @_configured = true end yield(self) self end
configured?()
click to toggle source
# File lib/rodakase/container.rb, line 34 def self.configured? @_configured end
finalize!() { |self| ... }
click to toggle source
# File lib/rodakase/container.rb, line 38 def self.finalize!(&block) yield(self) if block Dir[root.join('core/boot/**/*.rb')].each(&method(:require)) if config.auto_register Array(config.auto_register).each(&method(:auto_register!)) end freeze end
import_module()
click to toggle source
# File lib/rodakase/container.rb, line 50 def self.import_module auto_inject = Dry::AutoInject(self) -> *keys { keys.each { |key| load_component(key) unless key?(key) } auto_inject[*keys] } end
load_component(key)
click to toggle source
# File lib/rodakase/container.rb, line 94 def self.load_component(key) require_component(key) { |klass| register(key) { klass.new } } end
load_paths()
click to toggle source
# File lib/rodakase/container.rb, line 123 def self.load_paths @_load_paths ||= [] end
load_paths!(*dirs)
click to toggle source
# File lib/rodakase/container.rb, line 114 def self.load_paths!(*dirs) dirs.map(&:to_s).each do |dir| path = root.join(dir) load_paths << path $LOAD_PATH.unshift(path.to_s) end self end
require(*paths)
click to toggle source
# File lib/rodakase/container.rb, line 84 def self.require(*paths) paths .flat_map { |path| path.include?('*') ? Dir[root.join(path)] : root.join(path) } .each { |path| Kernel.require path } end
require_component(key) { |constant| ... }
click to toggle source
# File lib/rodakase/container.rb, line 98 def self.require_component(key, &block) component = Rodakase.Component(key) path = load_paths.detect { |p| p.join(component.file).exist? } if path Kernel.require component.path yield(component.constant) if block else raise ArgumentError, "could not resolve require file for #{key}" end end
root()
click to toggle source
# File lib/rodakase/container.rb, line 110 def self.root config.root end