servactory 2.5.0.rc5 → 2.5.0.rc6

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: 81e8630b2ea211b5dc7e84b9fdb0a3617a1f6d6dd4dc257eedd1b654b79af5d5
4
- data.tar.gz: 2f91e9ecb08c940be78d22e2b737af42470fd0c9ec593a4bb8eae1f4905d0fa7
3
+ metadata.gz: fe966e4418033cec85b4d0f335a4cbfaefc5fe65e2c510bfec9a755601a088c7
4
+ data.tar.gz: b6bf04ea33fc1e3f5307406ea848fb2fb65117ec697339c99b581796ff4f568e
5
5
  SHA512:
6
- metadata.gz: f7b5ebee2a8041b78007a610b13b247df76382d33eae9f47b6d2fb2f443a1f25a67805815a756712b0f179867ee8485b3eaee61e6c03ebd4b51e0125578f77a3
7
- data.tar.gz: 1c9df4f3145e43768edfec44bf9e49d8eebd22a5d213f71d7b938be2871dfcc927e544ae5e3856f0183ac12f3ceb382ef7153c20e11a4f8b4d551a37bad0aaba
6
+ metadata.gz: '0847386548d522669a7faf2ad1fc86a41a10cec8d19b1f7c1263b8b842210b236f0c84f1fc9e1bedbd196594031b0e79e20cbaece5e5b5b2bde6efcd458ae14c'
7
+ data.tar.gz: d8bf8ebff755faebe4d7ccdefe9ab412a79e33b6b9ab888537d1a0cae7b19e78fa57b36d4e387cccdc451c37f1a2443ef5d09b6eb79118526145a8b1491581f8
@@ -55,6 +55,8 @@ module ApplicationService
55
55
  # action_shortcuts %i[assign build create save]
56
56
 
57
57
  # action_aliases %i[do_it!]
58
+
59
+ # predicate_methods_enabled false
58
60
  end
59
61
  end
60
62
  end
@@ -29,6 +29,8 @@ module Servactory
29
29
  child.config.action_aliases = config.action_aliases
30
30
  child.config.action_shortcuts = config.action_shortcuts
31
31
  child.config.action_rescue_handlers = config.action_rescue_handlers
32
+
33
+ child.config.predicate_methods_enabled = config.predicate_methods_enabled
32
34
  end
33
35
 
34
36
  def config
@@ -97,6 +97,12 @@ module Servactory
97
97
  @config.action_shortcuts.merge(action_shortcuts)
98
98
  end
99
99
 
100
+ def predicate_methods_enabled(flag)
101
+ return @config.predicate_methods_enabled = flag if boolean?(flag)
102
+
103
+ raise_error_about_wrong_predicate_methods_enabled_with(:predicate_methods_enabled, flag)
104
+ end
105
+
100
106
  private
101
107
 
102
108
  # def action_rescue_handlers(action_rescue_handlers)
@@ -111,6 +117,10 @@ module Servactory
111
117
  value.is_a?(Class) && value <= Servactory::Result
112
118
  end
113
119
 
120
+ def boolean?(value)
121
+ value.is_a?(TrueClass) || value.is_a?(FalseClass)
122
+ end
123
+
114
124
  ##########################################################################
115
125
 
116
126
  def raise_error_about_wrong_exception_class_with(config_name, value)
@@ -126,6 +136,13 @@ module Servactory
126
136
  "The `#{value}` value must be a subclass of `Servactory::Result`. " \
127
137
  "See configuration example here: https://servactory.com/guide/configuration"
128
138
  end
139
+
140
+ def raise_error_about_wrong_predicate_methods_enabled_with(config_name, value)
141
+ raise ArgumentError,
142
+ "Error in `#{config_name}` configuration. " \
143
+ "The `#{value}` value must be `TrueClass` or `FalseClass`. " \
144
+ "See configuration example here: https://servactory.com/guide/configuration"
145
+ end
129
146
  end
130
147
  end
131
148
  end
@@ -16,7 +16,8 @@ module Servactory
16
16
  :output_option_helpers,
17
17
  :action_aliases,
18
18
  :action_shortcuts,
19
- :action_rescue_handlers
19
+ :action_rescue_handlers,
20
+ :predicate_methods_enabled
20
21
 
21
22
  def initialize # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
22
23
  @input_exception_class = Servactory::Exceptions::Input
@@ -46,6 +47,12 @@ module Servactory
46
47
  @action_aliases = Servactory::Actions::Aliases::Collection.new
47
48
  @action_shortcuts = Servactory::Actions::Shortcuts::Collection.new
48
49
  @action_rescue_handlers = Servactory::Actions::RescueHandlers::Collection.new
50
+
51
+ @predicate_methods_enabled = true
52
+ end
53
+
54
+ def predicate_methods_enabled?
55
+ @predicate_methods_enabled
49
56
  end
50
57
 
51
58
  private
@@ -43,7 +43,8 @@ module Servactory
43
43
 
44
44
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
45
45
  def getter_with(name:, &block)
46
- input_name = name.to_s.chomp("?").to_sym
46
+ input_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
47
+
47
48
  input = @collection_of_inputs.find_by(name: input_name)
48
49
 
49
50
  return yield if input.nil?
@@ -58,7 +59,7 @@ module Servactory
58
59
  input_prepare = input.prepare.fetch(:in, nil)
59
60
  input_value = input_prepare.call(value: input_value) if input_prepare.present?
60
61
 
61
- if name.to_s.end_with?("?")
62
+ if name.to_s.end_with?("?") && @context.class.config.predicate_methods_enabled?
62
63
  Servactory::Utils.query_attribute(input_value)
63
64
  else
64
65
  input_value
@@ -53,15 +53,15 @@ module Servactory
53
53
  @context.send(:servactory_service_store).assign_internal(internal.name, value)
54
54
  end
55
55
 
56
- def getter_with(name:, &block) # rubocop:disable Lint/UnusedMethodArgument
57
- internal_name = name.to_s.chomp("?").to_sym
56
+ def getter_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
57
+ internal_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
58
58
  internal = @collection_of_internals.find_by(name: internal_name)
59
59
 
60
60
  return yield if internal.nil?
61
61
 
62
62
  internal_value = @context.send(:servactory_service_store).fetch_internal(internal.name)
63
63
 
64
- if name.to_s.end_with?("?")
64
+ if name.to_s.end_with?("?") && @context.class.config.predicate_methods_enabled?
65
65
  Servactory::Utils.query_attribute(internal_value)
66
66
  else
67
67
  internal_value
@@ -53,15 +53,15 @@ module Servactory
53
53
  @context.send(:servactory_service_store).assign_output(output.name, value)
54
54
  end
55
55
 
56
- def getter_with(name:, &block) # rubocop:disable Lint/UnusedMethodArgument
57
- output_name = name.to_s.chomp("?").to_sym
56
+ def getter_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
57
+ output_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
58
58
  output = @collection_of_outputs.find_by(name: output_name)
59
59
 
60
60
  return yield if output.nil?
61
61
 
62
62
  output_value = @context.send(:servactory_service_store).fetch_output(output.name)
63
63
 
64
- if name.to_s.end_with?("?")
64
+ if name.to_s.end_with?("?") && @context.class.config.predicate_methods_enabled?
65
65
  Servactory::Utils.query_attribute(output_value)
66
66
  else
67
67
  output_value
@@ -3,9 +3,9 @@
3
3
  module Servactory
4
4
  class Result
5
5
  class Outputs
6
- def initialize(outputs)
6
+ def initialize(outputs:, predicate_methods_enabled:)
7
7
  outputs.each_pair do |key, value|
8
- define_singleton_method(:"#{key}?") { Servactory::Utils.query_attribute(value) }
8
+ define_singleton_method(:"#{key}?") { Servactory::Utils.query_attribute(value) } if predicate_methods_enabled
9
9
  define_singleton_method(key) { value }
10
10
  end
11
11
  end
@@ -104,7 +104,14 @@ module Servactory
104
104
  end
105
105
 
106
106
  def outputs
107
- @outputs ||= Outputs.new(@context.send(:servactory_service_store).outputs)
107
+ @outputs ||= Outputs.new(
108
+ outputs: @context.send(:servactory_service_store).outputs,
109
+ predicate_methods_enabled: if @context.is_a?(Servactory::TestKit::Result)
110
+ true
111
+ else
112
+ @context.class.config.predicate_methods_enabled?
113
+ end
114
+ )
108
115
  end
109
116
 
110
117
  ########################################################################
@@ -5,7 +5,7 @@ module Servactory
5
5
  MAJOR = 2
6
6
  MINOR = 5
7
7
  PATCH = 0
8
- PRE = "rc5"
8
+ PRE = "rc6"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  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: 2.5.0.rc5
4
+ version: 2.5.0.rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov