Class: ROM::Lint::Gateway

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

Overview

Ensures that a [ROM::Gateway] extension provides datasets through the expected methods

Constant Summary

Constants inherited from Linter

Linter::Failure

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Linter

each_lint, #lint

Constructor Details

#initialize(identifier, gateway, uri = nil) ⇒ Gateway

Create a gateway linter

Parameters:

  • identifier (Symbol)
  • gateway (Class)
  • uri (String) (defaults to: nil)

    optional



35
36
37
38
39
40
# File 'lib/rom/lint/gateway.rb', line 35

def initialize(identifier, gateway, uri = nil)
  @identifier = identifier
  @gateway = gateway
  @uri = uri
  @gateway_instance = setup_gateway_instance
end

Instance Attribute Details

#gatewayObject (readonly)

The gateway class



18
19
20
# File 'lib/rom/lint/gateway.rb', line 18

def gateway
  @gateway
end

#gateway_instanceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gateway instance used in lint tests



28
29
30
# File 'lib/rom/lint/gateway.rb', line 28

def gateway_instance
  @gateway_instance
end

#identifierObject (readonly)

The gateway identifier e.g. :memory



13
14
15
# File 'lib/rom/lint/gateway.rb', line 13

def identifier
  @identifier
end

#uriObject (readonly)

The optional URI



23
24
25
# File 'lib/rom/lint/gateway.rb', line 23

def uri
  @uri
end

Instance Method Details

#lint_adapter_readerObject

Lint: Ensure gateway_instance returns adapter name



90
91
92
93
94
95
96
# File 'lib/rom/lint/gateway.rb', line 90

def lint_adapter_reader
  if gateway_instance.adapter != identifier
    complain "#{gateway_instance} must have the adapter identifier set to #{identifier.inspect}"
  end
rescue MissingAdapterIdentifierError
  complain "#{gateway_instance} is missing the adapter identifier"
end

#lint_dataset_predicateObject

Lint: Ensure that gateway_instance responds to dataset?



66
67
68
69
70
# File 'lib/rom/lint/gateway.rb', line 66

def lint_dataset_predicate
  return if gateway_instance.respond_to? :dataset?

  complain "#{gateway_instance} must respond to dataset?"
end

#lint_dataset_readerObject

Lint: Ensure that gateway_instance responds to []



57
58
59
60
61
# File 'lib/rom/lint/gateway.rb', line 57

def lint_dataset_reader
  return if gateway_instance.respond_to? :[]

  complain "#{gateway_instance} must respond to []"
end

#lint_gateway_setupObject

Lint: Ensure that gateway setups up its instance



45
46
47
48
49
50
51
52
# File 'lib/rom/lint/gateway.rb', line 45

def lint_gateway_setup
  return if gateway_instance.instance_of? gateway

  complain <<-STRING
    #{gateway}.setup must return a gateway instance but
    returned #{gateway_instance.inspect}
  STRING
end

#lint_transaction_supportObject

Lint: Ensure gateway_instance supports transaction interface



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rom/lint/gateway.rb', line 75

def lint_transaction_support
  result = gateway_instance.transaction { 1 }

  if result != 1
    complain "#{gateway_instance} must return the result of a transaction block"
  end

  gateway_instance.transaction do |t|
    t.rollback!

    complain "#{gateway_instance} must interrupt a transaction on rollback"
  end
end