Class: RedmineExtensions::PatchManager::EasyPatch

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @original_klass_to_patch, @patching_module, @options = original_klass_to_patch, patching_module, options
  all_patching_modules << patching_module
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



369
370
371
# File 'lib/redmine_extensions/patch_manager.rb', line 369

def options
  @options
end

#original_klass_to_patchObject

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_moduleObject

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_modulesObject



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_modulesObject



365
366
367
# File 'lib/redmine_extensions/patch_manager.rb', line 365

def all_patching_modules
  self.class.all_patching_modules
end

#apply_patchObject



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

#inspectObject



380
381
382
# File 'lib/redmine_extensions/patch_manager.rb', line 380

def inspect
  to_s
end

#to_sObject



376
377
378
# File 'lib/redmine_extensions/patch_manager.rb', line 376

def to_s
  "#{@original_klass_to_patch} <= #{@patching_module}"
end