Sha256: 716ba278dfd18e900595b2690682fd90ec4028b2cdfceb5b1e69b862de4751bf

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'rom/lint/linter'

module ROM
  module Lint
    # Ensures that a [ROM::EnumerableDataset] extension correctly yields
    # arrays and tuples
    #
    # @api public
    class EnumerableDataset < ROM::Lint::Linter
      # The linted subject
      #
      # @api public
      attr_reader :dataset

      # The expected data
      #
      # @api public
      attr_reader :data

      # Create a linter for EnumerableDataset
      #
      # @param [EnumerableDataset] dataset the linted subject
      # @param [Object] data the expected data
      #
      # @api public
      def initialize(dataset, data)
        @dataset = dataset
        @data = data
      end

      # Lint: Ensure that +dataset+ yield tuples via +each+
      #
      # @api public
      def lint_each
        result = []
        dataset.each do |tuple|
          result << tuple
        end
        return if result == data

        complain "#{dataset.class}#each must yield tuples"
      end

      # Lint: Ensure that +dataset+'s array equals to expected +data+
      #
      # @api public
      def lint_to_a
        return if dataset.to_a == data

        complain "#{dataset.class}#to_a must cast dataset to an array"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/lint/enumerable_dataset.rb
rom-core-5.3.1 lib/rom/lint/enumerable_dataset.rb
rom-core-5.3.0 lib/rom/lint/enumerable_dataset.rb
rom-core-5.2.6 lib/rom/lint/enumerable_dataset.rb
rom-core-5.2.5 lib/rom/lint/enumerable_dataset.rb
rom-core-5.2.4 lib/rom/lint/enumerable_dataset.rb
rom-core-5.2.3 lib/rom/lint/enumerable_dataset.rb
rom-core-5.2.2 lib/rom/lint/enumerable_dataset.rb
rom-core-5.2.1 lib/rom/lint/enumerable_dataset.rb
rom-core-5.1.2 lib/rom/lint/enumerable_dataset.rb
rom-core-5.1.1 lib/rom/lint/enumerable_dataset.rb
rom-core-5.1.0 lib/rom/lint/enumerable_dataset.rb
rom-core-5.0.2 lib/rom/lint/enumerable_dataset.rb
rom-core-5.0.1 lib/rom/lint/enumerable_dataset.rb
rom-core-5.0.0 lib/rom/lint/enumerable_dataset.rb