Class: Slugforge::SluginManager::Slugin

Inherits:
Object
  • Object
show all
Defined in:
lib/slugforge/slugins.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, gem_name, spec, enabled) ⇒ Slugin

Returns a new instance of Slugin.



22
23
24
# File 'lib/slugforge/slugins.rb', line 22

def initialize(name, gem_name, spec, enabled)
  @name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
end

Instance Attribute Details

#activeObject Also known as: active?

Returns the value of attribute active.



20
21
22
# File 'lib/slugforge/slugins.rb', line 20

def active
  @active
end

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



20
21
22
# File 'lib/slugforge/slugins.rb', line 20

def enabled
  @enabled
end

#gem_nameObject

Returns the value of attribute gem_name.



20
21
22
# File 'lib/slugforge/slugins.rb', line 20

def gem_name
  @gem_name
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/slugforge/slugins.rb', line 20

def name
  @name
end

#specObject

Returns the value of attribute spec.



20
21
22
# File 'lib/slugforge/slugins.rb', line 20

def spec
  @spec
end

Instance Method Details

#activate!(config) ⇒ Object

Activate the slugin (run its defined activation method) Does not reactivate if already active.



57
58
59
60
61
62
63
64
65
# File 'lib/slugforge/slugins.rb', line 57

def activate!(config)
  return if active?

  if klass = slugin_class
    klass.activate(config) if klass.respond_to?(:activate)
  end

  self.active = true
end

#disable!Object

Disable a slugin. (prevents slugin from being loaded, cannot disable an already activated slugin)



28
29
30
# File 'lib/slugforge/slugins.rb', line 28

def disable!
  self.enabled = false
end

#enable!Object

Enable a slugin. (does not load it immediately but puts on ‘white list’ to be loaded)



34
35
36
# File 'lib/slugforge/slugins.rb', line 34

def enable!
  self.enabled = true
end

#load!Object

Load the slugin (require the gem - enables/loads the slugin immediately at point of call, even if slugin is disabled) Does not reload slugin if it’s already loaded.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/slugforge/slugins.rb', line 42

def load!
  begin
    require gem_name
  rescue LoadError => e
    warn "Found slugin #{gem_name}, but could not require '#{gem_name}.rb'"
    warn e
  rescue => e
    warn "require '#{gem_name}' failed, saying: #{e}"
  end

  self.enabled = true
end