Sha256: f6f340f8eeb5dbcb1778a21b9a5e289b82d12643ad1c7ff9da7d188f7f651769

Contents?: true

Size: 1.48 KB

Versions: 70

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require "metanorma/cli/ui"

module Metanorma
  class Flavor
    SUPPORTED_GEMS = [
      "metanorma-iso",
      "metanorma-iec",
      "metanorma-ietf",
      "metanorma-bipm",
      "metanorma-cc",
      "metanorma-csa",
      "metanorma-iho",
      "metanorma-m3aawg",
      "metanorma-generic",
      "metanorma-standoc",
      "metanorma-un",
      "metanorma-ogc",
      "metanorma-itu",
    ].freeze

    PRIVATE_SUPPORTED_GEMS = [
      "metanorma-ribose",
      "metanorma-mpfa",
      "metanorma-nist",
    ].freeze

    def self.activate
      new.activate
    end

    def self.load_flavors
      new.load_flavors
    end

    def activate
      flavors.each do |flavor_name|
        begin
          gem(flavor_name)
        rescue LoadError, MissingSpecError => _e
          Metanorma::Cli::UI.debug("#{flavor_name} is not present!")
        end
      end
    end

    def load_flavors
      flavors.each do |flavor_name|
        begin
          require(flavor_name)
        rescue LoadError => _e
          gem_loading_error(flavor_name)
        end
      end
    end

    private

    def flavors
      @flavors ||= [SUPPORTED_GEMS + PRIVATE_SUPPORTED_GEMS].flatten.uniq
    end

    def gem_loading_error(flavor_name)
      unless PRIVATE_SUPPORTED_GEMS.include?(flavor_name)
        Metanorma::Cli::UI.error(
          "[metanorma] Error: flavor gem #{flavor_name} not present",
        )
      end
    end
  end
end

# Activate flavors
Metanorma::Flavor.activate

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
metanorma-cli-1.5.11pre lib/metanorma/flavor.rb
metanorma-cli-1.5.10 lib/metanorma/flavor.rb
metanorma-cli-1.5.10pre lib/metanorma/flavor.rb
metanorma-cli-1.5.9 lib/metanorma/flavor.rb
metanorma-cli-1.5.9pre lib/metanorma/flavor.rb
metanorma-cli-1.5.8 lib/metanorma/flavor.rb
metanorma-cli-1.5.8pre lib/metanorma/flavor.rb
metanorma-cli-1.5.7 lib/metanorma/flavor.rb
metanorma-cli-1.5.7pre lib/metanorma/flavor.rb
metanorma-cli-1.5.6 lib/metanorma/flavor.rb
metanorma-cli-1.5.6pre lib/metanorma/flavor.rb
metanorma-cli-1.5.5 lib/metanorma/flavor.rb
metanorma-cli-1.5.5pre lib/metanorma/flavor.rb
metanorma-cli-1.5.4 lib/metanorma/flavor.rb
metanorma-cli-1.5.4pre lib/metanorma/flavor.rb
metanorma-cli-1.5.3 lib/metanorma/flavor.rb
metanorma-cli-1.5.3pre1 lib/metanorma/flavor.rb
metanorma-cli-1.5.3pre lib/metanorma/flavor.rb
metanorma-cli-1.5.2 lib/metanorma/flavor.rb
metanorma-cli-1.5.2pre lib/metanorma/flavor.rb