servactory 1.8.3 → 1.8.5

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: 0b5fa4f5c8c0a4ee8dfff54269c90deb49615e0395790a776b3c0b7dc7cced9e
4
- data.tar.gz: 9cbbb49123e91308390b90b9e0ba3d49a7921ea9340bb4ac6383403420b97c3f
3
+ metadata.gz: 1b7493cf468717aef41460f0658f7bc3b7de1a280be66dd7408eeb14a861817e
4
+ data.tar.gz: e4d05dbc3d4a37ddd3c1bb6bb3c536dde9f11d03525cb53d7f3af74f4ec56030
5
5
  SHA512:
6
- metadata.gz: e16ac59db1d6402d2c44fca9539eadf336c31ad8c29381c2482db52573f0e0864a1bfd9f920daab6f6e5668a886cf4615cf7803fc76d864972f49f21cb7333b9
7
- data.tar.gz: b9321f6a95199ba298e644ad42cb8c4b54c3aebb16fe1472367428c45263c7845b7689c2031512a96425dcefaa80885ef2de65523b9557d4fe3723538bedfbc8
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
- input = @collection_of_inputs.find_by(name: name)
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
- input_value
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
- internal = @collection_of_internals.find_by(name: name)
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
- output = @collection_of_outputs.find_by(name: name)
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
@@ -84,7 +84,7 @@ module Servactory
84
84
  end
85
85
 
86
86
  def fetch_internal(key)
87
- service_storage.fetch(:internals).fetch(key)
87
+ service_storage.fetch(:internals).fetch(key, nil)
88
88
  end
89
89
 
90
90
  def assign_output(key, value)
@@ -92,7 +92,7 @@ module Servactory
92
92
  end
93
93
 
94
94
  def fetch_output(key)
95
- service_storage.fetch(:outputs).fetch(key)
95
+ service_storage.fetch(:outputs).fetch(key, nil)
96
96
  end
97
97
  end
98
98
  end
@@ -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
 
@@ -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
- value.to_s.casecmp("true").to_i.zero?
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
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 8
7
- PATCH = 3
7
+ PATCH = 5
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.8.3
4
+ version: 1.8.5
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-28 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport