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.17 lib/metanorma/flavor.rb
metanorma-cli-1.5.17.pre lib/metanorma/flavor.rb
metanorma-cli-1.5.16 lib/metanorma/flavor.rb
metanorma-cli-1.5.16.pre.pre lib/metanorma/flavor.rb
metanorma-cli-1.5.15 lib/metanorma/flavor.rb
metanorma-cli-1.5.15.pre.alpha.2 lib/metanorma/flavor.rb
metanorma-cli-1.5.15.pre.alpha lib/metanorma/flavor.rb
metanorma-cli-1.5.15.pre.pre2 lib/metanorma/flavor.rb
metanorma-cli-1.5.15pre2 lib/metanorma/flavor.rb
metanorma-cli-1.5.15pre lib/metanorma/flavor.rb
metanorma-cli-1.5.15pre1 lib/metanorma/flavor.rb
metanorma-cli-1.5.14 lib/metanorma/flavor.rb
metanorma-cli-1.5.14pre1 lib/metanorma/flavor.rb
metanorma-cli-1.5.14pre lib/metanorma/flavor.rb
metanorma-cli-1.5.13 lib/metanorma/flavor.rb
metanorma-cli-1.5.13pre lib/metanorma/flavor.rb
metanorma-cli-1.5.12 lib/metanorma/flavor.rb
metanorma-cli-1.5.12pre1 lib/metanorma/flavor.rb
metanorma-cli-1.5.12pre lib/metanorma/flavor.rb
metanorma-cli-1.5.11 lib/metanorma/flavor.rb