Class: Appfuel::Feature::Initializer
- Inherits:
-
Object
- Object
- Appfuel::Feature::Initializer
- Defined in:
- lib/appfuel/feature/initializer.rb
Overview
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.
Instance Method Summary collapse
-
#call(name, container) ⇒ Boolean
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.
Instance Method Details
#call(name, container) ⇒ Boolean
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/appfuel/feature/initializer.rb', line 14 def call(name, container) name = name.to_s.underscore feature_key = "features.#{name}" finished_key = "#{feature_key}.initialized" if container.key?(finished_key) && container[finished_key] == true return false end 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 trace = e.backtrace.join("\n") raise "[#{feature_key} initialize] could not load " + "#{feature_path}: #{e.} #{trace}" end end container[:auto_register_classes].each do |klass| key = klass.container_class_path next if container.key?(key) || !klass.register_class? container.register(key, klass) end Appfuel.run_initializers(feature_key, container) container.register(finished_key, true) true end |