servactory 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +116 -0
  3. data/Rakefile +12 -0
  4. data/lib/servactory/base.rb +11 -0
  5. data/lib/servactory/configuration.rb +18 -0
  6. data/lib/servactory/context/configuration.rb +23 -0
  7. data/lib/servactory/context/dsl.rb +58 -0
  8. data/lib/servactory/context/store.rb +51 -0
  9. data/lib/servactory/errors/base.rb +7 -0
  10. data/lib/servactory/errors/failure.rb +7 -0
  11. data/lib/servactory/errors/input_argument_error.rb +7 -0
  12. data/lib/servactory/errors/internal_argument_error.rb +7 -0
  13. data/lib/servactory/errors/output_argument_error.rb +7 -0
  14. data/lib/servactory/input_arguments/checks/base.rb +23 -0
  15. data/lib/servactory/input_arguments/checks/inclusion.rb +45 -0
  16. data/lib/servactory/input_arguments/checks/must.rb +75 -0
  17. data/lib/servactory/input_arguments/checks/required.rb +54 -0
  18. data/lib/servactory/input_arguments/checks/type.rb +84 -0
  19. data/lib/servactory/input_arguments/collection.rb +19 -0
  20. data/lib/servactory/input_arguments/dsl.rb +27 -0
  21. data/lib/servactory/input_arguments/input_argument.rb +79 -0
  22. data/lib/servactory/input_arguments/tools/check.rb +74 -0
  23. data/lib/servactory/input_arguments/tools/find_unnecessary.rb +32 -0
  24. data/lib/servactory/input_arguments/tools/prepare.rb +89 -0
  25. data/lib/servactory/input_arguments/tools/rules.rb +38 -0
  26. data/lib/servactory/input_arguments/workbench.rb +40 -0
  27. data/lib/servactory/inputs.rb +7 -0
  28. data/lib/servactory/internal_arguments/checks/base.rb +17 -0
  29. data/lib/servactory/internal_arguments/checks/type.rb +55 -0
  30. data/lib/servactory/internal_arguments/collection.rb +19 -0
  31. data/lib/servactory/internal_arguments/dsl.rb +27 -0
  32. data/lib/servactory/internal_arguments/internal_argument.rb +33 -0
  33. data/lib/servactory/internal_arguments/tools/prepare.rb +58 -0
  34. data/lib/servactory/internal_arguments/workbench.rb +27 -0
  35. data/lib/servactory/output_arguments/checks/base.rb +17 -0
  36. data/lib/servactory/output_arguments/checks/type.rb +55 -0
  37. data/lib/servactory/output_arguments/collection.rb +19 -0
  38. data/lib/servactory/output_arguments/dsl.rb +27 -0
  39. data/lib/servactory/output_arguments/output_argument.rb +40 -0
  40. data/lib/servactory/output_arguments/tools/conflicts.rb +34 -0
  41. data/lib/servactory/output_arguments/tools/prepare.rb +58 -0
  42. data/lib/servactory/output_arguments/workbench.rb +31 -0
  43. data/lib/servactory/result.rb +21 -0
  44. data/lib/servactory/stage/dsl.rb +29 -0
  45. data/lib/servactory/stage/factory.rb +15 -0
  46. data/lib/servactory/stage/handyman.rb +35 -0
  47. data/lib/servactory/stage/method.rb +21 -0
  48. data/lib/servactory/stage/methods.rb +15 -0
  49. data/lib/servactory/utils.rb +11 -0
  50. data/lib/servactory/version.rb +11 -0
  51. data/lib/servactory.rb +34 -0
  52. metadata +237 -0
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module OutputArguments
5
+ module DSL
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ private
12
+
13
+ def output(name, **options)
14
+ collection_of_output_arguments << OutputArgument.new(name, **options)
15
+ end
16
+
17
+ def collection_of_output_arguments
18
+ @collection_of_output_arguments ||= Collection.new
19
+ end
20
+
21
+ def output_arguments_workbench
22
+ @output_arguments_workbench ||= Workbench.work_with(collection_of_output_arguments)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module OutputArguments
5
+ class OutputArgument
6
+ attr_reader :name,
7
+ :types,
8
+ :required,
9
+ :default
10
+
11
+ def initialize(name, type:, **options)
12
+ @name = name
13
+ @types = Array(type)
14
+
15
+ @required = options.fetch(:required, true)
16
+ @default = required? ? nil : options.fetch(:default, nil)
17
+ end
18
+
19
+ def options_for_checks
20
+ {
21
+ types:,
22
+ required:,
23
+ default:
24
+ }
25
+ end
26
+
27
+ def required?
28
+ Servactory::Utils.boolean?(required)
29
+ end
30
+
31
+ def optional?
32
+ !required?
33
+ end
34
+
35
+ def default_value_present?
36
+ !default.nil?
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module OutputArguments
5
+ module Tools
6
+ class Conflicts
7
+ def self.check!(...)
8
+ new(...).check!
9
+ end
10
+
11
+ def initialize(context, collection_of_output_arguments, collection_of_internal_arguments)
12
+ @context = context
13
+ @collection_of_output_arguments = collection_of_output_arguments
14
+ @collection_of_internal_arguments = collection_of_internal_arguments
15
+ end
16
+
17
+ def check!
18
+ return if overlapping_attributes.empty?
19
+
20
+ raise Servactory.configuration.output_argument_error_class,
21
+ "The \"#{@context.class.name}\" service contains internal attributes that " \
22
+ "conflict with outputs: \"#{overlapping_attributes.join(', ')}\""
23
+ end
24
+
25
+ private
26
+
27
+ def overlapping_attributes
28
+ @overlapping_attributes ||=
29
+ @collection_of_output_arguments.names.intersection(@collection_of_internal_arguments.names)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module OutputArguments
5
+ module Tools
6
+ class Prepare
7
+ def self.prepare(...)
8
+ new(...).prepare
9
+ end
10
+
11
+ def initialize(context, collection_of_output_arguments)
12
+ @context = context
13
+ @collection_of_output_arguments = collection_of_output_arguments
14
+ end
15
+
16
+ def prepare
17
+ @collection_of_output_arguments.each do |output_argument|
18
+ create_instance_variable_for(output_argument)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def create_instance_variable_for(output_argument)
25
+ @context.instance_variable_set(:"@#{output_argument.name}", nil)
26
+
27
+ @context.class.class_eval(context_output_argument_template_for(output_argument))
28
+ end
29
+
30
+ # EXAMPLE:
31
+ #
32
+ # define_method(:user=) do |value|;
33
+ # Servactory::InternalArguments::Checks::Type.check!( context: self, output_argument:, value: );
34
+ #
35
+ # instance_variable_set(:@user, value);
36
+ # end;
37
+ #
38
+ # private attr_reader :user;
39
+ #
40
+ def context_output_argument_template_for(output_argument)
41
+ <<-RUBY.squish
42
+ define_method(:#{output_argument.name}=) do |value|;
43
+ Servactory::OutputArguments::Checks::Type.check!(
44
+ context: self,
45
+ output_argument:,
46
+ value:
47
+ );
48
+
49
+ instance_variable_set(:@#{output_argument.name}, value);
50
+ end;
51
+
52
+ private attr_reader :#{output_argument.name};
53
+ RUBY
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module OutputArguments
5
+ class Workbench
6
+ def self.work_with(...)
7
+ new(...)
8
+ end
9
+
10
+ def initialize(collection_of_output_arguments)
11
+ @collection_of_output_arguments = collection_of_output_arguments
12
+ end
13
+
14
+ def assign(context:)
15
+ @context = context
16
+ end
17
+
18
+ def find_conflicts_in!(collection_of_internal_arguments:)
19
+ Tools::Conflicts.check!(context, collection_of_output_arguments, collection_of_internal_arguments)
20
+ end
21
+
22
+ def prepare
23
+ Tools::Prepare.prepare(context, collection_of_output_arguments)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :context, :collection_of_output_arguments
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ class Result
5
+ def self.prepare_for(...)
6
+ new.send(:prepare_for, ...)
7
+ end
8
+
9
+ private
10
+
11
+ def prepare_for(context:, collection_of_output_arguments:)
12
+ collection_of_output_arguments.each do |output|
13
+ self.class.attr_reader(:"#{output.name}")
14
+
15
+ instance_variable_set(:"@#{output.name}", context.instance_variable_get(:"@#{output.name}"))
16
+ end
17
+
18
+ self
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Stage
5
+ module DSL
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ private
12
+
13
+ attr_reader :stage_handyman
14
+
15
+ def stage(&)
16
+ @stage_factory ||= Factory.new
17
+
18
+ @stage_factory.instance_eval(&)
19
+
20
+ @stage_handyman = Handyman.work_in(@stage_factory)
21
+
22
+ # @stage_factory
23
+
24
+ nil
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Stage
5
+ class Factory
6
+ def make(name, **options)
7
+ methods << Method.new(name, **options)
8
+ end
9
+
10
+ def methods
11
+ @methods ||= Methods.new
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Stage
5
+ class Handyman
6
+ def self.work_in(...)
7
+ new(...)
8
+ end
9
+
10
+ def initialize(factory)
11
+ @factory = factory
12
+ end
13
+
14
+ def assign(context:)
15
+ @context = context
16
+ end
17
+
18
+ def methods
19
+ factory.methods
20
+ end
21
+
22
+ def run_methods!
23
+ methods.each do |method|
24
+ next if method.condition && !method.condition.call(context)
25
+
26
+ context.send(method.name)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :factory, :context
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Stage
5
+ class Method
6
+ attr_reader :name, :condition
7
+
8
+ def initialize(name, **options)
9
+ @name = name
10
+
11
+ @condition = options.fetch(:if, nil)
12
+ end
13
+
14
+ # def options
15
+ # {
16
+ # condition:
17
+ # }
18
+ # end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Stage
5
+ class Methods
6
+ # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
+ extend Forwardable
8
+ def_delegators :@methods, :<<, :each
9
+
10
+ def initialize(*)
11
+ @methods = []
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Utils
5
+ module_function
6
+
7
+ def boolean?(value)
8
+ value.to_s.casecmp("true").to_i.zero?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module VERSION
5
+ MAJOR = 1
6
+ MINOR = 1
7
+ PATCH = 0
8
+
9
+ STRING = [MAJOR, MINOR, PATCH].join(".")
10
+ end
11
+ end
data/lib/servactory.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+
5
+ require "active_support/core_ext/string"
6
+
7
+ # require "servactory/support/loader"
8
+ # require "servactory/engine"
9
+
10
+ loader = Zeitwerk::Loader.for_gem
11
+ loader.inflector.inflect(
12
+ "dsl" => "DSL"
13
+ )
14
+ loader.setup
15
+
16
+ module Servactory
17
+ module_function
18
+
19
+ def configuration
20
+ @configuration ||= Servactory::Configuration.new
21
+ end
22
+
23
+ def reset
24
+ @configuration = Servactory::Configuration.new
25
+ end
26
+
27
+ def configure
28
+ yield(configuration)
29
+ end
30
+ end
31
+
32
+ # require_relative "servactory/exceptions"
33
+
34
+ # require_relative "servactory/base"
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: servactory
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anton Sokolov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rbs
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.50'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.50'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.17'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.19'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.19'
153
+ description: A set of tools for building reliable services of any complexity
154
+ email:
155
+ - profox.rus@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - README.md
161
+ - Rakefile
162
+ - lib/servactory.rb
163
+ - lib/servactory/base.rb
164
+ - lib/servactory/configuration.rb
165
+ - lib/servactory/context/configuration.rb
166
+ - lib/servactory/context/dsl.rb
167
+ - lib/servactory/context/store.rb
168
+ - lib/servactory/errors/base.rb
169
+ - lib/servactory/errors/failure.rb
170
+ - lib/servactory/errors/input_argument_error.rb
171
+ - lib/servactory/errors/internal_argument_error.rb
172
+ - lib/servactory/errors/output_argument_error.rb
173
+ - lib/servactory/input_arguments/checks/base.rb
174
+ - lib/servactory/input_arguments/checks/inclusion.rb
175
+ - lib/servactory/input_arguments/checks/must.rb
176
+ - lib/servactory/input_arguments/checks/required.rb
177
+ - lib/servactory/input_arguments/checks/type.rb
178
+ - lib/servactory/input_arguments/collection.rb
179
+ - lib/servactory/input_arguments/dsl.rb
180
+ - lib/servactory/input_arguments/input_argument.rb
181
+ - lib/servactory/input_arguments/tools/check.rb
182
+ - lib/servactory/input_arguments/tools/find_unnecessary.rb
183
+ - lib/servactory/input_arguments/tools/prepare.rb
184
+ - lib/servactory/input_arguments/tools/rules.rb
185
+ - lib/servactory/input_arguments/workbench.rb
186
+ - lib/servactory/inputs.rb
187
+ - lib/servactory/internal_arguments/checks/base.rb
188
+ - lib/servactory/internal_arguments/checks/type.rb
189
+ - lib/servactory/internal_arguments/collection.rb
190
+ - lib/servactory/internal_arguments/dsl.rb
191
+ - lib/servactory/internal_arguments/internal_argument.rb
192
+ - lib/servactory/internal_arguments/tools/prepare.rb
193
+ - lib/servactory/internal_arguments/workbench.rb
194
+ - lib/servactory/output_arguments/checks/base.rb
195
+ - lib/servactory/output_arguments/checks/type.rb
196
+ - lib/servactory/output_arguments/collection.rb
197
+ - lib/servactory/output_arguments/dsl.rb
198
+ - lib/servactory/output_arguments/output_argument.rb
199
+ - lib/servactory/output_arguments/tools/conflicts.rb
200
+ - lib/servactory/output_arguments/tools/prepare.rb
201
+ - lib/servactory/output_arguments/workbench.rb
202
+ - lib/servactory/result.rb
203
+ - lib/servactory/stage/dsl.rb
204
+ - lib/servactory/stage/factory.rb
205
+ - lib/servactory/stage/handyman.rb
206
+ - lib/servactory/stage/method.rb
207
+ - lib/servactory/stage/methods.rb
208
+ - lib/servactory/utils.rb
209
+ - lib/servactory/version.rb
210
+ homepage: https://github.com/afuno/servactory
211
+ licenses:
212
+ - MIT
213
+ metadata:
214
+ homepage_uri: https://github.com/afuno/servactory
215
+ source_code_uri: https://github.com/afuno/servactory
216
+ changelog_uri: https://github.com/afuno/servactory/blob/master/CHANGELOG.md
217
+ rubygems_mfa_required: 'true'
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 3.2.0
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubygems_version: 3.4.10
234
+ signing_key:
235
+ specification_version: 4
236
+ summary: A set of tools for building reliable services of any complexity
237
+ test_files: []