convenient_service 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gem_release.yml +0 -12
- data/.github/issue_template.md +35 -0
- data/.github/pull_request_template.md +31 -0
- data/.github/workflows/cd.yml +15 -2
- data/.github/workflows/ci.yml +6 -6
- data/CHANGELOG.md +27 -0
- data/README.md +12 -3
- data/ROADMAP.md +22 -8
- data/Taskfile.yml +5 -13
- data/env.rb +4 -0
- data/lib/convenient_service/common/plugins/caches_return_value/middleware.rb +17 -2
- data/lib/convenient_service/common/plugins/caches_return_value.rb +0 -1
- data/lib/convenient_service/common/plugins/has_constructor/concern.rb +13 -0
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb +27 -0
- data/lib/convenient_service/common/plugins/has_constructor_without_initialize.rb +3 -0
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb +8 -4
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb +0 -1
- data/lib/convenient_service/common/plugins.rb +1 -0
- data/lib/convenient_service/configs/standard.rb +16 -0
- data/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/container/commands/cast_container.rb +0 -2
- data/lib/convenient_service/dependencies.rb +1 -0
- data/lib/convenient_service/examples/dry/gemfile/dry_service/config.rb +3 -1
- data/lib/convenient_service/examples/dry/gemfile/services/assert_file_exists.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/assert_file_not_empty.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/assert_npm_package_available.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/parse_content.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/print_shell_command.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/read_file_content.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/run_shell.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile/services/strip_comments.rb +1 -1
- data/lib/convenient_service/examples/dry/gemfile.rb +5 -4
- data/lib/convenient_service/examples/rails/gemfile/rails_service/config.rb +3 -1
- data/lib/convenient_service/examples/rails/gemfile.rb +5 -4
- data/lib/convenient_service/examples/standard/cowsay/services/build_cloud.rb +42 -0
- data/lib/convenient_service/examples/standard/cowsay/services/build_cow.rb +38 -0
- data/lib/convenient_service/examples/standard/cowsay/services/print.rb +32 -0
- data/lib/convenient_service/examples/standard/cowsay/services.rb +5 -0
- data/lib/convenient_service/examples/standard/cowsay.rb +24 -0
- data/lib/convenient_service/examples/standard/gemfile/services/format.rb +2 -0
- data/lib/convenient_service/examples/standard/gemfile.rb +5 -4
- data/lib/convenient_service/rspec/helpers/custom/stub_service/entities/result_spec.rb +96 -7
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/entities/wrapped_method.rb +44 -8
- data/lib/convenient_service/rspec/helpers/custom/wrap_method/errors.rb +11 -9
- data/lib/convenient_service/rspec/matchers/custom/cache_its_value.rb +7 -7
- data/lib/convenient_service/rspec/matchers/custom/call_chain_next.rb +2 -0
- data/lib/convenient_service/rspec/matchers/custom/delegate_to.rb +50 -12
- data/lib/convenient_service/rspec/matchers/custom/results/be_success.rb +6 -0
- data/lib/convenient_service/service/plugins/aliases.rb +1 -0
- data/lib/convenient_service/service/plugins/has_inspect/concern.rb +23 -0
- data/lib/convenient_service/service/plugins/has_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb +10 -0
- data/lib/convenient_service/service/plugins/has_result/concern/class_methods.rb +23 -14
- data/lib/convenient_service/service/plugins/has_result/concern/instance_methods.rb +17 -1
- data/lib/convenient_service/service/plugins/has_result/entities/result/concern.rb +4 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect/concern.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb +37 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb +127 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb +27 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/class_methods.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb +32 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb +49 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb +45 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb +34 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb +73 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/{entities.rb → plugins/has_jsend_status_and_attributes/entities.rb} +0 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/errors.rb +29 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/middleware.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb +21 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb +8 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb +2 -0
- data/lib/convenient_service/service/plugins/has_result/entities/result.rb +0 -4
- data/lib/convenient_service/service/plugins/has_result_method_steps/middleware.rb +1 -1
- data/lib/convenient_service/service/plugins/has_result_method_steps/services/method_step_config.rb +30 -4
- data/lib/convenient_service/service/plugins/has_result_params_validations/using_dry_validation/middleware.rb +19 -9
- data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb +63 -0
- data/lib/convenient_service/service/plugins/has_result_status_check_short_syntax.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/concern.rb +2 -1
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect/concern.rb +31 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb +3 -0
- data/lib/convenient_service/service/plugins/has_result_steps/entities/step.rb +1 -0
- data/lib/convenient_service/service/plugins/has_result_steps/middleware.rb +1 -1
- data/lib/convenient_service/service/plugins.rb +2 -0
- data/lib/convenient_service/support/cache/key.rb +100 -0
- data/lib/convenient_service/support/cache.rb +131 -0
- data/lib/convenient_service/support/copyable.rb +3 -2
- data/lib/convenient_service/support/delegate.rb +3 -2
- data/lib/convenient_service/support.rb +1 -0
- data/lib/convenient_service/version.rb +1 -1
- data/logo.png +0 -0
- metadata +40 -21
- data/lib/convenient_service/common/plugins/caches_return_value/entities/key.rb +0 -79
- data/lib/convenient_service/common/plugins/caches_return_value/entities.rb +0 -3
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb +0 -81
- data/lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb +0 -33
- data/lib/convenient_service/service/plugins/has_result/entities/result/commands.rb +0 -3
- data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb +0 -64
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb +0 -45
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb +0 -28
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb +0 -45
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb +0 -41
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb +0 -30
- data/lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb +0 -69
- data/lib/convenient_service/service/plugins/has_result/entities/result/errors.rb +0 -25
- data/lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb +0 -17
- data/lib/convenient_service/service/plugins/has_result/entities/result/structs.rb +0 -3
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "cache/key"
|
4
|
+
|
5
|
+
module ConvenientService
|
6
|
+
module Support
|
7
|
+
class Cache
|
8
|
+
##
|
9
|
+
# @return [void]
|
10
|
+
#
|
11
|
+
def initialize(hash = {})
|
12
|
+
@hash = hash
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
##
|
17
|
+
# @return [ConvenientService::Support::Cache::Key]
|
18
|
+
#
|
19
|
+
def keygen(...)
|
20
|
+
Cache::Key.new(...)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# @return [Boolean]
|
26
|
+
#
|
27
|
+
# @internal
|
28
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-exist-3F
|
29
|
+
#
|
30
|
+
def exist?(key)
|
31
|
+
hash.has_key?(key)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Object] Can be any type.
|
36
|
+
#
|
37
|
+
# @internal
|
38
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-read
|
39
|
+
#
|
40
|
+
def read(key)
|
41
|
+
hash[key]
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# @return [Object] Can be any type.
|
46
|
+
#
|
47
|
+
# @internal
|
48
|
+
# NOTE: `alias_method` is NOT used in order to have an ability to use `allow(cache).to receive(:read).with(key).and_call_original` for both `cache[key]` and `cache.read(key)` in RSpec.
|
49
|
+
#
|
50
|
+
def [](key)
|
51
|
+
read(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# @param key [Object] Can be any type.
|
56
|
+
# @param value [Object] Can be any type.
|
57
|
+
# @return [Object] Can be any type.
|
58
|
+
#
|
59
|
+
# @internal
|
60
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-write
|
61
|
+
#
|
62
|
+
def write(key, value)
|
63
|
+
hash[key] = value
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# @param key [Object] Can be any type.
|
68
|
+
# @param value [Object] Can be any type.
|
69
|
+
# @return [Object] Can be any type.
|
70
|
+
#
|
71
|
+
# @internal
|
72
|
+
# NOTE: `alias_method` is NOT used in order to have an ability to use `allow(cache).to receive(:write).with(key, value).and_call_original` for both `cache[key] = value` and `cache.write(key, value)` in RSpec.
|
73
|
+
#
|
74
|
+
def []=(key, value)
|
75
|
+
write(key, value)
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# @param key [Object] Can be any type.
|
80
|
+
# @return [Object] Can be any type.
|
81
|
+
#
|
82
|
+
# @internal
|
83
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-delete
|
84
|
+
#
|
85
|
+
def delete(key)
|
86
|
+
hash.delete(key)
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# @param key [Object] Can be any type.
|
91
|
+
# @param block [Proc]
|
92
|
+
# @return [Object] Can be any type.
|
93
|
+
#
|
94
|
+
# @internal
|
95
|
+
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-fetch
|
96
|
+
#
|
97
|
+
def fetch(key, &block)
|
98
|
+
return read(key) unless block
|
99
|
+
|
100
|
+
exist?(key) ? read(key) : write(key, block.call)
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# @return [ConvenientService::Support::Cache::Key]
|
105
|
+
#
|
106
|
+
def keygen(...)
|
107
|
+
Cache.keygen(...)
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# @param other [Object] Can be any type.
|
112
|
+
# @return [Boolean]
|
113
|
+
#
|
114
|
+
def ==(other)
|
115
|
+
return unless other.instance_of?(self.class)
|
116
|
+
|
117
|
+
return false if hash != other.hash
|
118
|
+
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
122
|
+
protected
|
123
|
+
|
124
|
+
##
|
125
|
+
# @!attribute [r] hash
|
126
|
+
# @return [Hash]
|
127
|
+
#
|
128
|
+
attr_reader :hash
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -15,8 +15,9 @@ module ConvenientService
|
|
15
15
|
# copy = person.copy(overrides: {kwargs: {age: 18}})
|
16
16
|
# copy = person.copy(overrides: {block: proc { |p| print p }})
|
17
17
|
#
|
18
|
-
#
|
19
|
-
#
|
18
|
+
# @internal
|
19
|
+
# NOTE: Inline logic instead of private methods is used intentionally in order to NOT pollute the public interface.
|
20
|
+
# NOTE: This method is NOT likely to be ever changed, that is why inline logic is preferred over command classes in this particular case.
|
20
21
|
#
|
21
22
|
def copy(overrides: {})
|
22
23
|
overrides[:args] ||= {}
|
@@ -19,8 +19,9 @@ module ConvenientService
|
|
19
19
|
end
|
20
20
|
|
21
21
|
##
|
22
|
-
#
|
23
|
-
#
|
22
|
+
# @internal
|
23
|
+
# `ClassMethods` is loaded faster than `included` by `Concern`.
|
24
|
+
# Since `Forwardable` has it own `delegate` - a different name is used.
|
24
25
|
#
|
25
26
|
module ClassMethodsForForwardable
|
26
27
|
def delegate(*methods, to:)
|
data/logo.png
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convenient_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marian Kostyk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -303,6 +303,8 @@ extra_rdoc_files: []
|
|
303
303
|
files:
|
304
304
|
- ".dockerignore"
|
305
305
|
- ".gem_release.yml"
|
306
|
+
- ".github/issue_template.md"
|
307
|
+
- ".github/pull_request_template.md"
|
306
308
|
- ".github/workflows/cd.yml"
|
307
309
|
- ".github/workflows/ci.yml"
|
308
310
|
- ".gitignore"
|
@@ -342,8 +344,6 @@ files:
|
|
342
344
|
- lib/convenient_service/common/plugins/caches_constructor_params/entities/constructor_params.rb
|
343
345
|
- lib/convenient_service/common/plugins/caches_constructor_params/middleware.rb
|
344
346
|
- lib/convenient_service/common/plugins/caches_return_value.rb
|
345
|
-
- lib/convenient_service/common/plugins/caches_return_value/entities.rb
|
346
|
-
- lib/convenient_service/common/plugins/caches_return_value/entities/key.rb
|
347
347
|
- lib/convenient_service/common/plugins/caches_return_value/middleware.rb
|
348
348
|
- lib/convenient_service/common/plugins/can_be_copied.rb
|
349
349
|
- lib/convenient_service/common/plugins/can_be_copied/concern.rb
|
@@ -366,6 +366,8 @@ files:
|
|
366
366
|
- lib/convenient_service/common/plugins/has_callbacks/middleware.rb
|
367
367
|
- lib/convenient_service/common/plugins/has_constructor.rb
|
368
368
|
- lib/convenient_service/common/plugins/has_constructor/concern.rb
|
369
|
+
- lib/convenient_service/common/plugins/has_constructor_without_initialize.rb
|
370
|
+
- lib/convenient_service/common/plugins/has_constructor_without_initialize/concern.rb
|
369
371
|
- lib/convenient_service/common/plugins/has_internals.rb
|
370
372
|
- lib/convenient_service/common/plugins/has_internals/commands.rb
|
371
373
|
- lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
|
@@ -376,8 +378,6 @@ files:
|
|
376
378
|
- lib/convenient_service/common/plugins/has_internals/entities/internals/plugins.rb
|
377
379
|
- lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache.rb
|
378
380
|
- lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/concern.rb
|
379
|
-
- lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities.rb
|
380
|
-
- lib/convenient_service/common/plugins/has_internals/entities/internals/plugins/has_cache/entities/cache.rb
|
381
381
|
- lib/convenient_service/common/plugins/normalizes_env.rb
|
382
382
|
- lib/convenient_service/common/plugins/normalizes_env/middleware.rb
|
383
383
|
- lib/convenient_service/configs.rb
|
@@ -471,6 +471,11 @@ files:
|
|
471
471
|
- lib/convenient_service/examples/rails/gemfile/services/read_file_content.rb
|
472
472
|
- lib/convenient_service/examples/rails/gemfile/services/run_shell.rb
|
473
473
|
- lib/convenient_service/examples/rails/gemfile/services/strip_comments.rb
|
474
|
+
- lib/convenient_service/examples/standard/cowsay.rb
|
475
|
+
- lib/convenient_service/examples/standard/cowsay/services.rb
|
476
|
+
- lib/convenient_service/examples/standard/cowsay/services/build_cloud.rb
|
477
|
+
- lib/convenient_service/examples/standard/cowsay/services/build_cow.rb
|
478
|
+
- lib/convenient_service/examples/standard/cowsay/services/print.rb
|
474
479
|
- lib/convenient_service/examples/standard/gemfile.rb
|
475
480
|
- lib/convenient_service/examples/standard/gemfile/services.rb
|
476
481
|
- lib/convenient_service/examples/standard/gemfile/services/assert_file_exists.rb
|
@@ -545,6 +550,8 @@ files:
|
|
545
550
|
- lib/convenient_service/service/plugins/aliases.rb
|
546
551
|
- lib/convenient_service/service/plugins/can_recalculate_result.rb
|
547
552
|
- lib/convenient_service/service/plugins/can_recalculate_result/concern.rb
|
553
|
+
- lib/convenient_service/service/plugins/has_inspect.rb
|
554
|
+
- lib/convenient_service/service/plugins/has_inspect/concern.rb
|
548
555
|
- lib/convenient_service/service/plugins/has_result.rb
|
549
556
|
- lib/convenient_service/service/plugins/has_result/commands.rb
|
550
557
|
- lib/convenient_service/service/plugins/has_result/commands/create_result_class.rb
|
@@ -554,23 +561,30 @@ files:
|
|
554
561
|
- lib/convenient_service/service/plugins/has_result/constants.rb
|
555
562
|
- lib/convenient_service/service/plugins/has_result/entities.rb
|
556
563
|
- lib/convenient_service/service/plugins/has_result/entities/result.rb
|
557
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/commands.rb
|
558
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/commands/cast_result_params.rb
|
559
564
|
- lib/convenient_service/service/plugins/has_result/entities/result/concern.rb
|
560
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb
|
561
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities.rb
|
562
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/code.rb
|
563
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/code/class_methods.rb
|
564
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/data.rb
|
565
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/data/class_methods.rb
|
566
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/message.rb
|
567
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/message/class_methods.rb
|
568
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/status.rb
|
569
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/entities/status/class_methods.rb
|
570
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/errors.rb
|
571
565
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins.rb
|
572
566
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_recalculate_result.rb
|
573
567
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/can_recalculate_result/concern.rb
|
568
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.rb
|
569
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect/concern.rb
|
570
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes.rb
|
571
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands.rb
|
572
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/commands/cast_jsend_attributes.rb
|
573
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern.rb
|
574
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/concern/instance_methods.rb
|
575
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities.rb
|
576
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code.rb
|
577
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/code/class_methods.rb
|
578
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data.rb
|
579
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/data/class_methods.rb
|
580
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message.rb
|
581
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/message/class_methods.rb
|
582
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
|
583
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status/class_methods.rb
|
584
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/errors.rb
|
585
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/middleware.rb
|
586
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs.rb
|
587
|
+
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/structs/jsend_attributes.rb
|
574
588
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax.rb
|
575
589
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern.rb
|
576
590
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_result_short_syntax/concern/instance_methods.rb
|
@@ -579,8 +593,6 @@ files:
|
|
579
593
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status.rb
|
580
594
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/errors.rb
|
581
595
|
- lib/convenient_service/service/plugins/has_result/entities/result/plugins/raises_on_not_checked_result_status/middleware.rb
|
582
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/structs.rb
|
583
|
-
- lib/convenient_service/service/plugins/has_result/entities/result/structs/result_params.rb
|
584
596
|
- lib/convenient_service/service/plugins/has_result/errors.rb
|
585
597
|
- lib/convenient_service/service/plugins/has_result/middleware.rb
|
586
598
|
- lib/convenient_service/service/plugins/has_result_method_steps.rb
|
@@ -614,6 +626,8 @@ files:
|
|
614
626
|
- lib/convenient_service/service/plugins/has_result_short_syntax/success/commands/refute_kwargs_contain_data_and_extra_keys.rb
|
615
627
|
- lib/convenient_service/service/plugins/has_result_short_syntax/success/errors.rb
|
616
628
|
- lib/convenient_service/service/plugins/has_result_short_syntax/success/middleware.rb
|
629
|
+
- lib/convenient_service/service/plugins/has_result_status_check_short_syntax.rb
|
630
|
+
- lib/convenient_service/service/plugins/has_result_status_check_short_syntax/concern.rb
|
617
631
|
- lib/convenient_service/service/plugins/has_result_steps.rb
|
618
632
|
- lib/convenient_service/service/plugins/has_result_steps/commands.rb
|
619
633
|
- lib/convenient_service/service/plugins/has_result_steps/commands/create_step_class.rb
|
@@ -655,6 +669,9 @@ files:
|
|
655
669
|
- lib/convenient_service/service/plugins/has_result_steps/entities/step/concern.rb
|
656
670
|
- lib/convenient_service/service/plugins/has_result_steps/entities/step/concern/instance_methods.rb
|
657
671
|
- lib/convenient_service/service/plugins/has_result_steps/entities/step/errors.rb
|
672
|
+
- lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins.rb
|
673
|
+
- lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect.rb
|
674
|
+
- lib/convenient_service/service/plugins/has_result_steps/entities/step/plugins/has_inspect/concern.rb
|
658
675
|
- lib/convenient_service/service/plugins/has_result_steps/entities/step/structs.rb
|
659
676
|
- lib/convenient_service/service/plugins/has_result_steps/entities/step/structs/params.rb
|
660
677
|
- lib/convenient_service/service/plugins/has_result_steps/entities/step_collection.rb
|
@@ -668,6 +685,8 @@ files:
|
|
668
685
|
- lib/convenient_service/support.rb
|
669
686
|
- lib/convenient_service/support/abstract_method.rb
|
670
687
|
- lib/convenient_service/support/abstract_method/errors.rb
|
688
|
+
- lib/convenient_service/support/cache.rb
|
689
|
+
- lib/convenient_service/support/cache/key.rb
|
671
690
|
- lib/convenient_service/support/castable.rb
|
672
691
|
- lib/convenient_service/support/castable/errors.rb
|
673
692
|
- lib/convenient_service/support/command.rb
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ConvenientService
|
4
|
-
module Common
|
5
|
-
module Plugins
|
6
|
-
module CachesReturnValue
|
7
|
-
module Entities
|
8
|
-
class Key
|
9
|
-
attr_reader :method, :args, :kwargs, :block
|
10
|
-
|
11
|
-
##
|
12
|
-
#
|
13
|
-
#
|
14
|
-
def initialize(method:, args:, kwargs:, block:)
|
15
|
-
@method = method
|
16
|
-
@args = args
|
17
|
-
@kwargs = kwargs
|
18
|
-
@block = block
|
19
|
-
end
|
20
|
-
|
21
|
-
##
|
22
|
-
#
|
23
|
-
#
|
24
|
-
def ==(other)
|
25
|
-
return unless other.instance_of?(self.class)
|
26
|
-
|
27
|
-
return false if method != other.method
|
28
|
-
return false if args != other.args
|
29
|
-
return false if kwargs != other.kwargs
|
30
|
-
return false if block&.source_location != other.block&.source_location
|
31
|
-
|
32
|
-
true
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# IMPORTANT: `Key` instances are used as Ruby hash keys.
|
37
|
-
#
|
38
|
-
# This method is overridden in order to avoid the following case:
|
39
|
-
#
|
40
|
-
# hash = {}
|
41
|
-
#
|
42
|
-
# ##
|
43
|
-
# # Two equal keys in terms of `==`.
|
44
|
-
# #
|
45
|
-
# first_key = ConvenientService::Common::Plugins::CachesReturnValue::Entities::Key.new(method: :result, args: [], kwargs: {}, block: nil)
|
46
|
-
# second_key = ConvenientService::Common::Plugins::CachesReturnValue::Entities::Key.new(method: :result, args: [], kwargs: {}, block: nil)
|
47
|
-
#
|
48
|
-
# first_key == second_key
|
49
|
-
# # => true
|
50
|
-
#
|
51
|
-
# hash[first_key] = "value"
|
52
|
-
#
|
53
|
-
# hash[second_key]
|
54
|
-
# # => nil # This happens since keys are not equal in terms of `eql?`.
|
55
|
-
#
|
56
|
-
# NOTE: Ruby hash and Object#hash are not the same things.
|
57
|
-
# https://ruby-doc.org/core-3.1.2/Object.html#method-i-hash
|
58
|
-
# https://belighted.com/blog/overriding-equals-equals/
|
59
|
-
#
|
60
|
-
def eql?(other)
|
61
|
-
return unless other.instance_of?(self.class)
|
62
|
-
|
63
|
-
hash == other.hash
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# NOTE: hash is overridden to treat blocks that were defined at the same location as equal.
|
68
|
-
# https://ruby-doc.org/core-3.1.2/Proc.html#method-i-source_location
|
69
|
-
# https://ruby-doc.org/core-3.1.2/Object.html#method-i-hash
|
70
|
-
#
|
71
|
-
def hash
|
72
|
-
[method, args, kwargs, block&.source_location].hash
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ConvenientService
|
4
|
-
module Common
|
5
|
-
module Plugins
|
6
|
-
module HasInternals
|
7
|
-
module Entities
|
8
|
-
class Internals
|
9
|
-
module Plugins
|
10
|
-
module HasCache
|
11
|
-
module Entities
|
12
|
-
##
|
13
|
-
# TODO: Specs.
|
14
|
-
#
|
15
|
-
class Cache
|
16
|
-
attr_reader :hash
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@hash = {}
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-exist-3F
|
24
|
-
#
|
25
|
-
def exist?(key)
|
26
|
-
hash.has_key?(key)
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-read
|
31
|
-
#
|
32
|
-
def read(key)
|
33
|
-
hash[key]
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# NOTE: `alias_method` is NOT used in order to have an ability to use `allow(cache).to receive(:read).with(key).and_call_original` for both `cache[key]` and `cache.read(key)` in RSpec.
|
38
|
-
#
|
39
|
-
def [](key)
|
40
|
-
read(key)
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-write
|
45
|
-
#
|
46
|
-
def write(key, value)
|
47
|
-
hash[key] = value
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# NOTE: `alias_method` is NOT used in order to have an ability to use `allow(cache).to receive(:write).with(key, value).and_call_original` for both `cache[key] = value` and `cache.write(key, value)` in RSpec.
|
52
|
-
#
|
53
|
-
def []=(key, value)
|
54
|
-
write(key, value)
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-delete
|
59
|
-
#
|
60
|
-
def delete(key)
|
61
|
-
hash.delete(key)
|
62
|
-
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-fetch
|
66
|
-
#
|
67
|
-
def fetch(key, &block)
|
68
|
-
return read(key) unless block
|
69
|
-
|
70
|
-
exist?(key) ? read(key) : write(key, block.call)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ConvenientService
|
4
|
-
module Service
|
5
|
-
module Plugins
|
6
|
-
module HasResult
|
7
|
-
module Entities
|
8
|
-
class Result
|
9
|
-
module Commands
|
10
|
-
class CastResultParams < Support::Command
|
11
|
-
attr_reader :params
|
12
|
-
|
13
|
-
def initialize(params:)
|
14
|
-
@params = params
|
15
|
-
end
|
16
|
-
|
17
|
-
def call
|
18
|
-
Structs::ResultParams.new(
|
19
|
-
service: params[:service],
|
20
|
-
status: Entities::Status.cast!(params[:status]),
|
21
|
-
data: Entities::Data.cast!(params[:data]),
|
22
|
-
message: Entities::Message.cast!(params[:message]),
|
23
|
-
code: Entities::Code.cast!(params[:code])
|
24
|
-
)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/convenient_service/service/plugins/has_result/entities/result/concern/instance_methods.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ConvenientService
|
4
|
-
module Service
|
5
|
-
module Plugins
|
6
|
-
module HasResult
|
7
|
-
module Entities
|
8
|
-
class Result
|
9
|
-
module Concern
|
10
|
-
##
|
11
|
-
# TODO: How to use concern outside?
|
12
|
-
#
|
13
|
-
module InstanceMethods
|
14
|
-
include Support::Delegate
|
15
|
-
include Support::Copyable
|
16
|
-
|
17
|
-
delegate \
|
18
|
-
:service,
|
19
|
-
:status,
|
20
|
-
:data,
|
21
|
-
:message,
|
22
|
-
:code,
|
23
|
-
to: :params
|
24
|
-
|
25
|
-
delegate \
|
26
|
-
:success?,
|
27
|
-
:failure?,
|
28
|
-
:error?,
|
29
|
-
:not_success?,
|
30
|
-
:not_failure?,
|
31
|
-
:not_error?,
|
32
|
-
to: :status
|
33
|
-
|
34
|
-
def initialize(**params)
|
35
|
-
@params = Commands::CastResultParams.call(params: params)
|
36
|
-
end
|
37
|
-
|
38
|
-
def ==(other)
|
39
|
-
return unless other.instance_of?(self.class)
|
40
|
-
|
41
|
-
return false if service.class != other.service.class
|
42
|
-
return false if status != other.status
|
43
|
-
return false if data != other.data
|
44
|
-
return false if message != other.message
|
45
|
-
return false if code != other.code
|
46
|
-
|
47
|
-
true
|
48
|
-
end
|
49
|
-
|
50
|
-
def to_kwargs
|
51
|
-
{service: service, status: status, data: data, message: message, code: code}
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
attr_reader :params
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ConvenientService
|
4
|
-
module Service
|
5
|
-
module Plugins
|
6
|
-
module HasResult
|
7
|
-
module Entities
|
8
|
-
class Result
|
9
|
-
module Entities
|
10
|
-
class Code
|
11
|
-
module ClassMethods
|
12
|
-
def cast(other)
|
13
|
-
case other
|
14
|
-
when ::String
|
15
|
-
new(value: other.to_sym)
|
16
|
-
when ::Symbol
|
17
|
-
new(value: other)
|
18
|
-
when Code
|
19
|
-
new(value: other.value)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|