Module: Rys::EngineExtensions

Defined in:
lib/rys/engine_extensions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rys/engine_extensions.rb', line 4

def self.included(base)
  base.extend(ClassMethods)

  Rys::PluginsManagement.add(base)

  patches_dir = base.root.join('patches')
  Rys::Patcher.paths << patches_dir if patches_dir.directory?

  base.class_attribute :initializers_moves
  base.initializers_moves = []

  base.initializer :append_migrations do |app|
    if defined?(ENGINE_PATH) && base.root.to_s == ENGINE_PATH
      # Rails is loaded through this engine
      # and migrations are automatically added
    else
      config.paths['db/migrate'].expanded.each do |expanded_path|
        app.config.paths['db/migrate'] << expanded_path
      end
    end
  end

  # To load after Redmine
  base.config.before_configuration do |app|
    app.config.railties_order.unshift(base)
  end

  # To prepend view path after Redmine and plugins
  base.move_initializer(:add_view_paths, after: :load_config_initializers)
end

Instance Method Details

#initializersObject


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rys/engine_extensions.rb', line 35

def initializers
  @changed_initializers ||= begin
    original_initializers = super
    new_initializers = []

    initializers_moves.each do |moves|
      initializer = original_initializers.find{|i| i.name == moves[:name] }
      next if initializer.nil?

      new_initializer = initializer.dup
      new_initializer.instance_eval {
        @name = "moved.#{name}"
        @options = @options.dup

        if moves[:before]
          @options[:before] = moves[:before]
        end

        if moves[:after]
          @options[:after] = moves[:after]
        end
      }
      new_initializers << new_initializer

      # Initializer must remain
      initializer.instance_eval {
        @block = proc {}
      }
    end

    original_initializers + new_initializers
  end
end