Last active
April 2, 2020 16:09
-
-
Save kjlape/5764700ee3ee5a3da2375164991f571b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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