anyway_config 2.2.0 → 2.2.1

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: 87d32ae676d03c8a9fd3a0b22efe3321d76661f226438f52fd313f4d73b1876d
4
- data.tar.gz: 82f2ab5d663b03622f650fbcf8e37216a71d81fdfd9270d54f539fd6253ada9d
3
+ metadata.gz: a0f3278ebf47801b6fdd2836c3f9f63d9a8fc1fe324f04e30f74d2dca179f471
4
+ data.tar.gz: 8be597f8b2c6065f0ea96e5c58ec54d6ef3532f00d7a8639a963e99b2bba65c9
5
5
  SHA512:
6
- metadata.gz: 9f7952609c7964cc9866fe530a9a519cf981f0551f9979c72f38b2acd31e59edd98d6234f095da99419acd462bcfc7c6b7d5016c41ded3bb0206d7f1e03550b3
7
- data.tar.gz: 1559b8e140b7df15164134233fd6c65e11d9283f94c9495a0d92f6afdcc69271cec68a7bc6f5052b8ec06dab35e33f1cadd32f4f044701156bfcc0ca4676ba41
6
+ metadata.gz: 8174b86b24e86de09a55e473bcec74fc37aeca1c38bb2a75e83e71dbeebf512b68fdb93ae23d247cb6a8ae6c5d1e2fbb86d659bf611f83ad219fccabad1ba7b6
7
+ data.tar.gz: dcf73ae92079a78b8c518cc3059a85848dd4934633269d016b402114279a0303108ab7962477ea2172ff15a1abc9c6401cea9106a83ba9b4c46a02220264eb23
data/CHANGELOG.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  ## master
4
4
 
5
- ## 2.2.0
5
+ ## 2.2.1 (2020-09-28)
6
+
7
+ - Minor fixes to the prev release.
8
+
9
+ ## 2.2.0 ⛓ (2020-09-28)
6
10
 
7
11
  - Add RBS signatures and generator. ([@palkan][])
8
12
 
data/README.md CHANGED
@@ -602,6 +602,13 @@ Type coercion is especially useful to deal with array values:
602
602
  coerce_types list: {type: :string, array: true}
603
603
  ```
604
604
 
605
+ You can use `type: nil` in case you don't want to coerce values, just convert a value into an array:
606
+
607
+ ```ruby
608
+ # From AnyCable config (sentinels could be represented via strings or hashes)
609
+ coerce_types redis_sentinels: {type: nil, array: true}
610
+ ```
611
+
605
612
  It's also could be useful to explicitly define non-array types (to avoid confusion):
606
613
 
607
614
  ```ruby
@@ -22,8 +22,10 @@ module Anyway
22
22
  end
23
23
 
24
24
  def deserialize(raw, type_id, array: false)
25
+ return if raw.nil?
26
+
25
27
  caster =
26
- if type_id.is_a?(Symbol)
28
+ if type_id.is_a?(Symbol) || type_id.nil?
27
29
  registry.fetch(type_id) { raise ArgumentError, "Unknown type: #{type_id}" }
28
30
  else
29
31
  raise ArgumentError, "Type must implement #call(val): #{type_id}" unless type_id.respond_to?(:call)
@@ -31,7 +33,7 @@ module Anyway
31
33
  end
32
34
 
33
35
  if array
34
- raw_arr = raw.is_a?(Array) ? raw : raw.split(/\s*,\s*/)
36
+ raw_arr = raw.is_a?(String) ? raw.split(/\s*,\s*/) : Array(raw)
35
37
  raw_arr.map { |_1| caster.call(_1) }
36
38
  else
37
39
  caster.call(raw)
@@ -50,6 +52,7 @@ module Anyway
50
52
  end
51
53
 
52
54
  TypeRegistry.default.tap do |obj|
55
+ obj.accept(nil, &:itself)
53
56
  obj.accept(:string, &:to_s)
54
57
  obj.accept(:integer, &:to_i)
55
58
  obj.accept(:float, &:to_f)
@@ -57,23 +60,33 @@ module Anyway
57
60
  obj.accept(:date) do |_1|
58
61
  require "date" unless defined?(::Date)
59
62
 
60
- Date.parse(_1)
63
+ next _1 if _1.is_a?(::Date)
64
+
65
+ next _1.to_date if _1.respond_to?(:to_date)
66
+
67
+ ::Date.parse(_1)
61
68
  end
62
69
 
63
70
  obj.accept(:datetime) do |_1|
64
71
  require "date" unless defined?(::Date)
65
72
 
66
- DateTime.parse(_1)
73
+ next _1 if _1.is_a?(::DateTime)
74
+
75
+ next _1.to_datetime if _1.respond_to?(:to_datetime)
76
+
77
+ ::DateTime.parse(_1)
67
78
  end
68
79
 
69
80
  obj.accept(:uri) do |_1|
70
81
  require "uri" unless defined?(::URI)
71
82
 
72
- URI.parse(_1)
83
+ next _1 if _1.is_a?(::URI)
84
+
85
+ ::URI.parse(_1)
73
86
  end
74
87
 
75
88
  obj.accept(:boolean) do |_1|
76
- _1.match?(/\A(true|t|yes|y|1)\z/i)
89
+ _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
77
90
  end
78
91
  end
79
92
 
@@ -22,8 +22,10 @@ module Anyway
22
22
  end
23
23
 
24
24
  def deserialize(raw, type_id, array: false)
25
+ return if raw.nil?
26
+
25
27
  caster =
26
- if type_id.is_a?(Symbol)
28
+ if type_id.is_a?(Symbol) || type_id.nil?
27
29
  registry.fetch(type_id) { raise ArgumentError, "Unknown type: #{type_id}" }
28
30
  else
29
31
  raise ArgumentError, "Type must implement #call(val): #{type_id}" unless type_id.respond_to?(:call)
@@ -31,7 +33,7 @@ module Anyway
31
33
  end
32
34
 
33
35
  if array
34
- raw_arr = raw.is_a?(Array) ? raw : raw.split(/\s*,\s*/)
36
+ raw_arr = raw.is_a?(String) ? raw.split(/\s*,\s*/) : Array(raw)
35
37
  raw_arr.map { caster.call(_1) }
36
38
  else
37
39
  caster.call(raw)
@@ -50,6 +52,7 @@ module Anyway
50
52
  end
51
53
 
52
54
  TypeRegistry.default.tap do |obj|
55
+ obj.accept(nil, &:itself)
53
56
  obj.accept(:string, &:to_s)
54
57
  obj.accept(:integer, &:to_i)
55
58
  obj.accept(:float, &:to_f)
@@ -57,23 +60,33 @@ module Anyway
57
60
  obj.accept(:date) do
58
61
  require "date" unless defined?(::Date)
59
62
 
60
- Date.parse(_1)
63
+ next _1 if _1.is_a?(::Date)
64
+
65
+ next _1.to_date if _1.respond_to?(:to_date)
66
+
67
+ ::Date.parse(_1)
61
68
  end
62
69
 
63
70
  obj.accept(:datetime) do
64
71
  require "date" unless defined?(::Date)
65
72
 
66
- DateTime.parse(_1)
73
+ next _1 if _1.is_a?(::DateTime)
74
+
75
+ next _1.to_datetime if _1.respond_to?(:to_datetime)
76
+
77
+ ::DateTime.parse(_1)
67
78
  end
68
79
 
69
80
  obj.accept(:uri) do
70
81
  require "uri" unless defined?(::URI)
71
82
 
72
- URI.parse(_1)
83
+ next _1 if _1.is_a?(::URI)
84
+
85
+ ::URI.parse(_1)
73
86
  end
74
87
 
75
88
  obj.accept(:boolean) do
76
- _1.match?(/\A(true|t|yes|y|1)\z/i)
89
+ _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
77
90
  end
78
91
  end
79
92
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.2.0"
4
+ VERSION = "2.2.1"
5
5
  end
@@ -51,6 +51,12 @@ module Anyway
51
51
  end
52
52
  end
53
53
 
54
+ type valueType = Symbol | nil
55
+ type arrayType = {array: bool, type: valueType}
56
+ type hashType = Hash[Symbol, valueType | arrayType | hashType]
57
+
58
+ type mappingType = valueType | arrayType | hashType
59
+
54
60
  class Config
55
61
  extend RBSGenerator
56
62
  extend DynamicConfig::ClassMethods
@@ -66,7 +72,7 @@ module Anyway
66
72
  def self.on_load: (*Symbol callbacks) ?{ () -> void } -> void
67
73
  def self.config_name: (?(Symbol | String) val) -> String?
68
74
  def self.env_prefix: (?(Symbol | String) val) -> String
69
- def self.coerce_types: (untyped mapping) -> untyped
75
+ def self.coerce_types: (**mappingType) -> void
70
76
  def self.coercion_mapping: -> Hash[untyped, untyped]?
71
77
  def self.disable_auto_cast!: -> void
72
78
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyway_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.13.1
19
+ version: 0.11.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.13.1
26
+ version: 0.11.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ammeter
29
29
  requirement: !ruby/object:Gem::Requirement