Class: FeduxOrgStdlib::GemPlugins::Plugin
- Inherits:
-
Object
- Object
- FeduxOrgStdlib::GemPlugins::Plugin
- Defined in:
- lib/fedux_org_stdlib/gem_plugins/plugin.rb
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#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.
15 16 17 18 19 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 15 def initialize(name, gem_name:, enabled:) @name = name @gem_name = gem_name @enabled = enabled end |
Instance Attribute Details
#gem_name ⇒ Object
Returns the value of attribute gem_name.
13 14 15 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 13 def gem_name @gem_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 13 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 37 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?
58 59 60 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 58 def active? active == true end |
#blank? ⇒ Boolean
Is an existing plugin
68 69 70 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 68 def blank? false end |
#disable ⇒ Object
Disable a plugin. (prevents plugin from being loaded, cannot disable an already activated plugin)
23 24 25 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 23 def disable self.enabled = false end |
#enable ⇒ Object
Enable a plugin. (does not load it immediately but puts on ‘white list’ to be loaded)
29 30 31 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 29 def enable self.enabled = true end |
#enabled? ⇒ Boolean
Is plugin enabled?
63 64 65 |
# File 'lib/fedux_org_stdlib/gem_plugins/plugin.rb', line 63 def enabled? enabled == true end |