servactory 1.6.7 → 1.6.8

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: 66de0357d02ad9ef590de1d516d1e6d0ea2f9d19d52479cb93e4e4922d6967e5
4
+ data.tar.gz: 83f630ec6486102357ef9d4b629dbc4e4f618e55325d97592b16b7530722299f
5
5
  SHA512:
6
- metadata.gz: e9b3da95a52a025298169b2f6eea8e6b75bf538dc1ea98c4e903c3c43e50dccada335f37b6883f1cf7c1cb49ed4370a2b182ee2c05cb1c48e35b888575bdd26e
7
- data.tar.gz: d52fe6ad625529e3f5efb114cbea5331505df217802f3acfc3a68acaa61e761de770c394210d28dd16be134c2eb1003e42d6ed1dc994e8ed8ec8ddad6538e1ad
6
+ metadata.gz: 292293afa0bfc8fba8d35605cfc80b6daa75865b3c1ad9d2d1807338c5e784bab0aa94d852b2be54d9157ca8ae44e0c0b2cf9141e92b26256d11d2c08d6ad1e2
7
+ data.tar.gz: 93ca03e6db127e20eb04a244e1c48c8596cf910328ab9148543c68da8068ba0cc12be24ed366996e1d72896c88ea474a9fa61f16e2c5d1c87bbbe6ccabc95fa6
@@ -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)
@@ -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
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 6
7
- PATCH = 7
7
+ PATCH = 8
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
@@ -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