Class: Dry::System::Rails::Railtie Private

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/dry/system/rails/railtie.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

System railtie is responsible for setting up a container and handling reloading in dev mode

Instance Method Summary collapse

Instance Method Details

#app_namespaceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: we had to rename namespace=>app_namespace because

Rake::DSL's Kernel#namespace *sometimes* breaks things.
Currently we are missing specs verifying that rake tasks work
correctly and those must be added!


44
45
46
47
48
49
# File 'lib/dry/system/rails/railtie.rb', line 44

def app_namespace
  @app_namespace ||= begin
    top_level_namespace = ::Rails.application.class.to_s.split("::").first
    Object.const_get(top_level_namespace)
  end
end

#finalize!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
26
# File 'lib/dry/system/rails/railtie.rb', line 17

def finalize!
  container = System::Rails.create_container(name: name)

  set_or_reload(:Container, container)
  set_or_reload(:Import, container.injector)

  container.refresh_boot_files if reloading?

  container.finalize! unless ::Rails.env.test?
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/dry/system/rails/railtie.rb', line 34

def name
  app_namespace.name.underscore.to_sym
end

#reloading?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


29
30
31
# File 'lib/dry/system/rails/railtie.rb', line 29

def reloading?
  app_namespace.const_defined?(:Container)
end

#set_or_reload(const_name, const) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
57
58
# File 'lib/dry/system/rails/railtie.rb', line 52

def set_or_reload(const_name, const)
  if app_namespace.const_defined?(const_name)
    app_namespace.__send__(:remove_const, const_name)
  end

  app_namespace.const_set(const_name, const)
end