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(name, gem_name:, enabled:, prefix: nil) ⇒ Plugin

Returns a new instance of Plugin.



22
23
24
25
26
27
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 22

def initialize(name, gem_name:, enabled:, prefix: nil)
  @name     = name
  @gem_name = gem_name
  @enabled  = enabled
  @prefix   = prefix
end

Instance Attribute Details

#gem_nameObject

Returns the value of attribute gem_name.



20
21
22
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 20

def gem_name
  @gem_name
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 20

def name
  @name
end

#required_fileObject (readonly)

Returns the value of attribute required_file.



20
21
22
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 20

def required_file
  @required_file
end

Instance Method Details

#<=>(other) ⇒ Object



86
87
88
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 86

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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 45

def activate
  begin
    unless active?
      begin
        required_file = variants.shift
        require required_file

        @required_file = required_file
      rescue LoadError
        retry unless variants.blank?

        raise LoadError
      end
    end
  rescue LoadError => e
    warn "Found plugin #{gem_name}, but could not require '#{variants.to_list(last_separator: ' or ')}'"
    warn e
  rescue StandardError => e
    warn "require '#{gem_name}' # Failed, saying: #{e}\n#{e.backtrace.join("\n")}"
  end

  self.active  = true
  self.enabled = true
end

#active?Boolean

Is plugin active?

Returns:

  • (Boolean)


71
72
73
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 71

def active?
  active == true
end

#blank?Boolean

Is an existing plugin

Returns:

  • (Boolean)


81
82
83
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 81

def blank?
  false
end

#disableObject

Disable a plugin. (prevents plugin from being loaded, cannot disable an already activated plugin)



31
32
33
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 31

def disable
  self.enabled = false
end

#enableObject

Enable a plugin. (does not load it immediately but puts on ‘white list’ to be loaded)



37
38
39
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 37

def enable
  self.enabled = true
end

#enabled?Boolean

Is plugin enabled?

Returns:

  • (Boolean)


76
77
78
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 76

def enabled?
  enabled == true
end