Skip to content

Patches

Ondřej Moravčík edited this page Sep 26, 2018 · 1 revision

Patching is quite easy in Rys

First you need to register a path to directory. If you generated Rys via rys:plugin this step can be skipped.

# extend your engine
include ::Rys::EngineExtensions

# or manually
Rys::Patcher.paths << PATH_TO_DIRECTORY

Definition of the patch

Rys::Patcher.add(CLASS_TO_PATCH_IN_STRING) do

  # nothing
  #    patch is applied after redmine plugins are loaded
  # :earlier_to_prepare
  #    applied as soon as possible
  where WHERE

  # Applied once. Useful for classes which are not reloaded (like String)
  apply_only_once!

  # Applied if CONDITION is met
  apply_if do
    CONDITION
  end

  # Apply if redmine plugins exist and its installed
  apply_if_plugins :easy_crm_cases

  included do
    # This section is evaluated in CLASS_TO_PATCH_IN_STRING
  end

  instance_methods do
    # Your instance methods
  end

  instance_methods(feature: FEATURE) do
    # Your conditional methods
  end

  class_methods do
    # Your class methods
  end

end

So your patch can look like this

Rys::Patcher.add('IssuesController') do

  included do
    before_action :add_flash_notice, only: [:show]
  end

  instance_methods do

    def show
      flash.now[:notice] = 'Hello'
      super
    end

  end
end

Notes

  • Patches are applied via .preload so you can call super
  • Be careful of mixing patching with alias_method_chain (try to avoid it)
  • Method insides instance_methods(feature:) must have super method

Rys basic

Dependencies

Tests

Management

Clone this wiki locally