-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(has_negated_j_send_result): move negated_result from service…
… to result
- Loading branch information
Showing
13 changed files
with
416 additions
and
385 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
2 changes: 1 addition & 1 deletion
2
lib/convenient_service/service/plugins/has_j_send_result/entities/result/plugins.rb
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
3 changes: 0 additions & 3 deletions
3
...nient_service/service/plugins/has_j_send_result/entities/result/plugins/can_be_negated.rb
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
...rvice/service/plugins/has_j_send_result/entities/result/plugins/can_be_negated/concern.rb
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...t_service/service/plugins/has_j_send_result/entities/result/plugins/has_negated_result.rb
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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "has_negated_result/concern" |
58 changes: 58 additions & 0 deletions
58
...e/service/plugins/has_j_send_result/entities/result/plugins/has_negated_result/concern.rb
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,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasJSendResult | ||
module Entities | ||
class Result | ||
module Plugins | ||
module HasNegatedResult | ||
module Concern | ||
include Support::Concern | ||
|
||
instance_methods do | ||
## | ||
# @return [Boolean] | ||
# | ||
def negated? | ||
Utils.to_bool(extra_kwargs[:negated]) | ||
end | ||
|
||
## | ||
# @return [ConvenientService::Service::Plugins::HasJSendResult::Entities::Result] | ||
# | ||
# @internal | ||
# NOTE: `original_result = result` is used to cache `result` independently, without relying on `CachesReturnValue` plugin. | ||
# | ||
# TODO: `Utils::String.concat_if`? How? | ||
# - https://stackoverflow.com/a/28648594/12201472 | ||
# | ||
def negated_result | ||
case status.to_sym | ||
when :success | ||
service.failure( | ||
data: unsafe_data, | ||
message: "Original `result` is `success`#{" with `message` - #{unsafe_message}" unless unsafe_message.empty?}", | ||
code: "negated_#{unsafe_code}" | ||
) | ||
when :failure | ||
service.success( | ||
data: unsafe_data, | ||
message: "Original `result` is `failure`#{" with `message` - #{unsafe_message}" unless unsafe_message.empty?}", | ||
code: "negated_#{unsafe_code}" | ||
) | ||
when :error | ||
copy | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
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
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
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
65 changes: 0 additions & 65 deletions
65
.../service/plugins/has_j_send_result/entities/result/plugins/can_be_negated/concern_spec.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.