Sha256: a29cb7c69dc50f2a6bd3be8c79860afe6a4bd9e76425a2395c5985a15862d5ab

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Lolcommits
  class GemPlugin
    attr_accessor :name, :gem_name, :spec, :required

    def initialize(name, gem_name, spec)
      @name     = name
      @gem_name = gem_name
      @spec     = spec
      @required = false
    end

    # activate the plugin (require the gem - enables/loads the plugin
    # immediately at point of call if not already required)
    def activate!
      begin
        require gem_path unless required?
      rescue LoadError => e
        warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
        warn e
      rescue => e
        warn "require '#{gem_name}' # Failed, saying: #{e}"
      end

      self.required = true
    end

    alias required? required

    def supported?
      # false if the plugin gem does not support this version of Lolcommits
      lolcommits_version = Gem::Version.new(::Lolcommits::VERSION)
      spec.dependencies.each do |dependency|
        if dependency.name == Lolcommits::GEM_NAME
          return dependency.requirement.satisfied_by?(lolcommits_version)
        end
      end
      true
    end

    private

    def gem_path
      gem_name.gsub(/-|_/, '/')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lolcommits-0.9.3.pre1 lib/lolcommits/gem_plugin.rb