Class: RedmineExtensions::PatchManager::EasyPatch
- Defined in:
- lib/redmine_extensions/patch_manager.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#original_klass_to_patch ⇒ Object
Returns the value of attribute original_klass_to_patch.
-
#patching_module ⇒ Object
Returns the value of attribute patching_module.
Class Method Summary collapse
Instance Method Summary collapse
- #all_patching_modules ⇒ Object
- #apply_patch ⇒ Object
- #easy_constantize(name) ⇒ Object
-
#initialize(original_klass_to_patch, patching_module, options = {}) ⇒ EasyPatch
constructor
A new instance of EasyPatch.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(original_klass_to_patch, patching_module, options = {}) ⇒ EasyPatch
Returns a new instance of EasyPatch.
371 372 373 374 |
# File 'lib/redmine_extensions/patch_manager.rb', line 371 def initialize(original_klass_to_patch, patching_module, = {}) @original_klass_to_patch, @patching_module, @options = original_klass_to_patch, patching_module, all_patching_modules << patching_module end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
369 370 371 |
# File 'lib/redmine_extensions/patch_manager.rb', line 369 def @options end |
#original_klass_to_patch ⇒ Object
Returns the value of attribute original_klass_to_patch.
369 370 371 |
# File 'lib/redmine_extensions/patch_manager.rb', line 369 def original_klass_to_patch @original_klass_to_patch end |
#patching_module ⇒ Object
Returns the value of attribute patching_module.
369 370 371 |
# File 'lib/redmine_extensions/patch_manager.rb', line 369 def patching_module @patching_module end |
Class Method Details
.all_patching_modules ⇒ Object
361 362 363 |
# File 'lib/redmine_extensions/patch_manager.rb', line 361 def self.all_patching_modules @@all_patching_modules ||= [] end |
Instance Method Details
#all_patching_modules ⇒ Object
365 366 367 |
# File 'lib/redmine_extensions/patch_manager.rb', line 365 def all_patching_modules self.class.all_patching_modules end |
#apply_patch ⇒ Object
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/redmine_extensions/patch_manager.rb', line 384 def apply_patch if (cond = @options[:if]) && cond.respond_to?(:call) return unless cond.call end pm_klass = easy_constantize(patching_module) # pm_klass.class_eval { unloadable } oktp_klass = easy_constantize(original_klass_to_patch) if oktp_klass.include?(pm_klass) puts "Patch (#{oktp_klass} #{pm_klass}) is already included!" else if @options[:prepend] oktp_klass.prepend pm_klass else oktp_klass.include pm_klass end end end |
#easy_constantize(name) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/redmine_extensions/patch_manager.rb', line 405 def easy_constantize(name) const = name.constantize rescue NameError if RedmineExtensions::PatchManager.patches_locations.has_key?(name) RedmineExtensions::PatchManager.with_reloading_code do load RedmineExtensions::PatchManager.patches_locations[patching_module] end name.constantize else raise end end |
#inspect ⇒ Object
380 381 382 |
# File 'lib/redmine_extensions/patch_manager.rb', line 380 def inspect to_s end |
#to_s ⇒ Object
376 377 378 |
# File 'lib/redmine_extensions/patch_manager.rb', line 376 def to_s "#{@original_klass_to_patch} <= #{@patching_module}" end |