Class: FeduxOrgStdlib::GemPlugins::Plugin
- Inherits:
-
Object
- Object
- FeduxOrgStdlib::GemPlugins::Plugin
- Defined in:
- lib/fedux_org_stdlib/gem_plugins/plugin.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#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:) ⇒ Plugin
constructor
A new instance of Plugin.
Constructor Details
#initialize(name, gem_name:, enabled:) ⇒ Plugin
Returns a new instance of Plugin.
14 15 16 17 18 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 14 def initialize(name, gem_name:, enabled:) @name = name @gem_name = gem_name @enabled = enabled end |
Instance Attribute Details
#name ⇒ Object (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 |
Instance Method Details
#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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 36 def activate begin if !active? begin require gem_name rescue LoadError require gem_name.gsub(/-/, '/') end end rescue LoadError => e warn "Found plugin #{gem_name}, but could not require '#{gem_name}' or '#{gem_name.gsub(/-/, '/')}'" warn e rescue StandardError => e warn "require '#{gem_name}' # Failed, saying: #{e}" end self.active = true self.enabled = true end |
#active? ⇒ Boolean
Is plugin active?
57 58 59 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 57 def active? active == true end |
#blank? ⇒ Boolean
Is an existing plugin
67 68 69 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 67 def blank? false end |
#disable ⇒ Object
Disable a plugin. (prevents plugin from being loaded, cannot disable an already activated plugin)
22 23 24 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 22 def disable self.enabled = false end |
#enable ⇒ Object
Enable a plugin. (does not load it immediately but puts on ‘white list’ to be loaded)
28 29 30 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 28 def enable self.enabled = true end |
#enabled? ⇒ Boolean
Is plugin enabled?
62 63 64 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 62 def enabled? enabled == true end |