Sha256: d419f17223b0349ac04483dd7e928b70ea361b51e4f891dfc600cc56a11bcedf
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
# encoding: utf-8 module FeduxOrgStdlib module GemPlugins class Plugin private attr_accessor :enabled, :active attr_writer :gem_name public attr_reader :name, :gem_name def initialize(name, gem_name:, enabled:) @name = name @gem_name = gem_name @enabled = enabled 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 StandardError => e warn "require '#{gem_name}' # Failed, saying: #{e}" end self.active = true self.enabled = true end # Is plugin active? def active? active == true end # Is plugin enabled? def enabled? enabled == true end # Is an existing plugin def blank? false end end end end
Version data entries
3 entries across 3 versions & 1 rubygems