Class: ROM::Lint::EnumerableDataset

Inherits:
Linter
  • Object
show all
Defined in:
core/lib/rom/lint/enumerable_dataset.rb

Overview

Ensures that a [ROM::EnumerableDataset] extension correctly yields arrays and tuples

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset, data) ⇒ EnumerableDataset

Create a linter for EnumerableDataset

Parameters:

  • dataset (EnumerableDataset)

    the linted subject

  • data (Object)

    the expected data



28
29
30
31
# File 'core/lib/rom/lint/enumerable_dataset.rb', line 28

def initialize(dataset, data)
  @dataset = dataset
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

The expected data



20
21
22
# File 'core/lib/rom/lint/enumerable_dataset.rb', line 20

def data
  @data
end

#datasetObject (readonly)

The linted subject



15
16
17
# File 'core/lib/rom/lint/enumerable_dataset.rb', line 15

def dataset
  @dataset
end

Instance Method Details

#lint_eachObject

Lint: Ensure that +dataset+ yield tuples via +each+



36
37
38
39
40
41
42
43
44
# File 'core/lib/rom/lint/enumerable_dataset.rb', line 36

def lint_each
  result = []
  dataset.each do |tuple|
    result << tuple
  end
  return if result == data

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

#lint_to_aObject

Lint: Ensure that +dataset+'s array equals to expected +data+



49
50
51
52
53
# File 'core/lib/rom/lint/enumerable_dataset.rb', line 49

def lint_to_a
  return if dataset.to_a == data

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