Sha256: ce3bf5786d85e8be41835120f85f6c32180a0ecbb42cc61c13525aaefcbbdda3

Contents?: true

Size: 1.71 KB

Versions: 51

Compression:

Stored size: 1.71 KB

Contents

module ROM
  module Lint
    # Base class for building linters that check source code
    #
    # Linters are used by authors of ROM adapters to verify that their
    # integration complies with the ROM api.
    #
    # Most of the time, authors won't need to construct linters directly
    # because the provided test helpers will automatically run when required
    # in tests and specs.
    #
    # @example
    #   require 'rom/lint/spec'
    #
    #
    # @api public
    class Linter
      # A failure raised by +complain+
      Failure = Class.new(StandardError)

      # Iterate over all lint methods
      #
      # @yield [String, ROM::Lint]
      #
      # @api public
      def self.each_lint
        return to_enum unless block_given?
        lints.each { |lint| yield lint, self }
      end

      # Run a lint method
      #
      # @param [String] name
      #
      # @raise [ROM::Lint::Linter::Failure] if linting fails
      #
      # @api public
      def lint(name)
        before_lint
        public_send name
        after_lint
        true # for assertions
      end

      private

      # Return a list a lint methods
      #
      # @return [String]
      #
      # @api private
      def self.lints
        public_instance_methods(true).grep(/^lint_/).map(&:to_s)
      end

      # Raise a failure if a lint verification fails
      #
      # @raise [ROM::Lint::Linter::Failure]
      #
      # @api private
      def complain(*args)
        raise Failure, *args
      end

      # Hook method executed before each lint method run
      #
      # @api private
      def before_lint
      end

      # Hook method executed after each lint method run
      #
      # @api private
      def after_lint
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
rom-core-4.2.1 lib/rom/lint/linter.rb
rom-core-4.2.0 lib/rom/lint/linter.rb
rom-core-4.1.2 lib/rom/lint/linter.rb
rom-core-4.1.1 lib/rom/lint/linter.rb
rom-core-4.1.0 lib/rom/lint/linter.rb
rom-core-4.0.2 lib/rom/lint/linter.rb
rom-core-4.0.1 lib/rom/lint/linter.rb
rom-3.3.3 lib/rom/lint/linter.rb
rom-core-4.0.0 lib/rom/lint/linter.rb
rom-3.3.2 lib/rom/lint/linter.rb
rom-core-4.0.0.rc2 lib/rom/lint/linter.rb
rom-core-4.0.0.rc1 lib/rom/lint/linter.rb
rom-core-4.0.0.beta3 lib/rom/lint/linter.rb
rom-3.3.1 lib/rom/lint/linter.rb
rom-core-4.0.0.beta2 lib/rom/lint/linter.rb
rom-3.3.0 lib/rom/lint/linter.rb
rom-core-4.0.0.beta1 lib/rom/lint/linter.rb
rom-3.2.3 lib/rom/lint/linter.rb
rom-3.2.2 lib/rom/lint/linter.rb
rom-3.2.1 lib/rom/lint/linter.rb