class Roda::Endpoints::Transactions

The DSL for defining {Transactions transactions} for endpoints.

Attributes

container[R]

@return [Dry::Container::Mixin]

endpoint[R]

@return [Endpoint]

options[R]

@return [{Symbol=>Object}]

Public Class Methods

define() { |new| ... } click to toggle source
# File lib/roda/endpoints/transactions.rb, line 18
def self.define
  yield new
end
new(endpoint:, **options) click to toggle source

@param [Endpoint] endpoint @param [Hash] options

# File lib/roda/endpoints/transactions.rb, line 29
def initialize(endpoint:, **options)
  @endpoint = endpoint
  @container = endpoint.container
  @options = self.class.options
                 .merge(container: endpoint.container)
                 .merge(options)
end
options() click to toggle source

@return [{Symbol=>Object}]

# File lib/roda/endpoints/transactions.rb, line 23
def self.options
  { container: config.container }.merge(config.options)
end

Public Instance Methods

[](shortcut) click to toggle source

@param [Symbol] shortcut

# File lib/roda/endpoints/transactions.rb, line 70
def [](shortcut)
  key = key_for(shortcut)
  container[key]
end
define(shortcut, &block) click to toggle source

@param [Symbol] shortcut @param [Proc] block

# File lib/roda/endpoints/transactions.rb, line 50
def define(shortcut, &block)
  key = key_for(shortcut)
  return if container.key? key
  container.register(
    key,
    Dry.Transaction(
      container: container,
      endpoint: endpoint,
      &block
    )
  )
end
key_for(verb) click to toggle source

@param [Symbol] verb @return [String]

# File lib/roda/endpoints/transactions.rb, line 65
def key_for(verb)
  "transactions.#{endpoint.ns}.#{verb}"
end