lib/roda/endpoints/endpoint/transactions.rb in roda-endpoints-0.3.0 vs lib/roda/endpoints/endpoint/transactions.rb in roda-endpoints-0.3.1
- old
+ new
@@ -8,20 +8,31 @@
class Endpoint
# Namespacing operations, validations, etc.
module Transactions
# @return [Endpoints::Transactions]
def transactions
- endpoint = self
- @transactions ||=
- begin
- transactions = Endpoints::Transactions.new(endpoint: self)
- self.class.transactions.each do |(name, block)|
- transactions.define(name) { instance_exec(endpoint, &block) }
- end
- transactions
- end
+ @transactions ||= Endpoints::Transactions.new(endpoint: self)
yield @transaction if block_given?
@transactions
+ end
+
+ 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
# @param [Symbol, String] name
# @param [Proc] block
def step(name, only: [], **kwargs, &block)