Class: FeduxOrgStdlib::GemPlugins::Plugin
- Inherits:
-
Object
- Object
- FeduxOrgStdlib::GemPlugins::Plugin
- Includes:
- Comparable
- Defined in:
- lib/fedux_org_stdlib/gem_plugins/plugin.rb
Overview
Plugin
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required_file ⇒ Object
readonly
Returns the value of attribute required_file.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#activate ⇒ Object
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.
-
#active? ⇒ Boolean
Is plugin active?.
-
#blank? ⇒ Boolean
Is an existing plugin.
-
#disable ⇒ Object
Disable a plugin.
-
#enable ⇒ Object
Enable a plugin.
-
#enabled? ⇒ Boolean
Is plugin enabled?.
-
#initialize(name, gem_name:, enabled:, prefix: nil) ⇒ Plugin
constructor
A new instance of Plugin.
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_name ⇒ Object
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 |
#name ⇒ Object (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_file ⇒ Object (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 |
#activate ⇒ Object
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?
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
81 82 83 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 81 def blank? false end |
#disable ⇒ Object
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 |
#enable ⇒ Object
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?
76 77 78 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 76 def enabled? enabled == true end |