Skip to content

Commit

Permalink
Fix bug, where the block was not transferred when the instance was split
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherRegularDude committed Dec 16, 2024
1 parent eb9d721 commit cb905b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/resol/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Resol
module Plugins
PLUGINS_PATH = Pathname("resol/plugins")

class Manager
def self.resolve_module(module_name)
Plugins.const_get(module_name)
Expand Down
6 changes: 3 additions & 3 deletions lib/resol/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def plugin(...)
manager.plugin(self, ...)
end

def call(...)
service = build(...)
def call(*args, **kwargs, &)
service = build(*args, **kwargs)

result = handle_catch(service) do
service.instance_variable_set(:@__performing__, true)
__run_callbacks__(service)
service.call
service.call(&)
end
return Resol::Success(result.data) if service.__result_method__called__

Expand Down
13 changes: 13 additions & 0 deletions spec/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def call
end
end

class YieldingService < SmartService
def call
success!(yield)
end
end

class PluginSuccessService < ReturnEngineService
def call
success!(:success_result)
Expand Down Expand Up @@ -243,6 +249,13 @@ def call
expect { HackyService.call!(0) }.to raise_error(Resol::Service::InvalidCommandCall)
end
end

context "when block passed to the service" do
it "yields block" do
result = YieldingService.call! { "kek" }
expect(result).to eq("kek")
end
end
end

context "with Return on success plugin" do
Expand Down

0 comments on commit cb905b5

Please sign in to comment.