Class: ROM::Lint::Gateway
Overview
Ensures that a [ROM::Gateway] extension provides datasets through the expected methods
Constant Summary
Constants inherited from Linter
Instance Attribute Summary collapse
-
#gateway ⇒ Object
readonly
The gateway class.
-
#gateway_instance ⇒ Object
readonly
private
Gateway instance used in lint tests.
-
#identifier ⇒ Object
readonly
The gateway identifier e.g.
-
#uri ⇒ Object
readonly
The optional URI.
Instance Method Summary collapse
-
#initialize(identifier, gateway, uri = nil) ⇒ Gateway
constructor
Create a gateway linter.
-
#lint_adapter_reader ⇒ Object
Lint: Ensure
gateway_instance
returns adapter name. -
#lint_dataset_predicate ⇒ Object
Lint: Ensure that
gateway_instance
responds todataset?
. -
#lint_dataset_reader ⇒ Object
Lint: Ensure that
gateway_instance
responds to[]
. -
#lint_gateway_setup ⇒ Object
Lint: Ensure that
gateway
setups up its instance. -
#lint_transaction_support ⇒ Object
Lint: Ensure
gateway_instance
supportstransaction
interface.
Methods inherited from Linter
Constructor Details
#initialize(identifier, gateway, uri = nil) ⇒ Gateway
Create a gateway linter
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
#gateway ⇒ Object (readonly)
The gateway class
18 19 20 |
# File 'lib/rom/lint/gateway.rb', line 18 def gateway @gateway end |
#gateway_instance ⇒ Object (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 |
#identifier ⇒ Object (readonly)
The gateway identifier e.g. :memory
13 14 15 |
# File 'lib/rom/lint/gateway.rb', line 13 def identifier @identifier end |
#uri ⇒ Object (readonly)
The optional URI
23 24 25 |
# File 'lib/rom/lint/gateway.rb', line 23 def uri @uri end |
Instance Method Details
#lint_adapter_reader ⇒ Object
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_predicate ⇒ Object
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_reader ⇒ Object
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_setup ⇒ Object
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_support ⇒ Object
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 |