servactory 1.6.7 → 1.6.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36958cd40c5a7f821265cbbaa4509262da61fb1dcb799d9ba57433012d2e35c1
4
- data.tar.gz: 3a7a5736e738bc71be30ddef3bee4c536c108a29f24493da9359aa3cfd3eef3c
3
+ metadata.gz: 2c500354cf4e4fdb64d43928419b2d5d90eb99a7f4075bb7b92c78fa0f498748
4
+ data.tar.gz: ffd1d27087d1f5ad5457738c20cda5cb9fa73821fca05cc9cf3161c0c035fb71
5
5
  SHA512:
6
- metadata.gz: e9b3da95a52a025298169b2f6eea8e6b75bf538dc1ea98c4e903c3c43e50dccada335f37b6883f1cf7c1cb49ed4370a2b182ee2c05cb1c48e35b888575bdd26e
7
- data.tar.gz: d52fe6ad625529e3f5efb114cbea5331505df217802f3acfc3a68acaa61e761de770c394210d28dd16be134c2eb1003e42d6ed1dc994e8ed8ec8ddad6538e1ad
6
+ metadata.gz: '039459dc8df65093417fe4b6703783e43ace1c401f86b9b067d5ce3aeeebd0f64866561904a15ea299c2be15224fb66a1fe71dfc8477d7e0f12458f086c09b8a'
7
+ data.tar.gz: 794a191acdc4f2d94d8b827d05c1994a4e644a2124ac2e8fc83106abcfdeb80b35fc069a413c89cf98fc43b22b5f343bb96070d38ed05ffd3f7123d741fc3256
@@ -19,6 +19,10 @@ module Servactory
19
19
  Servactory.configuration.failure_class = failure_class
20
20
  end
21
21
 
22
+ def input_option_helpers(input_option_helpers)
23
+ Servactory.configuration.input_option_helpers.merge(input_option_helpers)
24
+ end
25
+
22
26
  def method_shortcuts(method_shortcuts)
23
27
  Servactory.configuration.method_shortcuts.merge(method_shortcuts)
24
28
  end
@@ -7,6 +7,7 @@ module Servactory
7
7
  :internal_error_class,
8
8
  :output_error_class,
9
9
  :failure_class,
10
+ :input_option_helpers,
10
11
  :method_shortcuts
11
12
 
12
13
  def initialize
@@ -16,8 +17,20 @@ module Servactory
16
17
 
17
18
  @failure_class = Servactory::Errors::Failure
18
19
 
20
+ @input_option_helpers = Servactory::Inputs::OptionHelpersCollection.new(default_input_option_helpers)
21
+
19
22
  @method_shortcuts = Servactory::Methods::Shortcuts::Collection.new
20
23
  end
24
+
25
+ private
26
+
27
+ def default_input_option_helpers
28
+ Set[
29
+ Servactory::Inputs::OptionHelper.new(name: :optional, equivalent: { required: false }),
30
+ Servactory::Inputs::OptionHelper.new(name: :internal, equivalent: { internal: true }),
31
+ Servactory::Inputs::OptionHelper.new(name: :as_array, equivalent: { array: true })
32
+ ]
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -5,13 +5,7 @@ module Servactory
5
5
  class Input # rubocop:disable Metrics/ClassLength
6
6
  ARRAY_DEFAULT_VALUE = ->(is: false, message: nil) { { is: is, message: message } }
7
7
 
8
- HELPER_LIBRARY = {
9
- optional: { required: false },
10
- internal: { internal: true },
11
- as_array: { array: true }
12
- }.freeze
13
-
14
- private_constant :ARRAY_DEFAULT_VALUE, :HELPER_LIBRARY
8
+ private_constant :ARRAY_DEFAULT_VALUE
15
9
 
16
10
  attr_reader :name,
17
11
  :internal_name
@@ -43,11 +37,11 @@ module Servactory
43
37
  prepared_options = {}
44
38
 
45
39
  helpers.each do |helper|
46
- next unless HELPER_LIBRARY.key?(helper)
40
+ found_helper = Servactory.configuration.input_option_helpers.find_by(name: helper)
47
41
 
48
- found_helper = HELPER_LIBRARY[helper]
42
+ next if found_helper.blank?
49
43
 
50
- prepared_options.merge!(found_helper)
44
+ prepared_options.merge!(found_helper.equivalent)
51
45
  end
52
46
 
53
47
  options.merge(prepared_options)
@@ -69,6 +63,7 @@ module Servactory
69
63
  add_must_option_with(options)
70
64
 
71
65
  # Check Class: nil
66
+ add_prepare_option_with(options)
72
67
  add_internal_option_with(options)
73
68
  end
74
69
 
@@ -186,6 +181,29 @@ module Servactory
186
181
  )
187
182
  end
188
183
 
184
+ def add_prepare_option_with(options)
185
+ collection_of_options << Option.new(
186
+ name: :prepare,
187
+ input: self,
188
+ validation_class: nil,
189
+ define_input_methods: [
190
+ DefineInputMethod.new(
191
+ name: :prepare_present?,
192
+ content: ->(value:) { value[:in].present? }
193
+ )
194
+ ],
195
+ define_input_conflicts: [
196
+ DefineInputConflict.new(content: -> { :prepare_vs_array if prepare_present? && array? }),
197
+ DefineInputConflict.new(content: -> { :prepare_vs_inclusion if prepare_present? && inclusion_present? }),
198
+ DefineInputConflict.new(content: -> { :prepare_vs_must if prepare_present? && must_present? })
199
+ ],
200
+ need_for_checks: false,
201
+ value_key: :in,
202
+ value_fallback: false,
203
+ **options
204
+ )
205
+ end
206
+
189
207
  def add_internal_option_with(options) # rubocop:disable Metrics/MethodLength
190
208
  collection_of_options << Option.new(
191
209
  name: :internal,
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Inputs
5
+ class OptionHelper
6
+ attr_reader :name,
7
+ :equivalent
8
+
9
+ def initialize(name:, equivalent:)
10
+ @name = name
11
+ @equivalent = equivalent
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Inputs
5
+ class OptionHelpersCollection
6
+ # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
+ extend Forwardable
8
+ def_delegators :@collection, :<<, :find, :merge
9
+
10
+ def initialize(collection)
11
+ @collection = collection
12
+ end
13
+
14
+ def find_by(name:)
15
+ find { |helper| helper.name == name }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -31,6 +31,9 @@ module Servactory
31
31
  input_value = @incoming_arguments.fetch(input.name, nil)
32
32
  input_value = input.default if input.optional? && input_value.blank?
33
33
 
34
+ input_prepare = input.prepare.fetch(:in, nil)
35
+ input_value = input_prepare.call(value: input_value) if input_prepare.present?
36
+
34
37
  if input.internal?
35
38
  @internal_variables[input.name] = input_value
36
39
  else
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 6
7
- PATCH = 7
7
+ PATCH = 9
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 1.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-10 00:00:00.000000000 Z
11
+ date: 2023-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -211,6 +211,8 @@ files:
211
211
  - lib/servactory/inputs/dsl.rb
212
212
  - lib/servactory/inputs/input.rb
213
213
  - lib/servactory/inputs/option.rb
214
+ - lib/servactory/inputs/option_helper.rb
215
+ - lib/servactory/inputs/option_helpers_collection.rb
214
216
  - lib/servactory/inputs/options_collection.rb
215
217
  - lib/servactory/inputs/tools/check_errors.rb
216
218
  - lib/servactory/inputs/tools/find_unnecessary.rb