Sha256: c7f104f45a488bee26c318b5e5a2d636ba6da0af2a30639c0e69c6168641b3a6

Contents?: true

Size: 1006 Bytes

Versions: 15

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

module SlimLint
  class NoSuchLinter < StandardError; end

  # Stores all defined linters.
  module LinterRegistry
    @linters = []

    class << self
      # List of all registered linters.
      attr_reader :linters

      # Executed when a linter includes the {LinterRegistry} module.
      #
      # This results in the linter being registered with the registry.
      #
      # @param subclass [Class]
      def included(subclass)
        @linters << subclass
      end

      # Return a list of {SlimLint::Linter} {Class}es corresponding to the
      # specified list of names.
      #
      # @param linter_names [Array<String>]
      # @return [Array<Class>]
      def extract_linters_from(linter_names)
        linter_names.map do |linter_name|
          begin
            SlimLint::Linter.const_get(linter_name)
          rescue NameError
            raise NoSuchLinter, "Linter #{linter_name} does not exist"
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
slim_lint-0.24.0 lib/slim_lint/linter_registry.rb
slim_lint-0.23.0 lib/slim_lint/linter_registry.rb
slim_lint-0.22.1 lib/slim_lint/linter_registry.rb
slim_lint-0.22.0 lib/slim_lint/linter_registry.rb
slim_lint-0.21.1 lib/slim_lint/linter_registry.rb
slim_lint-0.21.0 lib/slim_lint/linter_registry.rb
slim_lint-0.20.2 lib/slim_lint/linter_registry.rb
slim_lint-0.20.1 lib/slim_lint/linter_registry.rb
slim_lint-0.20.0 lib/slim_lint/linter_registry.rb
slim_lint-0.19.0 lib/slim_lint/linter_registry.rb
slim_lint-0.18.0 lib/slim_lint/linter_registry.rb
slim_lint-0.17.1 lib/slim_lint/linter_registry.rb
slim_lint-0.17.0 lib/slim_lint/linter_registry.rb
slim_lint-0.16.1 lib/slim_lint/linter_registry.rb
slim_lint-0.16.0 lib/slim_lint/linter_registry.rb