Module: RequirePatch

Defined in:
lib/require_patch.rb,
lib/require_patch/version.rb

Constant Summary collapse

VERSION =
'0.0.4'

Instance Method Summary collapse

Instance Method Details

#require_patch(plugin_name, *resources) ⇒ Object

It includes resources patches for plugin

Examples:

Rails.config.to_prepare do
  require_patch 'awesome_plugin', 'user', 'issue', 'user_controller', 'issue_helper'
end

Parameters:

  • plugin_name (String)

    the plugin name

  • *resources (String)

    names of resources which will need patching



12
13
14
15
16
17
18
19
20
21
# File 'lib/require_patch.rb', line 12

def require_patch(plugin_name, *resources)
  resources.each do |resource|  
    require_dependency resource rescue Rails.logger.warn "Can't find '#{resource}' for require_dependency"

    resource_patch = [plugin_name, [resource, 'patch'].join('_')].join('/')
    resource_constant, resource_patch_constant = [resource, resource_patch].map(&:camelize).map(&:constantize)

    resource_constant.send(:include, resource_patch_constant) unless resource_constant.included_modules.include? resource_patch_constant  
  end
end