Class: Diggit::Plugin Abstract

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

Overview

This class is abstract.

Abstract superclass for all plugins.

Base class for plugins. They have associated options.

Direct Known Subclasses

Addon, Runnable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Plugin

Returns a new instance of Plugin.



29
30
31
# File 'lib/dgit/plugins.rb', line 29

def initialize(options)
	@options = options
end

Instance Attribute Details

#optionsHash<String, Object> (readonly)

Returns the hash of options.

Returns:

  • (Hash<String, Object>)

    the hash of options.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dgit/plugins.rb', line 26

class Plugin
	attr_reader :options

	def initialize(options)
		@options = options
	end

	# Returns the name of the plugin class
	# @return [String]
	def name
		self.class.name
	end

	# Returns the name of the plugin class
	# @return [String]
	def self.name
		to_s.underscore
	end

	# Returns the value of a plugin option
	# @param ns [Symbol] the name of the option's namespace
	# @param opt [Symbol] the name of the option
	# @param default [Object] the default value
	# @return [Object]
	def read_option(ns, opt, default)
		return @options[ns][opt] if @options.key?(ns) && @options[ns].key?(opt)
		default
	end
end

Class Method Details

.nameString

Returns the name of the plugin class

Returns:



41
42
43
# File 'lib/dgit/plugins.rb', line 41

def self.name
	to_s.underscore
end

Instance Method Details

#nameString

Returns the name of the plugin class

Returns:



35
36
37
# File 'lib/dgit/plugins.rb', line 35

def name
	self.class.name
end

#read_option(ns, opt, default) ⇒ Object

Returns the value of a plugin option

Parameters:

  • ns (Symbol)

    the name of the option’s namespace

  • opt (Symbol)

    the name of the option

  • default (Object)

    the default value

Returns:

  • (Object)


50
51
52
53
# File 'lib/dgit/plugins.rb', line 50

def read_option(ns, opt, default)
	return @options[ns][opt] if @options.key?(ns) && @options[ns].key?(opt)
	default
end