servactory 1.9.6 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/config/locales/en.yml +19 -4
  3. data/config/locales/ru.yml +21 -6
  4. data/lib/servactory/{methods/method.rb → actions/action.rb} +2 -2
  5. data/lib/servactory/{methods/aliases_for_make → actions/aliases}/collection.rb +2 -2
  6. data/lib/servactory/{methods/method_collection.rb → actions/collection.rb} +3 -3
  7. data/lib/servactory/{methods → actions}/dsl.rb +9 -9
  8. data/lib/servactory/{methods/shortcuts_for_make → actions/shortcuts}/collection.rb +2 -2
  9. data/lib/servactory/actions/stages/collection.rb +20 -0
  10. data/lib/servactory/actions/stages/stage.rb +30 -0
  11. data/lib/servactory/{methods → actions}/tools/runner.rb +1 -1
  12. data/lib/servactory/{methods → actions}/workspace.rb +4 -2
  13. data/lib/servactory/base.rb +1 -1
  14. data/lib/servactory/configuration/dsl.rb +4 -2
  15. data/lib/servactory/configuration/factory.rb +12 -4
  16. data/lib/servactory/configuration/setup.rb +24 -8
  17. data/lib/servactory/context/workspace/inputs.rb +43 -7
  18. data/lib/servactory/context/workspace/outputs.rb +1 -1
  19. data/lib/servactory/context/workspace.rb +0 -4
  20. data/lib/servactory/dsl.rb +18 -1
  21. data/lib/servactory/inputs/collection.rb +1 -1
  22. data/lib/servactory/inputs/dsl.rb +2 -0
  23. data/lib/servactory/inputs/input.rb +106 -88
  24. data/lib/servactory/inputs/tools/distributor.rb +24 -0
  25. data/lib/servactory/inputs/tools/rules.rb +3 -3
  26. data/lib/servactory/inputs/tools/{find_unnecessary.rb → unnecessary.rb} +4 -4
  27. data/lib/servactory/inputs/tools/validation.rb +5 -7
  28. data/lib/servactory/inputs/validations/base.rb +1 -1
  29. data/lib/servactory/inputs/validations/inclusion.rb +15 -10
  30. data/lib/servactory/inputs/validations/must.rb +26 -17
  31. data/lib/servactory/inputs/validations/required.rb +16 -11
  32. data/lib/servactory/inputs/validations/type.rb +19 -69
  33. data/lib/servactory/inputs/workspace.rb +6 -3
  34. data/lib/servactory/internals/dsl.rb +6 -1
  35. data/lib/servactory/internals/internal.rb +81 -14
  36. data/lib/servactory/internals/validations/base.rb +1 -1
  37. data/lib/servactory/internals/validations/type.rb +6 -43
  38. data/lib/servactory/maintenance/attributes/define_conflict.rb +15 -0
  39. data/lib/servactory/maintenance/attributes/define_method.rb +17 -0
  40. data/lib/servactory/maintenance/attributes/option.rb +121 -0
  41. data/lib/servactory/maintenance/attributes/option_helper.rb +17 -0
  42. data/lib/servactory/maintenance/attributes/option_helpers_collection.rb +20 -0
  43. data/lib/servactory/maintenance/attributes/options_collection.rb +48 -0
  44. data/lib/servactory/maintenance/collection_mode/class_names_collection.rb +16 -0
  45. data/lib/servactory/maintenance/hash_mode/class_names_collection.rb +16 -0
  46. data/lib/servactory/maintenance/validations/collection.rb +66 -0
  47. data/lib/servactory/maintenance/validations/object_schema.rb +116 -0
  48. data/lib/servactory/maintenance/validations/types.rb +181 -0
  49. data/lib/servactory/outputs/dsl.rb +6 -1
  50. data/lib/servactory/outputs/output.rb +79 -19
  51. data/lib/servactory/outputs/validations/base.rb +1 -1
  52. data/lib/servactory/outputs/validations/type.rb +6 -45
  53. data/lib/servactory/version.rb +5 -4
  54. data/lib/servactory.rb +1 -1
  55. metadata +56 -30
  56. data/lib/servactory/inputs/define_input_conflict.rb +0 -13
  57. data/lib/servactory/inputs/define_input_method.rb +0 -15
  58. data/lib/servactory/inputs/option.rb +0 -98
  59. data/lib/servactory/inputs/option_helper.rb +0 -15
  60. data/lib/servactory/inputs/option_helpers_collection.rb +0 -18
  61. data/lib/servactory/inputs/options_collection.rb +0 -46
  62. data/lib/servactory/methods/stage.rb +0 -28
  63. data/lib/servactory/methods/stage_collection.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 024a5ab65e8e000967f41494655da939111a0a43b4f6d4a941b28daff015def8
4
- data.tar.gz: 7ae8df0285b2d9510ddabcbb92d2f0b8061ac74490b0a129793c4a389027bcc2
3
+ metadata.gz: a360afbf0c2646c3509ad3f37cb49e4a59453ded9f741a012965d962565285e4
4
+ data.tar.gz: 47a2bca86fc7622a7fa5e8a70bbb9cac4c179e3a43ee67ee050e6c5dd7b0cb21
5
5
  SHA512:
6
- metadata.gz: 1a7541d4d78732b0dcbf549ca15460a96625c1e1a342bb5a6046f18f3e7b036eed2e1e2f44e90db3c70a25f2b0dfdc4ce755d7af1c73f5824d06b54e2329d8e4
7
- data.tar.gz: 4cc045df6054d694587c2038de8e63a1e1eda45d93a8912ecdee2d6bfcd42b9955a196c6f8d2f49a9076b078c2dd248d816b6526307961e89fcb5e151c2c894c
6
+ metadata.gz: d6e1c489135e42759ee1bae986ed590aaf01164f8243a77b24a8a0b13d37056f4f5de3b86c1b741a94bbee8abe87656be6ad351818de32cc01a255af68d4db7e
7
+ data.tar.gz: 379633b8ddee7e378eafabacc9b97ced01375daa8612ce6b162c054674a6aac825093670602a92e2b03594c76f4f5dc22de9cbec25dcfa3770b0e73f102860fa
@@ -13,11 +13,14 @@ en:
13
13
  required:
14
14
  default_error:
15
15
  default: "[%{service_class_name}] Required input `%{input_name}` is missing"
16
- for_array: "[%{service_class_name}] Required element in input array `%{input_name}` is missing"
16
+ for_collection: "[%{service_class_name}] Required element in input collection `%{input_name}` is missing"
17
17
  type:
18
18
  default_error:
19
19
  default: "[%{service_class_name}] Wrong type of input `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
20
- for_array: "[%{service_class_name}] Wrong type in input array `%{input_name}`, expected `%{expected_type}`"
20
+ for_collection:
21
+ wrong_element_type: "[%{service_class_name}] Wrong type in input collection `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
22
+ for_hash:
23
+ wrong_element_type: "[%{service_class_name}] Wrong type in input hash `%{input_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
21
24
  tools:
22
25
  find_unnecessary:
23
26
  error: "[%{service_class_name}] Unexpected attributes: `%{unnecessary_attributes}`"
@@ -29,14 +32,26 @@ en:
29
32
  setter: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
30
33
  checks:
31
34
  type:
32
- default_error: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
35
+ default_error:
36
+ default: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
37
+ for_collection:
38
+ wrong_type: "[%{service_class_name}] Wrong internal attribute collection type `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
39
+ wrong_element_type: "[%{service_class_name}] Wrong element type in internal attribute collection `%{internal_name}`, expected `%{expected_type}`"
40
+ for_hash:
41
+ wrong_element_type: "[%{service_class_name}] Wrong type in internal attribute hash `%{internal_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
33
42
  outputs:
34
43
  undefined:
35
44
  getter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
36
45
  setter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
37
46
  checks:
38
47
  type:
39
- default_error: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
48
+ default_error:
49
+ default: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
50
+ for_collection:
51
+ wrong_type: "[%{service_class_name}] Wrong output attribute collection type `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
52
+ wrong_element_type: "[%{service_class_name}] Wrong element type in output attribute collection `%{output_name}`, expected `%{expected_type}`"
53
+ for_hash:
54
+ wrong_element_type: "[%{service_class_name}] Wrong type in output attribute hash `%{output_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
40
55
  methods:
41
56
  call:
42
57
  not_used: Nothing to perform. Use `make` or create a `call` method.
@@ -6,18 +6,22 @@ ru:
6
6
  setter: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
7
7
  checks:
8
8
  inclusion:
9
- default_error: "[%{service_class_name}] Неверное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
9
+ default_error: "[%{service_class_name}] Неправильное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
10
10
  must:
11
11
  default_error: "[%{service_class_name}] Инпут `%{input_name}` должен \"%{code}\""
12
12
  syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` инпута `%{input_name}`"
13
13
  required:
14
14
  default_error:
15
15
  default: "[%{service_class_name}] Обязательный инпут `%{input_name}` отсутствует"
16
- for_array: "[%{service_class_name}] Обязательный элемент в инпуте-массиве `%{input_name}` отсутствует"
16
+ for_collection: "[%{service_class_name}] Обязательный элемент в коллекции инпута `%{input_name}` отсутствует"
17
17
  type:
18
18
  default_error:
19
- default: "[%{service_class_name}] Неверный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
20
- for_array: "[%{service_class_name}] Неверный тип инпута-массива `%{input_name}`, ожидалось `%{expected_type}`"
19
+ default: "[%{service_class_name}] Неправильный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
20
+ for_collection:
21
+ wrong_element_type: "[%{service_class_name}] Неправильный тип в коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
22
+ for_hash:
23
+ wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше инпута `%{input_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
24
+
21
25
  tools:
22
26
  find_unnecessary:
23
27
  error: "[%{service_class_name}] Неожиданные атрибуты: `%{unnecessary_attributes}`"
@@ -29,14 +33,25 @@ ru:
29
33
  setter: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
30
34
  checks:
31
35
  type:
32
- default_error: "[%{service_class_name}] Неверный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
36
+ default_error:
37
+ default: "[%{service_class_name}] Неправильный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
38
+ for_collection:
39
+ wrong_type: "[%{service_class_name}] Неправильный тип коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
40
+ wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`"
41
+ for_hash:
42
+ wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
33
43
  outputs:
34
44
  undefined:
35
45
  getter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
36
46
  setter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
37
47
  checks:
38
48
  type:
39
- default_error: "[%{service_class_name}] Неверный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
49
+ default: "[%{service_class_name}] Неправильный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
50
+ for_collection:
51
+ wrong_type: "[%{service_class_name}] Неправильный тип коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
52
+ wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`"
53
+ for_hash:
54
+ wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше выходящего атрибута `%{output_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
40
55
  methods:
41
56
  call:
42
57
  not_used: Нечего исполнять. Используйте `make` или создайте метод `call`.
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
5
- class Method
4
+ module Actions
5
+ class Action
6
6
  attr_reader :name,
7
7
  :position,
8
8
  :condition,
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
5
- module AliasesForMake
4
+ module Actions
5
+ module Aliases
6
6
  class Collection
7
7
  extend Forwardable
8
8
  def_delegators :@collection, :<<, :merge, :include?
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
5
- class MethodCollection
4
+ module Actions
5
+ class Collection
6
6
  extend Forwardable
7
7
  def_delegators :@collection, :<<, :each, :sort_by
8
8
 
@@ -11,7 +11,7 @@ module Servactory
11
11
  end
12
12
 
13
13
  def sorted_by_position
14
- MethodCollection.new(sort_by(&:position))
14
+ Collection.new(sort_by(&:position))
15
15
  end
16
16
  end
17
17
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
4
+ module Actions
5
5
  module DSL
6
6
  def self.included(base)
7
7
  base.extend(ClassMethods)
@@ -18,7 +18,7 @@ module Servactory
18
18
  private
19
19
 
20
20
  def stage(&block)
21
- @current_stage = Stage.new(position: next_position)
21
+ @current_stage = Stages::Stage.new(position: next_position)
22
22
 
23
23
  instance_eval(&block)
24
24
 
@@ -56,9 +56,9 @@ module Servactory
56
56
  def make(name, position: nil, **options)
57
57
  position = position.presence || next_position
58
58
 
59
- current_stage = @current_stage.presence || Stage.new(position: position)
59
+ current_stage = @current_stage.presence || Stages::Stage.new(position: position)
60
60
 
61
- current_stage.methods << Method.new(
61
+ current_stage.methods << Action.new(
62
62
  name,
63
63
  position: position,
64
64
  **options
@@ -68,14 +68,14 @@ module Servactory
68
68
  end
69
69
 
70
70
  def method_missing(name, *args, &block)
71
- return method_missing_for_aliases_for_make(name, *args, &block) if config.aliases_for_make.include?(name)
71
+ return method_missing_for_action_aliases(name, *args, &block) if config.action_aliases.include?(name)
72
72
 
73
- return method_missing_for_shortcuts_for_make(name, *args, &block) if config.shortcuts_for_make.include?(name)
73
+ return method_missing_for_shortcuts_for_make(name, *args, &block) if config.action_shortcuts.include?(name)
74
74
 
75
75
  super
76
76
  end
77
77
 
78
- def method_missing_for_aliases_for_make(_alias_name, *args, &block) # rubocop:disable Lint/UnusedMethodArgument
78
+ def method_missing_for_action_aliases(_alias_name, *args, &block) # rubocop:disable Lint/UnusedMethodArgument
79
79
  method_name = args.first
80
80
  method_options = args.last.is_a?(Hash) ? args.pop : {}
81
81
 
@@ -93,7 +93,7 @@ module Servactory
93
93
  end
94
94
 
95
95
  def respond_to_missing?(name, *)
96
- config.aliases_for_make.include?(name) || config.shortcuts_for_make.include?(name) || super
96
+ config.action_aliases.include?(name) || config.action_shortcuts.include?(name) || super
97
97
  end
98
98
 
99
99
  def next_position
@@ -101,7 +101,7 @@ module Servactory
101
101
  end
102
102
 
103
103
  def collection_of_stages
104
- @collection_of_stages ||= StageCollection.new
104
+ @collection_of_stages ||= Stages::Collection.new
105
105
  end
106
106
  end
107
107
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
5
- module ShortcutsForMake
4
+ module Actions
5
+ module Shortcuts
6
6
  class Collection
7
7
  extend Forwardable
8
8
  def_delegators :@collection, :<<, :each, :merge, :include?
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Actions
5
+ module Stages
6
+ class Collection
7
+ extend Forwardable
8
+ def_delegators :@collection, :<<, :each, :merge, :sort_by, :size, :empty?
9
+
10
+ def initialize(collection = Set.new)
11
+ @collection = collection
12
+ end
13
+
14
+ def sorted_by_position
15
+ Collection.new(sort_by(&:position))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Actions
5
+ module Stages
6
+ class Stage
7
+ attr_accessor :position,
8
+ :wrapper,
9
+ :rollback,
10
+ :condition,
11
+ :is_condition_opposite
12
+
13
+ def initialize(position:, wrapper: nil, rollback: nil, condition: nil)
14
+ @position = position
15
+ @wrapper = wrapper
16
+ @rollback = rollback
17
+ @condition = condition
18
+ end
19
+
20
+ def next_method_position
21
+ methods.size + 1
22
+ end
23
+
24
+ def methods
25
+ @methods ||= Collection.new
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
4
+ module Actions
5
5
  module Tools
6
6
  class Runner
7
7
  def self.run!(...)
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Methods
4
+ module Actions
5
5
  module Workspace
6
+ private
7
+
6
8
  def call!(collection_of_stages:, **)
7
9
  super
8
10
 
9
- Servactory::Methods::Tools::Runner.run!(self, collection_of_stages)
11
+ Servactory::Actions::Tools::Runner.run!(self, collection_of_stages)
10
12
  end
11
13
  end
12
14
  end
@@ -8,7 +8,7 @@ module Servactory
8
8
  include Inputs::DSL
9
9
  include Internals::DSL
10
10
  include Outputs::DSL
11
- include Methods::DSL
11
+ include Actions::DSL
12
12
 
13
13
  private_class_method :new
14
14
  end
@@ -17,10 +17,12 @@ module Servactory
17
17
 
18
18
  child.config.failure_class = config.failure_class
19
19
 
20
+ child.config.collection_mode_class_names = config.collection_mode_class_names
21
+
20
22
  child.config.input_option_helpers = config.input_option_helpers
21
23
 
22
- child.config.aliases_for_make = config.aliases_for_make
23
- child.config.shortcuts_for_make = config.shortcuts_for_make
24
+ child.config.action_aliases = config.action_aliases
25
+ child.config.action_shortcuts = config.action_shortcuts
24
26
  end
25
27
 
26
28
  def config
@@ -23,16 +23,24 @@ module Servactory
23
23
  @config.failure_class = failure_class
24
24
  end
25
25
 
26
+ def collection_mode_class_names(collection_mode_class_names)
27
+ @config.collection_mode_class_names.merge(collection_mode_class_names)
28
+ end
29
+
30
+ def hash_mode_class_names(hash_mode_class_names)
31
+ @config.hash_mode_class_names.merge(hash_mode_class_names)
32
+ end
33
+
26
34
  def input_option_helpers(input_option_helpers)
27
35
  @config.input_option_helpers.merge(input_option_helpers)
28
36
  end
29
37
 
30
- def aliases_for_make(aliases_for_make)
31
- @config.aliases_for_make.merge(aliases_for_make)
38
+ def action_aliases(action_aliases)
39
+ @config.action_aliases.merge(action_aliases)
32
40
  end
33
41
 
34
- def shortcuts_for_make(shortcuts_for_make)
35
- @config.shortcuts_for_make.merge(shortcuts_for_make)
42
+ def action_shortcuts(action_shortcuts)
43
+ @config.action_shortcuts.merge(action_shortcuts)
36
44
  end
37
45
  end
38
46
  end
@@ -7,29 +7,45 @@ module Servactory
7
7
  :internal_error_class,
8
8
  :output_error_class,
9
9
  :failure_class,
10
+ :collection_mode_class_names,
11
+ :hash_mode_class_names,
10
12
  :input_option_helpers,
11
- :aliases_for_make,
12
- :shortcuts_for_make
13
+ :action_aliases,
14
+ :action_shortcuts
13
15
 
14
- def initialize
16
+ def initialize # rubocop:disable Metrics/MethodLength
15
17
  @input_error_class = Servactory::Errors::InputError
16
18
  @internal_error_class = Servactory::Errors::InternalError
17
19
  @output_error_class = Servactory::Errors::OutputError
18
20
 
19
21
  @failure_class = Servactory::Errors::Failure
20
22
 
21
- @input_option_helpers = Servactory::Inputs::OptionHelpersCollection.new(default_input_option_helpers)
23
+ @collection_mode_class_names =
24
+ Servactory::Maintenance::CollectionMode::ClassNamesCollection.new(default_collection_mode_class_names)
22
25
 
23
- @aliases_for_make = Servactory::Methods::AliasesForMake::Collection.new
24
- @shortcuts_for_make = Servactory::Methods::ShortcutsForMake::Collection.new
26
+ @hash_mode_class_names =
27
+ Servactory::Maintenance::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
28
+
29
+ @input_option_helpers =
30
+ Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_input_option_helpers)
31
+
32
+ @action_aliases = Servactory::Actions::Aliases::Collection.new
33
+ @action_shortcuts = Servactory::Actions::Shortcuts::Collection.new
25
34
  end
26
35
 
27
36
  private
28
37
 
38
+ def default_collection_mode_class_names
39
+ Set[Array, Set]
40
+ end
41
+
42
+ def default_hash_mode_class_names
43
+ Set[Hash]
44
+ end
45
+
29
46
  def default_input_option_helpers
30
47
  Set[
31
- Servactory::Inputs::OptionHelper.new(name: :optional, equivalent: { required: false }),
32
- Servactory::Inputs::OptionHelper.new(name: :as_array, equivalent: { array: true })
48
+ Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
33
49
  ]
34
50
  end
35
51
  end
@@ -4,9 +4,11 @@ module Servactory
4
4
  module Context
5
5
  module Workspace
6
6
  class Inputs
7
- def initialize(context:, incoming_arguments:, collection_of_inputs:)
7
+ RESERVED_ATTRIBUTES = %i[type required default].freeze
8
+ private_constant :RESERVED_ATTRIBUTES
9
+
10
+ def initialize(context:, collection_of_inputs:)
8
11
  @context = context
9
- @incoming_arguments = incoming_arguments
10
12
  @collection_of_inputs = collection_of_inputs
11
13
  end
12
14
 
@@ -44,19 +46,53 @@ module Servactory
44
46
 
45
47
  return yield if input.nil?
46
48
 
47
- input_value = @incoming_arguments.fetch(input.name, nil)
48
- input_value = input.default if input.optional? && input_value.blank?
49
+ input.value = input.default if input.optional? && input.value.blank?
50
+
51
+ if input.hash_mode? && (tmp_schema = input.schema.fetch(:is)).present?
52
+ input.value = prepare_hash_values_inside(object: input.value, schema: tmp_schema)
53
+ end
49
54
 
50
55
  input_prepare = input.prepare.fetch(:in, nil)
51
- input_value = input_prepare.call(value: input_value) if input_prepare.present?
56
+ input.value = input_prepare.call(value: input.value) if input_prepare.present?
52
57
 
53
58
  if name.to_s.end_with?("?")
54
- Servactory::Utils.query_attribute(input_value)
59
+ Servactory::Utils.query_attribute(input.value)
55
60
  else
56
- input_value
61
+ input.value
62
+ end
63
+ end
64
+
65
+ def prepare_hash_values_inside(object:, schema:) # rubocop:disable Metrics/MethodLength
66
+ return object unless object.respond_to?(:fetch)
67
+
68
+ schema.to_h do |schema_key, schema_value|
69
+ attribute_type = schema_value.fetch(:type, String)
70
+
71
+ result =
72
+ if attribute_type == Hash
73
+ prepare_hash_values_inside(
74
+ object: object.fetch(schema_key, {}),
75
+ schema: schema_value.except(*RESERVED_ATTRIBUTES)
76
+ )
77
+ else
78
+ fetch_hash_values_from(
79
+ value: object.fetch(schema_key, {}),
80
+ schema_value: schema_value,
81
+ attribute_required: schema_value.fetch(:required, true)
82
+ )
83
+ end
84
+
85
+ [schema_key, result]
57
86
  end
58
87
  end
59
88
 
89
+ def fetch_hash_values_from(value:, schema_value:, attribute_required:)
90
+ return value if attribute_required
91
+ return value if value.present?
92
+
93
+ schema_value.fetch(:default, nil)
94
+ end
95
+
60
96
  def raise_error_for(type, name)
61
97
  message_text = I18n.t(
62
98
  "servactory.inputs.undefined.#{type}",
@@ -40,7 +40,7 @@ module Servactory
40
40
  def setter_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
41
41
  return yield unless @collection_of_outputs.names.include?(prepared_name)
42
42
 
43
- output = @collection_of_outputs.find_by(name: prepared_name) # ::Servactory::Outputs::Output
43
+ output = @collection_of_outputs.find_by(name: prepared_name)
44
44
 
45
45
  return yield if output.nil?
46
46
 
@@ -6,11 +6,9 @@ module Servactory
6
6
  def inputs
7
7
  @inputs ||= Inputs.new(
8
8
  context: self,
9
- incoming_arguments: incoming_arguments,
10
9
  collection_of_inputs: collection_of_inputs
11
10
  )
12
11
  end
13
- alias inp inputs
14
12
 
15
13
  def internals
16
14
  @internals ||= Internals.new(
@@ -18,7 +16,6 @@ module Servactory
18
16
  collection_of_internals: collection_of_internals
19
17
  )
20
18
  end
21
- alias int internals
22
19
 
23
20
  def outputs
24
21
  @outputs ||= Outputs.new(
@@ -26,7 +23,6 @@ module Servactory
26
23
  collection_of_outputs: collection_of_outputs
27
24
  )
28
25
  end
29
- alias out outputs
30
26
 
31
27
  def fail_input!(input_name, message:)
32
28
  raise self.class.config.input_error_class.new(
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Servactory
4
4
  module DSL
5
+ @extensions = []
6
+
5
7
  def self.included(base)
6
8
  base.include(Configuration::DSL)
7
9
  base.include(Info::DSL)
@@ -9,7 +11,22 @@ module Servactory
9
11
  base.include(Inputs::DSL)
10
12
  base.include(Internals::DSL)
11
13
  base.include(Outputs::DSL)
12
- base.include(Methods::DSL)
14
+
15
+ extensions.each { |extension| base.include(extension) }
16
+
17
+ base.include(Actions::DSL)
13
18
  end
19
+
20
+ def self.with_extensions(*extensions)
21
+ @extensions = extensions
22
+
23
+ self
24
+ end
25
+
26
+ def self.extensions
27
+ @extensions
28
+ end
29
+
30
+ private_class_method :extensions
14
31
  end
15
32
  end
@@ -4,7 +4,7 @@ module Servactory
4
4
  module Inputs
5
5
  class Collection
6
6
  extend Forwardable
7
- def_delegators :@collection, :<<, :filter, :each, :map, :to_h, :merge, :find
7
+ def_delegators :@collection, :<<, :filter, :each, :map, :flat_map, :to_h, :merge, :find
8
8
 
9
9
  def initialize(collection = Set.new)
10
10
  @collection = collection
@@ -21,6 +21,8 @@ module Servactory
21
21
  collection_of_inputs << Input.new(
22
22
  name,
23
23
  *helpers,
24
+ collection_mode_class_names: config.collection_mode_class_names,
25
+ hash_mode_class_names: config.hash_mode_class_names,
24
26
  option_helpers: config.input_option_helpers,
25
27
  **options
26
28
  )