Sha256: fec9f6ceeee298628987c67f2cc465c2e2ac1724a8220f39aab4f2aa6c6624c2
Contents?: true
Size: 1.9 KB
Versions: 18
Compression:
Stored size: 1.9 KB
Contents
module Appfuel module Feature # Run a given feature's initializers. Each feature can declare any number # of initializers just as the application does. This allow dependencies # and vendor code to be initialized only when the feature is used. class Initializer # Ensure the correct namespaces are registered so that the initializer # dsl will work and then require the feature and run its intializers # unless instructed not too. Initializers are only run once. # # @param name [String] name of the feature as found in the container # @param container [Dry::Container] application container # @return [Boolean] def call(name, container) name = name.to_s.underscore feature_key = "features.#{name}" return false if initialized?(container, feature_key) unless container.key?(feature_key) Appfuel.setup_container_dependencies(feature_key, container) end unless require_feature_disabled?(container, feature_key) feature_path = "#{container[:features_path]}/#{name}" begin require feature_path rescue LoadError => _e raise "[#{feature_key} initialize] could not load #{feature_path}" end end container[:auto_register_classes].each do |klass| next unless klass.register_class? container.register(klass.container_class_path, klass) end Appfuel.run_initializers(feature_key, container) true end private def require_feature_disabled?(container, feature_key) disable_key = "#{feature_key}.disable_require" container.key?(disable_key) && container[disable_key] == true end def initialized?(container, feature_key) init_key = "#{feature_key}.initialized" container.key?(init_key) && container[init_key] == true end end end end
Version data entries
18 entries across 18 versions & 1 rubygems