Method: Ruber::PluginLike#add_extensions_to_project

Defined in:
lib/ruber/plugin_like.rb

#add_extensions_to_project(prj, forbid_existing = true) ⇒ nil

Adds the project extensions provided by the plugin to a project

Only the extensions matching the project will be added.

If the project already has one of the extensions this method wouold add, it can either raise an exception or ignore the exception. The first behaviour is desirable the first time the plugin’s extensions are added to the project, while the second is useful if this method has already been called for the project. In the first case, the existing extension most likely belongs to another plugin, which may lead to conflict. In the second case, instead, the extension will belong to this plugin, so there’s no risk.

an extension already exists in the project. one of the extension which this method would add

Parameters:

  • prj (Ruber::AbstractProject)

    the project to add the extensions to

  • forbid_existing (Boolean) (defaults to: true)

    whether to raise an exception or do nothing if

Returns:

  • (nil)

Raises:

  • ArgumentError if forbid_existing is true and the project already has

See Also:



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/ruber/plugin_like.rb', line 287

def add_extensions_to_project prj, forbid_existing = true
  @plugin_description.extensions.each_pair do |name, o|
    unless forbid_existing
      next if prj.extension name
    end
    ext = nil
    if o.is_a? Array
      o = o.find{|i| prj.match_rule? i}
      next unless o
      ext = o.class_obj.new prj
    elsif prj.match_rule? o
      ext = o.class_obj.new prj
    end
    if ext
      ext.plugin = self
      prj.add_extension name, ext
      emit extension_added(name.to_s, prj) rescue nil
    end
  end
end