Class: Lolcommits::GemPlugin
- Inherits:
-
Object
- Object
- Lolcommits::GemPlugin
- Defined in:
- lib/lolcommits/gem_plugin.rb
Instance Attribute Summary collapse
-
#gem_spec ⇒ Object
Returns the value of attribute gem_spec.
-
#required ⇒ Object
(also: #required?)
Returns the value of attribute required.
Instance Method Summary collapse
-
#activate! ⇒ Object
activate the plugin (require the gem - enables/loads the plugin immediately at point of call if not already required).
- #gem_name ⇒ Object
-
#initialize(gem_spec) ⇒ GemPlugin
constructor
A new instance of GemPlugin.
- #name ⇒ Object
- #plugin_instance(runner) ⇒ Object
- #plugin_klass ⇒ Object
- #supported? ⇒ Boolean
Constructor Details
#initialize(gem_spec) ⇒ GemPlugin
Returns a new instance of GemPlugin.
5 6 7 |
# File 'lib/lolcommits/gem_plugin.rb', line 5 def initialize(gem_spec) @gem_spec = gem_spec end |
Instance Attribute Details
#gem_spec ⇒ Object
Returns the value of attribute gem_spec.
3 4 5 |
# File 'lib/lolcommits/gem_plugin.rb', line 3 def gem_spec @gem_spec end |
#required ⇒ Object Also known as: required?
Returns the value of attribute required.
3 4 5 |
# File 'lib/lolcommits/gem_plugin.rb', line 3 def required @required end |
Instance Method Details
#activate! ⇒ Object
activate the plugin (require the gem - enables/loads the plugin immediately at point of call if not already required)
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lolcommits/gem_plugin.rb', line 11 def activate! begin require gem_path unless required? rescue LoadError => e warn "Found plugin #{name}, but could not require gem '#{gem_name}'" warn e rescue StandardError => e warn "require gem '#{gem_name}' failed with: #{e}" end @required = true end |
#gem_name ⇒ Object
47 48 49 |
# File 'lib/lolcommits/gem_plugin.rb', line 47 def gem_name gem_spec.name end |
#name ⇒ Object
51 52 53 |
# File 'lib/lolcommits/gem_plugin.rb', line 51 def name gem_name.split("-", 2).last end |
#plugin_instance(runner) ⇒ Object
43 44 45 |
# File 'lib/lolcommits/gem_plugin.rb', line 43 def plugin_instance(runner) plugin_klass.new(runner: runner, config: runner.config.yaml[name], name: name) end |
#plugin_klass ⇒ Object
37 38 39 40 41 |
# File 'lib/lolcommits/gem_plugin.rb', line 37 def plugin_klass self.class.const_get(plugin_klass_name) rescue StandardError => e warn "failed to load constant from plugin gem '#{plugin_klass_name}: #{e}'" end |
#supported? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lolcommits/gem_plugin.rb', line 26 def supported? # false if the plugin gem does not support this version of Lolcommits lolcommits_version = Gem::Version.new(::Lolcommits::VERSION) gem_spec.dependencies.each do |dependency| if dependency.name == Lolcommits::GEM_NAME return dependency.requirement.satisfied_by?(lolcommits_version) end end true end |