servactory 1.8.4 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/servactory/context/workspace/inputs.rb +7 -2
- data/lib/servactory/context/workspace/internals.rb +9 -2
- data/lib/servactory/context/workspace/outputs.rb +9 -2
- data/lib/servactory/result.rb +1 -0
- data/lib/servactory/utils.rb +36 -1
- data/lib/servactory/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b7493cf468717aef41460f0658f7bc3b7de1a280be66dd7408eeb14a861817e
|
4
|
+
data.tar.gz: e4d05dbc3d4a37ddd3c1bb6bb3c536dde9f11d03525cb53d7f3af74f4ec56030
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c04b93e6f0a4ad53a8ba64e3ec86373bc5ae0bd151a169baddd4c3df195666c000353772cfe600a92ca1e82ad0403cc9f3abad359b6602375aa5eea59c3351e9
|
7
|
+
data.tar.gz: 74281796feed47017b68ba38b387fb1e20076c85131966ec967d2c0b88a76ad0996b802ea9574c02ec2bbba2a37c3cb1aca62bada4ae25ad1f66d692ecf49726
|
@@ -25,7 +25,8 @@ module Servactory
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def getter_with(name:, &block) # rubocop:disable Lint/UnusedMethodArgument
|
28
|
-
|
28
|
+
input_name = name.to_s.chomp("?").to_sym
|
29
|
+
input = @collection_of_inputs.find_by(name: input_name)
|
29
30
|
|
30
31
|
return yield if input.nil?
|
31
32
|
|
@@ -35,7 +36,11 @@ module Servactory
|
|
35
36
|
input_prepare = input.prepare.fetch(:in, nil)
|
36
37
|
input_value = input_prepare.call(value: input_value) if input_prepare.present?
|
37
38
|
|
38
|
-
|
39
|
+
if name.to_s.end_with?("?")
|
40
|
+
Servactory::Utils.query_attribute(input_value)
|
41
|
+
else
|
42
|
+
input_value
|
43
|
+
end
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
@@ -42,11 +42,18 @@ module Servactory
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def getter_with(name:, &block) # rubocop:disable Lint/UnusedMethodArgument
|
45
|
-
|
45
|
+
internal_name = name.to_s.chomp("?").to_sym
|
46
|
+
internal = @collection_of_internals.find_by(name: internal_name)
|
46
47
|
|
47
48
|
return yield if internal.nil?
|
48
49
|
|
49
|
-
@context.send(:fetch_internal, internal.name)
|
50
|
+
internal_value = @context.send(:fetch_internal, internal.name)
|
51
|
+
|
52
|
+
if name.to_s.end_with?("?")
|
53
|
+
Servactory::Utils.query_attribute(internal_value)
|
54
|
+
else
|
55
|
+
internal_value
|
56
|
+
end
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
@@ -42,11 +42,18 @@ module Servactory
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def getter_with(name:, &block) # rubocop:disable Lint/UnusedMethodArgument
|
45
|
-
|
45
|
+
output_name = name.to_s.chomp("?").to_sym
|
46
|
+
output = @collection_of_outputs.find_by(name: output_name)
|
46
47
|
|
47
48
|
return yield if output.nil?
|
48
49
|
|
49
|
-
@context.send(:fetch_output, output.name)
|
50
|
+
output_value = @context.send(:fetch_output, output.name)
|
51
|
+
|
52
|
+
if name.to_s.end_with?("?")
|
53
|
+
Servactory::Utils.query_attribute(output_value)
|
54
|
+
else
|
55
|
+
output_value
|
56
|
+
end
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
data/lib/servactory/result.rb
CHANGED
@@ -26,6 +26,7 @@ module Servactory
|
|
26
26
|
define_singleton_method(:failure?) { false }
|
27
27
|
|
28
28
|
@context.send(:service_storage).fetch(:outputs).each_pair do |key, value|
|
29
|
+
define_singleton_method(:"#{key}?") { Servactory::Utils.query_attribute(value) }
|
29
30
|
define_singleton_method(key) { value }
|
30
31
|
end
|
31
32
|
|
data/lib/servactory/utils.rb
CHANGED
@@ -4,16 +4,51 @@ module Servactory
|
|
4
4
|
module Utils
|
5
5
|
module_function
|
6
6
|
|
7
|
+
FALSE_VALUES = [
|
8
|
+
false,
|
9
|
+
nil, "",
|
10
|
+
"0", :"0", 0,
|
11
|
+
"f", :f,
|
12
|
+
"F", :F,
|
13
|
+
"false", :false, # rubocop:disable Lint/BooleanSymbol
|
14
|
+
"FALSE", :FALSE,
|
15
|
+
"off", :off,
|
16
|
+
"OFF", :OFF
|
17
|
+
].to_set.freeze
|
18
|
+
|
19
|
+
private_constant :FALSE_VALUES
|
20
|
+
|
7
21
|
# @param value [#to_s]
|
8
22
|
# @return [Boolean]
|
9
23
|
def true?(value)
|
10
|
-
|
24
|
+
!FALSE_VALUES.include?(value)
|
11
25
|
end
|
12
26
|
|
27
|
+
# @param value [#to_s]
|
28
|
+
# @return [Boolean]
|
13
29
|
def value_present?(value)
|
14
30
|
!value.nil? && (
|
15
31
|
value.respond_to?(:empty?) ? !value.empty? : true
|
16
32
|
)
|
17
33
|
end
|
34
|
+
|
35
|
+
# NOTE: Based on `query_cast_attribute` from ActiveRecord:
|
36
|
+
# https://github.com/rails/rails/blob/main/activerecord/lib/active_record/attribute_methods/query.rb
|
37
|
+
# @param value [#to_s]
|
38
|
+
# @return [Boolean]
|
39
|
+
def query_attribute(value) # rubocop:disable Metrics/MethodLength
|
40
|
+
case value
|
41
|
+
when true then true
|
42
|
+
when false, nil then false
|
43
|
+
else
|
44
|
+
if value.is_a?(Numeric) || (value.respond_to?(:match?) && !value.match?(/[^0-9]/))
|
45
|
+
!value.to_i.zero?
|
46
|
+
else
|
47
|
+
return false if FALSE_VALUES.include?(value)
|
48
|
+
|
49
|
+
!value.blank?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
18
53
|
end
|
19
54
|
end
|
data/lib/servactory/version.rb
CHANGED