# encoding: utf-8 module FeduxOrgStdlib module Plugins class Plugin attr_accessor :name, :gem_name, :enabled, :spec, :active def initialize(name, gem_name, spec, enabled) @name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec end # Disable a plugin. (prevents plugin from being loaded, cannot # disable an already activated plugin) def disable! self.enabled = false end # Enable a plugin. (does not load it immediately but puts on # 'white list' to be loaded) def enable! self.enabled = true end # 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. 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 => e warn "require '#{gem_name}' # Failed, saying: #{e}" end self.active = true self.enabled = true end alias active? active alias enabled? enabled end end end