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. 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

Constructor Details

#initialize(options) ⇒ Runnable

Returns a new instance of Runnable.



63
64
65
66
67
68
# File 'lib/dgit/plugins.rb', line 63

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:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/dgit/plugins.rb', line 60

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
    return [] if @required_addons.nil?
    @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.



87
88
89
# File 'lib/dgit/plugins.rb', line 87

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

.required_addonsObject



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

def self.required_addons
  return [] if @required_addons.nil?
  @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.



79
80
# File 'lib/dgit/plugins.rb', line 79

def clean
end

#runvoid

This method is abstract.

This method must be overrided.

This method returns an undefined value.

Run the runnable.



73
74
# File 'lib/dgit/plugins.rb', line 73

def run
end