class ROM::Lint::Gateway

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

@api public

Attributes

gateway[R]

The gateway class

@api public

gateway_instance[R]

Gateway instance used in lint tests

@api private

identifier[R]

The gateway identifier e.g. :memory

@api public

uri[R]

The optional URI

@api public

Public Class Methods

new(identifier, gateway, uri = nil) click to toggle source

Create a gateway linter

@param [Symbol] identifier @param [Class] gateway @param [String] uri optional

# File 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

Public Instance Methods

lint_adapter_reader() click to toggle source

Lint: Ensure gateway_instance returns adapter name

# 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_predicate() click to toggle source

Lint: Ensure that gateway_instance responds to dataset?

@api public

# File 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_reader() click to toggle source

Lint: Ensure that gateway_instance responds to []

@api public

# File 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_setup() click to toggle source

Lint: Ensure that gateway setups up its instance

@api public

# File 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_support() click to toggle source

Lint: Ensure gateway_instance supports transaction interface

@api public

# File 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

Private Instance Methods

after_lint() click to toggle source

Run Gateway#disconnect

@api private

Calls superclass method ROM::Lint::Linter#after_lint
# File lib/rom/lint/gateway.rb, line 114
def after_lint
  super
  gateway_instance.disconnect
end
setup_gateway_instance() click to toggle source

Setup gateway instance

@api private

# File lib/rom/lint/gateway.rb, line 103
def setup_gateway_instance
  if uri
    ROM::Gateway.setup(identifier, uri)
  else
    ROM::Gateway.setup(identifier)
  end
end