Sha256: 1f084a859dd0fa81d6ad415f0b57a900ad19ed2b0c32bc810cfc89279831e13a

Contents?: true

Size: 1.84 KB

Versions: 25

Compression:

Stored size: 1.84 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

        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

          @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
          )
        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

25 entries across 25 versions & 1 rubygems

Version Path
dradis-plugins-4.7.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.6.1 lib/dradis/plugins/export/base.rb
dradis-plugins-4.5.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.4.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.3.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.2.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.1.0 lib/dradis/plugins/export/base.rb
dradis-plugins-4.0.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.22.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.21.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.20.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.19.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.18.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.17.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.16.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.15.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.14.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.13.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.12.0 lib/dradis/plugins/export/base.rb
dradis-plugins-3.11.0 lib/dradis/plugins/export/base.rb