Sha256: 888b49a0d4ec11b7cc9bde757e2f49adac6eef67435addd199d75ddfbe4463e7

Contents?: true

Size: 1.92 KB

Versions: 6

Compression:

Stored size: 1.92 KB

Contents

# This module contains basic Export plugin functions.
#

module Dradis
  module Plugins
    module Export
      class Base
        attr_accessor :content_service, :logger, :options, :plugin, :project, :scope

        def initialize(args={})
          # Save everything just in case the implementing class needs any of it.
          @options = args

          # Can't use :fetch for :plugin or :default_plugin gets evaluated
          @logger  = args.fetch(:logger, Rails.logger)
          @plugin  = args[:plugin] || default_plugin
          @project = args.key?(:project_id) ? Project.find(args[:project_id]) : nil
          @scope = args.fetch(:scope, :published).to_sym

          @content_service = args.fetch(:content_service, default_content_service)

          post_initialize(args)
        end

        def export(args={})
          raise "The export() method is not implemented in this plugin [#{self.class.name}]."
        end

        # This method can be overwriten by plugins to do initialization tasks.
        def post_initialize(args={})
        end

        private
        def default_content_service
          @content ||= Dradis::Plugins::ContentService::Base.new(
            logger: logger,
            plugin: plugin,
            project: project,
            scope: scope
          )
        end

        # This assumes the plugin's Exporter class is directly nexted into the
        # plugin's namespace (e.g. Dradis::Plugins::HtmlExport::Exporter)
        def default_plugin
          plugin_module   = self.class.name.deconstantize
          plugin_constant = plugin_module.constantize
          plugin_engine   = plugin_constant::Engine
          if Dradis::Plugins.registered?(plugin_engine)
            plugin_constant
          else
            raise "You need to pass a :plugin value to your Exporter or define it under your plugin's root namespace."
          end
        end

      end # Base
    end # Export
  end # Plugins
end # Core

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dradis-plugins-4.14.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.13.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.11.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.10.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.9.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.8.0 lib/dradis/plugins/export/base.rb