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.
7 8 9 |
# File 'lib/lolcommits/gem_plugin.rb', line 7 def initialize(gem_spec) @gem_spec = gem_spec end |
Instance Attribute Details
#gem_spec ⇒ Object
Returns the value of attribute gem_spec.
5 6 7 |
# File 'lib/lolcommits/gem_plugin.rb', line 5 def gem_spec @gem_spec end |
#required ⇒ Object Also known as: required?
Returns the value of attribute required.
5 6 7 |
# File 'lib/lolcommits/gem_plugin.rb', line 5 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)
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lolcommits/gem_plugin.rb', line 13 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
49 50 51 |
# File 'lib/lolcommits/gem_plugin.rb', line 49 def gem_name gem_spec.name end |
#name ⇒ Object
53 54 55 |
# File 'lib/lolcommits/gem_plugin.rb', line 53 def name gem_name.split('-', 2).last end |
#plugin_instance(runner) ⇒ Object
45 46 47 |
# File 'lib/lolcommits/gem_plugin.rb', line 45 def plugin_instance(runner) plugin_klass.new(runner: runner, config: runner.config.yaml[name], name: name) end |
#plugin_klass ⇒ Object
39 40 41 42 43 |
# File 'lib/lolcommits/gem_plugin.rb', line 39 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
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lolcommits/gem_plugin.rb', line 28 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 |