Module: RedminePluginsHelper::Patches::Redmine::PluginPatch::ClassMethods

Defined in:
lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb

Instance Method Summary collapse

Instance Method Details

#by_path(path) ⇒ Object



20
21
22
23
24
# File 'lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb', line 20

def by_path(path)
  plugin_id_from_path(path).if_present do |v|
    registered_plugins[v]
  end
end

#plugin_id_from_path(path) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb', line 26

def plugin_id_from_path(path)
  path = path.to_pathname.expand_path
  return nil unless path.to_path.start_with?(::Rails.root.to_path)

  parts = path.relative_path_from(::Rails.root).each_filename.to_a
  return nil unless parts.first == 'plugins' && parts.count >= 2

  parts[1].to_sym
end

#post_register(plugin_name, &block) ⇒ Object



36
37
38
39
40
41
# File 'lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb', line 36

def post_register(plugin_name, &block)
  plugin = registered_plugins[plugin_name]
  raise "Plugin not registered: #{plugin_name}" unless plugin

  plugin.instance_eval(&block)
end