Skip to content

Instantly share code, notes, and snippets.

@kjlape
Last active April 2, 2020 16:09
Show Gist options
  • Save kjlape/5764700ee3ee5a3da2375164991f571b to your computer and use it in GitHub Desktop.
Save kjlape/5764700ee3ee5a3da2375164991f571b to your computer and use it in GitHub Desktop.
# Vanilla
Thing1.transaction do
Thing2.transaction do
Governor.allowing_malarkey do
Logger.with_context(some: :context) do
Auditor.with_context(some: [:more, :context]) do
do_a_thing
end
end
end
end
end
# Unnested
Nestor
.(Thing1.method(:transaction))
.(Thing2.method(:transaction))
.(Governor.method(:allowing_malarkey))
.(Logger.method(:with_context), some: :context)
.(Auditor.method(:with_context), some: [:more, :context]) do
do_a_thing
end
# Almost definitely doesn't work… Recursion and all that… Haven't tested this one bit. Shame, shame…
class Nestor
def initialize(nestor, nestee, params)
@parent = nestor
@nestee = nestee
@params = params
end
def call(nestee, *params, &block)
Nestor.new(self, nestee, params).tap do |nestor|
nestor.run(&block) if block
end
end
def run(&block)
@parent.run do
@nestee.call(*params) do
block.call
end
end
end
def self.call(nestee, *params)
Nestor.new(nil, nestee, params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment