Class: ROM::Lint::Gateway
Overview
Ensures that a [ROM::Gateway] extension provides datasets through the expected methods
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 to +dataset?+.
-
#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+ supports +transaction+ interface.
Constructor Details
#initialize(identifier, gateway, uri = nil) ⇒ Gateway
Create a gateway linter
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
#gateway ⇒ Object (readonly)
The gateway class
20 21 22 |
# File 'core/lib/rom/lint/gateway.rb', line 20 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
30 31 32 |
# File 'core/lib/rom/lint/gateway.rb', line 30 def gateway_instance @gateway_instance end |
#identifier ⇒ Object (readonly)
The gateway identifier e.g. +:memory+
15 16 17 |
# File 'core/lib/rom/lint/gateway.rb', line 15 def identifier @identifier end |
#uri ⇒ Object (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_reader ⇒ Object
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_predicate ⇒ Object
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_reader ⇒ Object
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_setup ⇒ Object
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_support ⇒ Object
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 |