servactory 1.6.6 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8df03a33262af045766ff179c047c3260b85f182aa0541137597e13d7d50bbe
4
- data.tar.gz: 813454694dafd13757259a9c45ad455e30e4fd73013a8d51b5022624d3bd194a
3
+ metadata.gz: 66de0357d02ad9ef590de1d516d1e6d0ea2f9d19d52479cb93e4e4922d6967e5
4
+ data.tar.gz: 83f630ec6486102357ef9d4b629dbc4e4f618e55325d97592b16b7530722299f
5
5
  SHA512:
6
- metadata.gz: b61bf7ef77779b5f8c697c514a2af1baac91095c553a31ff60c9e6080233f6153eae13b24a818e527a3f887755e35c3643ffd81c47fbbabdb5c64f8dc1a98054
7
- data.tar.gz: 9722ed5fff0d2390a11636e2dc28e313cb338c726e8a9c630c4eee75ac1046a8684cb7dc7385691aaab7393bf1b9568a61b500c5a2334ca2d157d2eb239988d5
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
@@ -6,6 +6,8 @@ module Servactory
6
6
  def call!(arguments = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
7
7
  @context_store = Store.new(self)
8
8
 
9
+ context_store.context.send(:assign_service_strict_mode, true)
10
+
9
11
  assign_data_with(arguments)
10
12
 
11
13
  inputs_workbench.find_unnecessary!
@@ -31,6 +33,8 @@ module Servactory
31
33
  def call(arguments = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
32
34
  @context_store = Store.new(self)
33
35
 
36
+ context_store.context.send(:assign_service_strict_mode, false)
37
+
34
38
  assign_data_with(arguments)
35
39
 
36
40
  inputs_workbench.find_unnecessary!
@@ -29,7 +29,17 @@ module Servactory
29
29
  end
30
30
 
31
31
  def fail!(message:, meta: nil)
32
- errors << Servactory.configuration.failure_class.new(message: message, meta: meta)
32
+ failure = Servactory.configuration.failure_class.new(message: message, meta: meta)
33
+
34
+ raise failure if @service_strict_mode
35
+
36
+ errors << failure
37
+ end
38
+
39
+ private
40
+
41
+ def assign_service_strict_mode(flag)
42
+ @service_strict_mode = flag
33
43
  end
34
44
  end
35
45
  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
@@ -94,7 +94,7 @@ module Servactory
94
94
  end
95
95
 
96
96
  def prepared_value
97
- @prepared_value ||= @input.optional? && !@input.default.nil? ? @input.default : @value
97
+ @prepared_value ||= @input.optional? && !@input.default.nil? && @value.blank? ? @input.default : @value
98
98
  end
99
99
  end
100
100
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Test
5
+ class FakeType; end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Test
5
+ class Result
6
+ def initialize(**attributes)
7
+ attributes.each_pair do |method_name, method_return|
8
+ define_singleton_method(method_name) { method_return }
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 6
7
- PATCH = 6
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.6
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
@@ -247,6 +249,8 @@ files:
247
249
  - lib/servactory/outputs/validations/type.rb
248
250
  - lib/servactory/outputs/workbench.rb
249
251
  - lib/servactory/result.rb
252
+ - lib/servactory/test/fake_type.rb
253
+ - lib/servactory/test/result.rb
250
254
  - lib/servactory/utils.rb
251
255
  - lib/servactory/version.rb
252
256
  homepage: https://github.com/afuno/servactory