Class: ROM::Lint::Gateway

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a gateway linter

Parameters:

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

    optional



37
38
39
40
41
42
# File 'core/lib/rom/lint/gateway.rb', line 37

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



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

def gateway
  @gateway
end

#identifierObject (readonly)

The gateway identifier e.g. +:memory+



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

def identifier
  @identifier
end

#uriObject (readonly)

The optional URI



25
26
27
# File 'core/lib/rom/lint/gateway.rb', line 25

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 'core/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?+



68
69
70
71
72
# File 'core/lib/rom/lint/gateway.rb', line 68

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 +[]+



59
60
61
62
63
# File 'core/lib/rom/lint/gateway.rb', line 59

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



47
48
49
50
51
52
53
54
# File 'core/lib/rom/lint/gateway.rb', line 47

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



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

def lint_transaction_support
  result = gateway_instance.transaction { 1 }

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

  gateway_instance.transaction do |t|
    t.rollback!

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