-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccb98ee
commit 07962fc
Showing
6 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resol | ||
class Configuration < Delegator | ||
DEFAULT_RETURN_ENGINE = ReturnEngine::Catch | ||
|
||
class << self | ||
def configure | ||
SmartCore::Initializer::Configuration.configure do |c| | ||
self.configurator = c | ||
yield self | ||
end | ||
end | ||
|
||
def return_engine | ||
@return_engine || DEFAULT_RETURN_ENGINE | ||
end | ||
|
||
def return_engine=(engine) | ||
@return_engine = engine | ||
end | ||
|
||
private | ||
|
||
attr_accessor :configurator | ||
|
||
def method_missing(meth, *args, &block) | ||
if configurator.respond_to?(target) | ||
configurator.__send__(meth, *args, &block) | ||
elsif ::Kernel.method_defined?(meth) || ::Kernel.private_method_defined?(meth) | ||
::Kernel.instance_method(meth).bind_call(self, *args, &block) | ||
else | ||
super(meth, *args, &block) | ||
end | ||
end | ||
|
||
def respond_to_missing?(m, include_private) | ||
configurator.respond_to?(m, include_private) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resol | ||
module ReturnEngine | ||
NOT_EXITED = Object.new.freeze | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resol | ||
module ReturnEngine | ||
module Catch | ||
extend self | ||
|
||
def wrap_call(service) | ||
catch(service) do | ||
yield | ||
NOT_EXITED | ||
end | ||
end | ||
|
||
def uncaught_call?(return_obj) | ||
return_obj == NOT_EXITED | ||
end | ||
|
||
def handle_return(service, data) | ||
throw(service, data) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resol | ||
module ReturnEngine | ||
module Return | ||
extend self | ||
|
||
DataWrapper = Struct.new(:data) | ||
|
||
def wrap_call(_service) | ||
yield | ||
end | ||
|
||
def uncaught_call?(return_obj) | ||
!return_obj.is_a?(DataWrapper) | ||
end | ||
|
||
def handle_return(_service, data) | ||
DataWrapper.new(data) | ||
end | ||
end | ||
end | ||
end |
This file contains 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