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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ca0fa5827beb874848039178b4711da493272bc8d1005ba5f0d7d3a566aa099
4
- data.tar.gz: 62e0eb9d9a955aaf04848f7612ac7f91a88cd583e5ead545d25df9ec99a02e06
3
+ metadata.gz: 1b7493cf468717aef41460f0658f7bc3b7de1a280be66dd7408eeb14a861817e
4
+ data.tar.gz: e4d05dbc3d4a37ddd3c1bb6bb3c536dde9f11d03525cb53d7f3af74f4ec56030
5
5
  SHA512:
6
- metadata.gz: a0720019832d9e0e5b8ca4ed63641ab2f21457b85dbe645bdbe9d1c771b13e261b60318368ec1f3dc98a1a0108761e67b9225c3da678bb9e4f29de5df47dd407
7
- data.tar.gz: 8b4471a08a037994f8b8e79aac11fb5d0bdaec365ea48a1843323a09518d5a679586656f11ef6c8f1805e18f1236e76ee00f2fd4646f4084e28b6a6d6939b90f
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
@@ -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 = 4
7
+ PATCH = 5
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.8.4
4
+ version: 1.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov