Skip to content

Commit

Permalink
Fixes and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherRegularDude committed Nov 13, 2023
1 parent 07962fc commit b83d496
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
resol (0.8.0)
resol (0.9.0)
smart_initializer (~> 0.7)

GEM
Expand Down Expand Up @@ -36,7 +36,7 @@ GEM
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
qonfig (0.27.0)
qonfig (0.28.0)
rack (2.2.3)
rainbow (3.1.1)
rake (13.0.6)
Expand Down Expand Up @@ -95,12 +95,12 @@ GEM
simplecov-html (0.12.3)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_engine (0.12.0)
smart_initializer (0.9.0)
smart_engine (0.17.0)
smart_initializer (0.11.1)
qonfig (~> 0.24)
smart_engine (~> 0.11)
smart_types (~> 0.4)
smart_types (0.7.0)
smart_engine (~> 0.16)
smart_types (~> 0.8)
smart_types (0.8.0)
smart_engine (~> 0.11)
symbiont-ruby (0.7.0)
thor (1.2.1)
Expand Down
3 changes: 2 additions & 1 deletion lib/resol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
require "smart_core/initializer"

require_relative "resol/version"
require_relative "resol/return_engine"
require_relative "resol/configuration"
require_relative "resol/service"

module Resol
Configuration = SmartCore::Initializer::Configuration
end
17 changes: 10 additions & 7 deletions lib/resol/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

module Resol
class Configuration < Delegator
class Configuration
DEFAULT_RETURN_ENGINE = ReturnEngine::Catch

class << self
def configure
SmartCore::Initializer::Configuration.configure do |c|
self.configurator = c
self.smartcore_config = c
yield self
self.smartcore_config = nil
end
end

Expand All @@ -22,20 +23,22 @@ def return_engine=(engine)

private

attr_accessor :configurator
attr_accessor :smartcore_config

def method_missing(meth, *args, &block)
if configurator.respond_to?(target)
configurator.__send__(meth, *args, &block)
# rubocop:disable Style/SafeNavigation
if smartcore_config && smartcore_config.respond_to?(meth)
# rubocop:enable Style/SafeNavigation
smartcore_config.__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)
def respond_to_missing?(meth, include_private)
smartcore_config.respond_to?(meth, include_private)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/resol/return_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ module Resol
module ReturnEngine
NOT_EXITED = Object.new.freeze
end

require_relative "return_engine/catch"
require_relative "return_engine/return"
end
6 changes: 5 additions & 1 deletion lib/resol/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def call(*args, **kwargs, &block)
Resol::Failure(e)
end

def return_engine
Resol::Configuration.return_engine
end

def call!(...)
call(...).value_or { |error| raise error }
end
Expand All @@ -77,7 +81,7 @@ def fail!(code, data = nil)

def success!(data = nil)
check_performing do
return_engine.handle_return(self, Result.new(data))
self.class.return_engine.handle_return(self, Result.new(data))
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/resol/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Resol
VERSION = "0.8.0"
VERSION = "0.9.0"
end
22 changes: 22 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

RSpec.describe Resol::Configuration do
around do |example|
example.call

described_class.configure do |c|
c.auto_cast = true
c.return_engine = described_class::DEFAULT_RETURN_ENGINE
end
end

it "delegates configuration" do
described_class.configure do |c|
c.auto_cast = false
c.return_engine = Resol::ReturnEngine::Return
end

expect(SmartCore::Initializer::Configuration.config[:auto_cast]).to eq(false)
expect(described_class.return_engine).to eq(Resol::ReturnEngine::Return)
end
end

0 comments on commit b83d496

Please sign in to comment.