Class: Diggit::Runnable Abstract

Inherits:
Plugin
  • Object
show all
Defined in:
lib/dgit/plugins.rb

Overview

This class is abstract.

Abstract superclass for analysis and joins.

Base class for analyses and joins. Runnables can be runned or cleaned. A clean of a runnable should always work, even if it has never been run. These methods have to be implemented in the subclasses. Addons can be made available to a runnable through a call to Runnable.require_addons. Addons can be accessed through the addons attribute, and they contain automatically methods that has names of their addons.

See Also:

Direct Known Subclasses

Analysis, Join

Instance Attribute Summary collapse

Attributes inherited from Plugin

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#name, name, #read_option

Constructor Details

#initialize(options) ⇒ Runnable

Returns a new instance of Runnable.



76
77
78
79
80
81
# File 'lib/dgit/plugins.rb', line 76

def initialize(options)
  super(options)
  @addons = {}
  self.class.required_addons.each { |a| @addons[a] = Dig.it.plugin_loader.load_plugin(a, :addon, true) }
  @addons.each_key { |a| self.class.class_eval { define_method(a) { return @addons[a] } } }
end

Instance Attribute Details

#addonsHash<String, Addon> (readonly)

Returns the hash of addons.

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dgit/plugins.rb', line 73

class Runnable < Plugin
  attr_reader :addons

  def initialize(options)
    super(options)
    @addons = {}
    self.class.required_addons.each { |a| @addons[a] = Dig.it.plugin_loader.load_plugin(a, :addon, true) }
    @addons.each_key { |a| self.class.class_eval { define_method(a) { return @addons[a] } } }
  end

  # Run the runnable.
  # @abstract This method must be overrided.
  # @return [void]
  def run; end

  # Clean the runnable.
  # @abstract This method must be overrided.
  # @return [void]
  def clean; end

  # Add an addon as a required addon.
  #
  # @param names [Array<String>] the names of addons to require.
  #  They correspond to the name of their class with underscore case.
  # @return [void]
  def self.require_addons(*names)
    @required_addons = names
  end

  def self.required_addons
    base_addons = superclass < Runnable ? superclass.required_addons : []
    return base_addons if @required_addons.nil?
    base_addons + @required_addons
  end
end

Class Method Details

.require_addons(*names) ⇒ void

This method returns an undefined value.

Add an addon as a required addon.

Parameters:

  • names (Array<String>)

    the names of addons to require. They correspond to the name of their class with underscore case.



98
99
100
# File 'lib/dgit/plugins.rb', line 98

def self.require_addons(*names)
  @required_addons = names
end

.required_addonsObject



102
103
104
105
106
# File 'lib/dgit/plugins.rb', line 102

def self.required_addons
  base_addons = superclass < Runnable ? superclass.required_addons : []
  return base_addons if @required_addons.nil?
  base_addons + @required_addons
end

Instance Method Details

#cleanvoid

This method is abstract.

This method must be overrided.

This method returns an undefined value.

Clean the runnable.



91
# File 'lib/dgit/plugins.rb', line 91

def clean; end

#runvoid

This method is abstract.

This method must be overrided.

This method returns an undefined value.

Run the runnable.



86
# File 'lib/dgit/plugins.rb', line 86

def run; end