Class: FeduxOrgStdlib::GemPlugins::Plugin

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/fedux_org_stdlib/gem_plugins/plugin.rb

Overview

Plugin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec:) ⇒ Plugin

Returns a new instance of Plugin.



14
15
16
17
18
19
20
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 14

def initialize(spec:)
  @name        = spec.name
  @author      = Array(spec.authors).zip(Array(spec.email)).map { |a, e| format('%s (%s)', a, e) }.to_list
  @version     = spec.version
  @homagepage  = spec.homepage
  @active      = false
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



12
13
14
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 12

def author
  @author
end

#homepageObject (readonly)

Returns the value of attribute homepage.



12
13
14
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 12

def homepage
  @homepage
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 12

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



12
13
14
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 12

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



57
58
59
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 57

def <=>(other)
  name <=> other.name
end

#activateObject

Activate the plugin (require the gem - enables/loads the plugin immediately at point of call, even if plugin is disabled) Does not reload plugin if it’s already active.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 26

def activate
  return if active?

  begin
    require name
  rescue LoadError => e
    warn "Found plugin \"#{name}\", but could not require \"#{require_file}\""
    warn e
  rescue StandardError => e
    warn "Require plugin \"#{name}\" failed, saying: #{e}\n#{e.backtrace.join("\n")}"
  end

  @active = true
end

#active?Boolean

Is plugin active?

Returns:

  • (Boolean)


42
43
44
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 42

def active?
  @active == true
end

#blank?Boolean

Is an existing plugin

Returns:

  • (Boolean)


47
48
49
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 47

def blank?
  false
end

#require_fileObject

Path of require file



52
53
54
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 52

def require_file
  "#{name}.rb"
end