Skip to content

Commit

Permalink
feat(can_have_connected_steps): start to use can_have_connected_steps…
Browse files Browse the repository at this point in the history
… by default
  • Loading branch information
marian13 committed Feb 29, 2024
1 parent 4d5f409 commit 16fb5e2
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 43 deletions.
37 changes: 35 additions & 2 deletions lib/convenient_service/service/configs/minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ module Minimal
use ConvenientService::Plugins::Service::HasJSendResult::Concern

use ConvenientService::Plugins::Service::CanHaveSteps::Concern
use ConvenientService::Plugins::Service::CanHaveSequentialSteps::Concern
use ConvenientService::Plugins::Service::CanHaveConnectedSteps::Concern
end

##
# TODO: Move `NormalizesEnv` inside `Core`.
#
middlewares :initialize do
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware
end
Expand All @@ -71,7 +74,7 @@ module Minimal

use ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware

use ConvenientService::Plugins::Service::CanHaveSequentialSteps::Middleware
use ConvenientService::Plugins::Service::CanHaveConnectedSteps::Middleware
end

middlewares :step do
Expand Down Expand Up @@ -100,6 +103,36 @@ module Minimal
use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
end

middlewares :not_step, scope: :class do
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware

use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
end

middlewares :and_step, scope: :class do
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware

use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
end

middlewares :and_not_step, scope: :class do
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware

use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
end

middlewares :or_step, scope: :class do
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware

use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
end

middlewares :or_not_step, scope: :class do
use ConvenientService::Plugins::Common::NormalizesEnv::Middleware

use ConvenientService::Plugins::Service::CanHaveMethodSteps::Middleware
end

class self::Internals
include Core

Expand Down
10 changes: 10 additions & 0 deletions lib/convenient_service/service/configs/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ module Standard
use ConvenientService::Plugins::Common::EnsuresNegatedJSendResult::Middleware
end

##
# TODO:
# `after :step do |step|` is executed after step result is calculated.
# This completely makes sence and is useful for debugging for example.
#
# But `before :step do` is alos executed after step result is calculated.
# That confuses the end-users a lot.
# Probably a dedicated plugin is needed?
# Or to forbid `before :step do`?
#
middlewares :step do
use ConvenientService::Plugins::Common::HasCallbacks::Middleware
use ConvenientService::Plugins::Common::HasAroundCallbacks::Middleware
Expand Down
8 changes: 8 additions & 0 deletions lib/convenient_service/service/configs/standard/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ module V1
use ConvenientService::Plugins::Common::HasAroundCallbacks::Concern

use ConvenientService::Plugins::Service::HasMermaidFlowchart::Concern

replace \
ConvenientService::Plugins::Service::CanHaveConnectedSteps::Concern,
ConvenientService::Plugins::Service::CanHaveSequentialSteps::Concern
end

middlewares :initialize do
Expand Down Expand Up @@ -61,6 +65,10 @@ module V1
insert_before \
ConvenientService::Plugins::Service::RaisesOnNotResultReturnValue::Middleware,
ConvenientService::Plugins::Service::SetsParentToForeignResult::Middleware

replace \
ConvenientService::Plugins::Service::CanHaveConnectedSteps::Middleware,
ConvenientService::Plugins::Service::CanHaveSequentialSteps::Middleware
end

middlewares :step do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Concern
# @param kwargs [Hash{Symbol => Object}]
# @return [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base]
#
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
#
def step(*args, **kwargs)
previous_expression = steps.expression

Expand Down Expand Up @@ -44,6 +46,7 @@ def step(*args, **kwargs)
#
# @note `not` from `not_step` has a similar precedence as Ruby's `!`.
# @note `not_step` is a rought equivalent of `!step`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def not_step(*args, **kwargs)
Expand Down Expand Up @@ -77,6 +80,7 @@ def not_step(*args, **kwargs)
#
# @note `and` from `and_step` has a similar precedence as Ruby's `&&`.
# @note `and_step` is a rought equivalent of `&& step`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def and_step(*args, **kwargs)
Expand Down Expand Up @@ -105,6 +109,7 @@ def and_step(*args, **kwargs)
# @note `and` from `and_step` has a similar precedence as Ruby's `&&`.
# @note `not` from `and_not_step` has a similar precedence as Ruby's `!`.
# @note `and_not_step` is a rought equivalent of `&& !step`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def and_not_step(*args, **kwargs)
Expand Down Expand Up @@ -134,6 +139,7 @@ def and_not_step(*args, **kwargs)
#
# @note `or` from `or_step` has a similar precedence as Ruby's `||`.
# @note `or_step` is a rought equivalent of `|| step`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
# @internal
Expand Down Expand Up @@ -175,6 +181,7 @@ def or_step(*args, **kwargs)
# @note `or` from `or_not_step` has a similar precedence as Ruby's `||`.
# @note `not` from `or_not_step` has a similar precedence as Ruby's `!`.
# @note `or_not_step` is a rought equivalent of `|| !step`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
# @internal
Expand Down Expand Up @@ -216,6 +223,7 @@ def or_not_step(*args, **kwargs)
#
# @note `group` has a similar precedence as Ruby's `()`.
# @note `group` is a rought equivalent of `()`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def group(&block)
Expand Down Expand Up @@ -249,6 +257,7 @@ def group(&block)
# @note `not` from `not_group` has a similar precedence as Ruby's `!`.
# @note `group` from `not_group` has a similar precedence as Ruby's `()`.
# @note `not_group` is a rought equivalent of `!()`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def not_group(&block)
Expand Down Expand Up @@ -286,6 +295,7 @@ def not_group(&block)
# @note `and` from `and_group` has a similar precedence as Ruby's `&&`.
# @note `group` from `and_group` has a similar precedence as Ruby's `()`.
# @note `not_group` is a rought equivalent of `&& ()`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def and_group(&block)
Expand Down Expand Up @@ -318,6 +328,7 @@ def and_group(&block)
# @note `not` from `and_not_group` has a similar precedence as Ruby's `!`.
# @note `group` from `and_not_group` has a similar precedence as Ruby's `()`.
# @note `and_not_group` is a rought equivalent of `&& !()`.
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
def and_not_group(&block)
Expand Down Expand Up @@ -348,14 +359,15 @@ def and_not_group(&block)
# @param block [Proc, nil]
# @return [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base]
#
# @internal
# NOTE: Decomposing of the `and` expression is needed to make its priority higher.
#
# @note `or` from `or_group` has a similar precedence as Ruby's `||`.
# @note `group` from `or_group` has a similar precedence as Ruby's `()`.
# @note `or_group` is a rought equivalent of `|| ()`
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
# @internal
# NOTE: Decomposing of the `and` expression is needed to make its priority higher.
#
def or_group(&block)
previous_expression = steps.expression

Expand Down Expand Up @@ -392,15 +404,16 @@ def or_group(&block)
# @param block [Proc, nil]
# @return [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base]
#
# @internal
# NOTE: Decomposing of the `and` expression is needed to make its priority higher.
#
# @note `or` from `or_not_group` has a similar precedence as Ruby's `||`.
# @note `not` from `or_not_group` has a similar precedence as Ruby's `!`.
# @note `group` from `or_not_group` has a similar precedence as Ruby's `()`.
# @note `or_not_group` is a rought equivalent of `|| !()`
# @note It is NOT recommended to rely on the return value of this method, since it may differ across different `step` related plugins.
# @see https://ruby-doc.org/core-2.7.1/doc/syntax/precedence_rdoc.html
#
# @internal
# NOTE: Decomposing of the `and` expression is needed to make its priority higher.
#
def or_not_group(&block)
previous_expression = steps.expression

Expand Down Expand Up @@ -474,7 +487,7 @@ def steps
# Returns `nil` when index is out of range.
#
# @param index [Integer]
# @return [ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base]
# @return [ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step]
#
# @note This method was initially designed as a hook (callback trigger).
# @see ConvenientService::Service::Plugins::CanHaveConnectedSteps::Middleware#next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ConvenientService::Service::Plugins::HasResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Concern,
ConvenientService::Service::Plugins::CanHaveSteps::Concern,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern,
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern,
ConvenientService::Common::Plugins::CachesConstructorArguments::Concern,
ConvenientService::Common::Plugins::CanBeCopied::Concern,
ConvenientService::Service::Plugins::CanRecalculateResult::Concern,
Expand Down Expand Up @@ -87,7 +87,7 @@
ConvenientService::Service::Plugins::SetsParentToForeignResult::Middleware,
ConvenientService::Service::Plugins::HasJSendResultParamsValidations::UsingDryValidation::Middleware,
ConvenientService::Service::Plugins::RaisesOnNotResultReturnValue::Middleware,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Middleware

##
# TODO: Rewrite. This plugin does NOT do what it states. Probably I was NOT with a clear mind while writing it (facepalm).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ConvenientService::Service::Plugins::HasResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Concern,
ConvenientService::Service::Plugins::CanHaveSteps::Concern,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern,
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern,
ConvenientService::Common::Plugins::CachesConstructorArguments::Concern,
ConvenientService::Common::Plugins::CanBeCopied::Concern,
ConvenientService::Service::Plugins::CanRecalculateResult::Concern,
Expand Down Expand Up @@ -89,7 +89,7 @@
ConvenientService::Service::Plugins::SetsParentToForeignResult::Middleware,
ConvenientService::Service::Plugins::HasJSendResultParamsValidations::UsingActiveModelValidations::Middleware,
ConvenientService::Service::Plugins::RaisesOnNotResultReturnValue::Middleware,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Middleware

##
# TODO: Rewrite. This plugin does NOT do what it states. Probably I was NOT with a clear mind while writing it (facepalm).
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/convenient_service/service/configs/minimal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
ConvenientService::Service::Plugins::HasResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Concern,
ConvenientService::Service::Plugins::CanHaveSteps::Concern,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern
]
end

Expand All @@ -62,7 +62,7 @@
ConvenientService::Common::Plugins::NormalizesEnv::Middleware,
ConvenientService::Common::Plugins::CachesReturnValue::Middleware,
ConvenientService::Service::Plugins::RaisesOnNotResultReturnValue::Middleware,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Middleware
]
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/convenient_service/service/configs/standard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ConvenientService::Service::Plugins::HasResult::Concern,
ConvenientService::Service::Plugins::HasJSendResult::Concern,
ConvenientService::Service::Plugins::CanHaveSteps::Concern,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern,
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern,
ConvenientService::Common::Plugins::CachesConstructorArguments::Concern,
ConvenientService::Common::Plugins::CanBeCopied::Concern,
ConvenientService::Service::Plugins::CanRecalculateResult::Concern,
Expand Down Expand Up @@ -82,7 +82,7 @@
ConvenientService::Common::Plugins::HasAroundCallbacks::Middleware,
ConvenientService::Service::Plugins::SetsParentToForeignResult::Middleware,
ConvenientService::Service::Plugins::RaisesOnNotResultReturnValue::Middleware,
ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware
ConvenientService::Service::Plugins::CanHaveConnectedSteps::Middleware

##
# TODO: Rewrite. This plugin does NOT do what it states. Probably I was NOT with a clear mind while writing it (facepalm).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
let(:service_class) do
Class.new do
include ConvenientService::Service::Configs::Minimal

concerns do
replace \
ConvenientService::Plugins::Service::CanHaveSequentialSteps::Concern,
ConvenientService::Plugins::Service::CanHaveConnectedSteps::Concern
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@
klass.class_exec(middleware) do |middleware|
include ConvenientService::Service::Configs::Standard

concerns do
replace ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern, ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern
end

middlewares :result do
replace ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware, middleware

observe middleware
end

Expand Down Expand Up @@ -102,13 +96,7 @@ def result
klass.class_exec(first_step, second_step, middleware) do |first_step, second_step, middleware|
include ConvenientService::Service::Configs::Standard

concerns do
replace ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern, ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern
end

middlewares :result do
replace ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware, middleware

observe middleware
end

Expand Down Expand Up @@ -212,13 +200,7 @@ def result
klass.class_exec(first_step, second_step, middleware) do |first_step, second_step, middleware|
include ConvenientService::Service::Configs::Standard

concerns do
replace ConvenientService::Service::Plugins::CanHaveSequentialSteps::Concern, ConvenientService::Service::Plugins::CanHaveConnectedSteps::Concern
end

middlewares :result do
replace ConvenientService::Service::Plugins::CanHaveSequentialSteps::Middleware, middleware

observe middleware
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
it "returns original step" do
method_value

expect(container.steps.first).to eq(container.step(service, **kwargs).copy(overrides: {kwargs: {index: index}}))
expect(container.steps.first).to eq(container.step_class.new(service, **kwargs.merge(index: index)))
end
end

Expand All @@ -83,7 +83,7 @@
it "returns customized step" do
method_value

expect(container.steps.first).to eq(container.step(container, **kwargs.merge(method: method_name)).copy(overrides: {kwargs: {index: index}}))
expect(container.steps.first).to eq(container.step_class.new(container, **kwargs.merge(method: method_name, index: index)))
end
end
end
Expand Down
Loading

0 comments on commit 16fb5e2

Please sign in to comment.