module Roda::Endpoints::Endpoint::Transactions

Namespacing operations, validations, etc.

Public Instance Methods

after(name, **kwargs, &block) click to toggle source
# File lib/roda/endpoints/endpoint/transactions.rb, line 56
def after(name, **kwargs, &block)
  step "after_#{name}", after: name, **kwargs, &block
end
before(name, **kwargs, &block) click to toggle source
# File lib/roda/endpoints/endpoint/transactions.rb, line 52
def before(name, **kwargs, &block)
  step "before_#{name}", before: name, **kwargs, &block
end
perform(operation, *args, **options) click to toggle source

@param [Symbol] operation @param [Array] args @return [Dry::Monads::Either]

# File lib/roda/endpoints/endpoint/transactions.rb, line 63
def perform(operation, *args, **options)
  transactions[operation].call(*args, **options)
end
prepare_transactions!() click to toggle source
# File lib/roda/endpoints/endpoint/transactions.rb, line 18
def prepare_transactions!
  return if @transactions_prepared
  endpoint = self
  self.class.transactions.each do |(name, block)|
    transactions.define(name) do
      instance_exec(endpoint, &block)
    end
  end
  verbs.each do |verb|
    key = "operations.#{ns}.#{verb}"
    next if container.key?(key)
    operation = method(verb)
    container.register key do |*args|
      endpoint.instance_exec(*args, &operation)
    end
  end
  @transactions_prepared = true
end
step(name, only: [], **kwargs, &block) click to toggle source

@param [Symbol, String] name @param [Proc] block

# File lib/roda/endpoints/endpoint/transactions.rb, line 39
def step(name, only: [], **kwargs, &block)
  name = "operations.#{ns}.#{name}"
  container.register(name, &block) if block_given?
  verbs = Array(only).flatten
  verbs.each do |verb|
    result = transactions[verb].insert(container: container, **kwargs) do
      step name
    end
    @transaction = result
  end
  transactions
end
transactions() { |transaction| ... } click to toggle source

@return [Endpoints::Transactions]

# File lib/roda/endpoints/endpoint/transactions.rb, line 12
def transactions
  @transactions ||= Endpoints::Transactions.new(endpoint: self)
  yield @transaction if block_given?
  @transactions
end