Sha256: 36e6cc09386f9fe3d0fae40f949226e1aa4692167d8009001f210361441477f8

Contents?: true

Size: 1.62 KB

Versions: 23

Compression:

Stored size: 1.62 KB

Contents

module Metanorma
  class Compile
    def validate_options(options)
      validate_type(options)
      validate_format(options)
    end

    def validate_type(options)
      unless options[:type]
        Util.log("[metanorma] Error: Please specify a standard type: "\
                 "#{@registry.supported_backends}.", :fatal)
      end
      stdtype = options[:type].to_sym
      load_flavor(stdtype)
    end

    def validate_format(options)
      unless options[:format] == :asciidoc
        Util.log("[metanorma] Error: Only source file format currently "\
                 "supported is 'asciidoc'.", :fatal)
      end
    end

    private

    def load_flavor(stdtype)
      flavor = "metanorma-#{stdtype}"
      unless @registry.supported_backends.include? stdtype
        Util.log("[metanorma] Info: Loading `#{flavor}` gem "\
                 "for standard type `#{stdtype}`.", :info)
      end
      require_flavor(flavor, stdtype)
      unless @registry.supported_backends.include? stdtype
        Util.log("[metanorma] Error: The `#{flavor}` gem "\
                 "still doesn't support `#{stdtype}`. Exiting.", :fatal)
      end
    end

    def require_flavor(flavor, stdtype)
      require flavor
      Util.log("[metanorma] Info: gem `#{flavor}` loaded.", :info)
    rescue Gem::ConflictError
      Util.log("[metanorma] Error: Couldn't resolve dependencies for "\
               "`metanorma-#{stdtype}`, Please add it to your Gemfile "\
               "and run bundle install first", :fatal)
    rescue LoadError
      Util.log("[metanorma] Error: loading gem `#{flavor}` "\
               "failed. Exiting.", :fatal)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
metanorma-1.4.10 lib/metanorma/compile_validate.rb
metanorma-1.4.9 lib/metanorma/compile_validate.rb
metanorma-1.4.8 lib/metanorma/compile_validate.rb
metanorma-1.4.7.1 lib/metanorma/compile_validate.rb
metanorma-1.4.7 lib/metanorma/compile_validate.rb
metanorma-1.4.6 lib/metanorma/compile_validate.rb
metanorma-1.4.5 lib/metanorma/compile_validate.rb
metanorma-1.4.4 lib/metanorma/compile_validate.rb
metanorma-1.4.3 lib/metanorma/compile_validate.rb
metanorma-1.4.2 lib/metanorma/compile_validate.rb
metanorma-1.4.1 lib/metanorma/compile_validate.rb
metanorma-1.4.0 lib/metanorma/compile_validate.rb
metanorma-1.3.12 lib/metanorma/compile_validate.rb
metanorma-1.3.11 lib/metanorma/compile_validate.rb
metanorma-1.3.10 lib/metanorma/compile_validate.rb
metanorma-1.3.9.1 lib/metanorma/compile_validate.rb
metanorma-1.3.9 lib/metanorma/compile_validate.rb
metanorma-1.3.8 lib/metanorma/compile_validate.rb
metanorma-1.3.7 lib/metanorma/compile_validate.rb
metanorma-1.3.6 lib/metanorma/compile_validate.rb