Class: RedmineExtensions::PatchManager

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine_extensions/patch_manager.rb

Defined Under Namespace

Classes: EasyPatch, EasyPatchesCollection, EasyPatchesSection

Constant Summary collapse

PERSISTING_PATCHES =
[:force_first, :ruby, :rails, :redmine_plugins, :others]
@@patches_locations =
{}
@@reloading_code =
false
@@reloadable_patches_applied =
0

Class Method Summary collapse

Class Method Details

.apply_easy_page_patchesObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/redmine_extensions/patch_manager.rb', line 143

def self.apply_easy_page_patches
  return if @registered_easy_page_controllers.nil? || @registered_easy_page_helpers.nil?
  @registered_easy_page_controllers.each do |controller_klass_name|
    controller_klass = controller_klass_name.constantize

    @registered_easy_page_helpers.each do |helper_klass_name|
      if helper_klass_name.end_with?('Helper')
        helper_klass_symbol = helper_klass_name[0, helper_klass_name.index('Helper')]
      end

      controller_klass.class_eval "helper :#{helper_klass_symbol.underscore}" if helper_klass_symbol
      controller_klass.class_eval "include #{helper_klass_name}"
    end
  end
end

.apply_persisting_patchesObject



159
160
161
162
163
164
165
# File 'lib/redmine_extensions/patch_manager.rb', line 159

def self.apply_persisting_patches
  PERSISTING_PATCHES.each do |section|
    @@registered_patches[section].apply_all_patches
  end

  true
end

.apply_reloadable_patchesObject



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/redmine_extensions/patch_manager.rb', line 167

def self.apply_reloadable_patches
  (@@registered_patches.keys - PERSISTING_PATCHES).each do |section|
    reloading_log "Applying #{section} patches (#{@@registered_patches[section].count})"
    @@registered_patches[section].apply_all_patches
  end

  reloading_log("Applying page module patches")
  apply_easy_page_patches

  @@reloadable_patches_applied += 1
  true
end

.initialize_sectionsObject

is called after EasyPatchesSection load



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/redmine_extensions/patch_manager.rb', line 13

def self.initialize_sections
  @@registered_patches ||= ActiveSupport::OrderedHash.new
  @@registered_patches[:force_first] ||= EasyPatchesSection.new
  @@registered_patches[:ruby] ||= EasyPatchesSection.new
  @@registered_patches[:rails] ||= EasyPatchesSection.new
  @@registered_patches[:redmine_plugins] ||= EasyPatchesSection.new
  @@registered_patches[:others] ||= EasyPatchesSection.new
  @@registered_patches[:concerns] ||= EasyPatchesSection.new
  @@registered_patches[:controllers] ||= EasyPatchesSection.new
  @@registered_patches[:helpers] ||= EasyPatchesSection.new
  @@registered_patches[:models] ||= EasyPatchesSection.new
end

.patches_locationsObject



26
27
28
# File 'lib/redmine_extensions/patch_manager.rb', line 26

def self.patches_locations
  @@patches_locations
end

.register_concern_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



107
108
109
# File 'lib/redmine_extensions/patch_manager.rb', line 107

def self.register_concern_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :concerns }.merge(options))
end

.register_controller_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



111
112
113
# File 'lib/redmine_extensions/patch_manager.rb', line 111

def self.register_controller_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :controllers }.merge(options))
end

.register_easy_page_controller(*controller_or_controllers_klass_name) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/redmine_extensions/patch_manager.rb', line 135

def self.register_easy_page_controller(*controller_or_controllers_klass_name)
  @registered_easy_page_controllers ||= []
  controller_or_controllers_klass_name.each do |controller_klass_name|
    @registered_easy_page_controllers << controller_klass_name if !@registered_easy_page_controllers.include?(controller_klass_name)
  end
  @registered_easy_page_controllers
end

.register_easy_page_helper(*helper_or_helpers_klass_name) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/redmine_extensions/patch_manager.rb', line 127

def self.register_easy_page_helper(*helper_or_helpers_klass_name)
  @registered_easy_page_helpers ||= []
  helper_or_helpers_klass_name.each do |helper_klass_name|
    @registered_easy_page_helpers << helper_klass_name if !@registered_easy_page_helpers.include?(helper_klass_name)
  end
  @registered_easy_page_helpers
end

.register_helper_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



115
116
117
# File 'lib/redmine_extensions/patch_manager.rb', line 115

def self.register_helper_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :helpers }.merge(options))
end

.register_model_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



119
120
121
# File 'lib/redmine_extensions/patch_manager.rb', line 119

def self.register_model_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :models }.merge(options))
end

.register_other_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



103
104
105
# File 'lib/redmine_extensions/patch_manager.rb', line 103

def self.register_other_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :others }.merge(options))
end

.register_patch_to_be_first(original_klass_to_patch, patching_module, options = {}) ⇒ Object



123
124
125
# File 'lib/redmine_extensions/patch_manager.rb', line 123

def self.register_patch_to_be_first(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :force_first }.merge(options))
end

.register_rails_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



95
96
97
# File 'lib/redmine_extensions/patch_manager.rb', line 95

def self.register_rails_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { section: :rails }.merge(options))
end

.register_redmine_plugin_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



99
100
101
# File 'lib/redmine_extensions/patch_manager.rb', line 99

def self.register_redmine_plugin_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { :section => :redmine_plugins }.merge(options))
end

.register_ruby_patch(original_klass_to_patch, patching_module, options = {}) ⇒ Object



91
92
93
# File 'lib/redmine_extensions/patch_manager.rb', line 91

def self.register_ruby_patch(original_klass_to_patch, patching_module, options = {})
  register_patch(original_klass_to_patch, patching_module, { section: :ruby }.merge(options))
end

.reloadable_patches_appliedObject



37
38
39
# File 'lib/redmine_extensions/patch_manager.rb', line 37

def self.reloadable_patches_applied
  @@reloadable_patches_applied
end

.reloading_log(message) ⇒ Object



180
181
182
183
# File 'lib/redmine_extensions/patch_manager.rb', line 180

def self.reloading_log(message)
  return if @@reloadable_patches_applied <= 1
  puts "PatchManager: #{message}"
end

.with_reloading_codeObject



30
31
32
33
34
35
# File 'lib/redmine_extensions/patch_manager.rb', line 30

def self.with_reloading_code
  @@reloading_code = true
  yield
ensure
  @@reloading_code = false
end