Module: Appfuel::Initialize
- Defined in:
- lib/appfuel/initialize.rb,
lib/appfuel/initialize/initializer.rb
Defined Under Namespace
Classes: Initializer
Class Method Summary collapse
-
.define(name, envs = [], app_name = nil, &block) ⇒ Object
Dsl used to add an initializer into to the application container.
-
.handle_configuration(container, params = {}) ⇒ Dry::Container
Populate configuration definition that is in the container and add its results to the container.
- .handle_repository_mapping(container, params = {}) ⇒ Object
-
.run(params = {}) ⇒ Dry::Container
This will initialize the app by handling configuration and running all the initilizers, which will result in an app container that has registered the config, env, and anything else the initializers decide to add.
- .runlist(name, list, app_name = nil) ⇒ Object
Class Method Details
.define(name, envs = [], app_name = nil, &block) ⇒ Object
Dsl used to add an initializer into to the application container. This will add an initializer into the default app unless another name is given.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/appfuel/initialize.rb', line 14 def define(name, envs = [], app_name = nil, &block) if !name.is_a?(String) && !name.include?('.') fail "initializer name must be a string in the in the form of " + "([feature|global].initializer_name)" end top, name = name.split('.') top = "features.#{top}" unless top == 'global' namespace = "#{top}.initializers.#{name}" container = Appfuel.app_container(app_name) initializer = Initializer.new(name, envs, &block) container.register(namespace, initializer) initializer end |
.handle_configuration(container, params = {}) ⇒ Dry::Container
Populate configuration definition that is in the container and add its results to the container. It also adds the environment from the config to the container for easier access.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/appfuel/initialize.rb', line 54 def handle_configuration(container, params = {}) overrides = params[:overrides] || {} env = params[:env] || ENV definition = container['config_definition'] config = definition.populate(env: env, overrides: overrides) env = config.fetch(:env) { fail "key (:env) is missing from config" } container.register(:config, config) container.register(:env, env) container end |
.handle_repository_mapping(container, params = {}) ⇒ Object
68 69 70 71 |
# File 'lib/appfuel/initialize.rb', line 68 def handle_repository_mapping(container, params = {}) initializer = container[:repository_initializer] initializer.call(container) end |
.run(params = {}) ⇒ Dry::Container
This will initialize the app by handling configuration and running all the initilizers, which will result in an app container that has registered the config, env, and anything else the initializers decide to add.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/appfuel/initialize.rb', line 81 def run(params = {}) app_name = params.fetch(:app_name) { Appfuel.default_app_name } container = Appfuel.app_container(app_name) if container.key?(:initialized) && container[:initialized] == true return container end handle_configuration(container, params) handle_repository_mapping(container, params) Appfuel.run_initializers('global', container, params[:exclude] || []) container.register(:initialized, true) container end |
.runlist(name, list, app_name = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/appfuel/initialize.rb', line 29 def runlist(name, list, app_name = nil) namespace = "#{name}.initializers.run" unless name == 'global' namespace = "features.#{namespace}" end list = [list] unless list.is_a?(Array) fail "run list must be [String|Symbol|Array]" unless list.is_a?(Array) container = Appfuel.app_container(app_name) container.register(namespace, list) nil end |