Module: Rys::EngineExtensions::ClassMethods

Defined in:
lib/rys/engine_extensions.rb

Instance Method Summary collapse

Instance Method Details

#lib_dependency_files(&block) ⇒ Object

Experimental function


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rys/engine_extensions.rb', line 73

def lib_dependency_files(&block)
  files = Array(block.call)
  abosulte_files = files.map do |file|
    root.join('lib', "#{file}.rb")
  end

  initializer "#{engine_name}.dependency_files", before: :engines_blank_point do |app|
    reloader = ActiveSupport::FileUpdateChecker.new(abosulte_files) do
      files.each do |file|
        require_dependency file
      end
    end

    reloader.execute
    app.reloaders << reloader

    config.to_prepare do
      reloader.execute_if_updated
    end
  end
end

#move_initializer(name, before: nil, after: nil) ⇒ Object

Move initializer

  1. Set execution block of original initializer to empty proc. Initializer remain but do nothing. This is because almost every initializer gets automatically `after` options and we cannot simply change it because others initializer may depend on it.

  2. New initializer is created with original execution block but under different name.

Be very careful with using this method. Results could be unpredictable. Also you must use the same name as orignal. String is different than Symbol.

move_initializer(:add_view_paths, after: :load_config_initializers)

More informations: guides.rubyonrails.org/configuring.html#initialization-events


111
112
113
# File 'lib/rys/engine_extensions.rb', line 111

def move_initializer(name, before: nil, after: nil)
  initializers_moves << { name: name, before: before, after: after }
end