datacaster 3.2.2 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datacaster/switch_node.rb +15 -7
- data/lib/datacaster/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2b45e5271b85a571b86bd83ff91494d68486b677a2f0cc0f03daeeb5e8d5307
|
4
|
+
data.tar.gz: 7dafa54ec77eee489282217026a845059725a164e381525be695874bbb2cecc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37337520c11d06b98d30e5afcb890b2a8b1bfdbc06f05d070fb8d3c3dc52c4adc9263a9f92a29c0cf92051f5b58c57833f9d1330a8f7cb7fe39a46c2fad694f9
|
7
|
+
data.tar.gz: 4792f1c3000d5df28c865e5c8c365a87356e8241009b9a7cbe5e55544422c964749ba43e8d6004aba05585a18e1795967dc6c3a22f2e06a03ef87eca0dd4fced
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module Datacaster
|
2
2
|
class SwitchNode < Base
|
3
|
-
def initialize(base = nil, on_casters
|
3
|
+
def initialize(base = nil, on_casters: [], else_caster: nil, pick_key: nil)
|
4
4
|
@base = base
|
5
|
+
@pick_key = pick_key
|
5
6
|
|
6
7
|
if Datacaster::Utils.pickable?(@base)
|
7
|
-
@
|
8
|
-
|
8
|
+
unless @pick_key.nil?
|
9
|
+
raise RuntimeError, "pick_key expected to be nil because #{@base.inspect} is pickable"
|
10
|
+
end
|
11
|
+
@pick_key = base
|
12
|
+
@base = Datacaster::Predefined.pick(base)
|
9
13
|
end
|
10
14
|
|
11
15
|
if !@base.nil? && !Datacaster.instance?(@base)
|
@@ -34,12 +38,12 @@ module Datacaster
|
|
34
38
|
|
35
39
|
clause = DefinitionDSL.expand(clause)
|
36
40
|
|
37
|
-
self.class.new(@base, @ons + [[caster, clause]], @else)
|
41
|
+
self.class.new(@base, on_casters: @ons + [[caster, clause]], else_caster: @else, pick_key: @pick_key)
|
38
42
|
end
|
39
43
|
|
40
44
|
def else(else_caster)
|
41
45
|
raise ArgumentError, "Datacaster: double else clause is not permitted", caller if @else
|
42
|
-
self.class.new(@base, @ons, else_caster)
|
46
|
+
self.class.new(@base, on_casters: @ons, else_caster: else_caster, pick_key: @pick_key)
|
43
47
|
end
|
44
48
|
|
45
49
|
def cast(object, runtime:)
|
@@ -59,7 +63,11 @@ module Datacaster
|
|
59
63
|
result = check.with_runtime(runtime).(switch_result)
|
60
64
|
next unless result.valid?
|
61
65
|
|
62
|
-
|
66
|
+
if @pick_key.nil?
|
67
|
+
return clause.with_runtime(runtime).(object)
|
68
|
+
else
|
69
|
+
return runtime.checked_key!(@pick_key) { clause.with_runtime(runtime).(object) }
|
70
|
+
end
|
63
71
|
end
|
64
72
|
|
65
73
|
# all 'on'-s have failed
|
@@ -71,7 +79,7 @@ module Datacaster
|
|
71
79
|
end
|
72
80
|
|
73
81
|
def inspect
|
74
|
-
"#<Datacaster::SwitchNode base: #{@base.inspect} on: #{@ons.inspect} else: #{@else.inspect}>"
|
82
|
+
"#<Datacaster::SwitchNode base: #{@base.inspect} on: #{@ons.inspect} else: #{@else.inspect} pick_key: #{@pick_key.inspect}>"
|
75
83
|
end
|
76
84
|
end
|
77
85
|
end
|
data/lib/datacaster/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Zolotarev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
- - "<"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '3'
|
109
|
-
description:
|
109
|
+
description:
|
110
110
|
email:
|
111
111
|
- eugzol@gmail.com
|
112
112
|
executables: []
|
@@ -178,7 +178,7 @@ licenses:
|
|
178
178
|
- MIT
|
179
179
|
metadata:
|
180
180
|
source_code_uri: https://github.com/EugZol/datacaster
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
197
|
-
signing_key:
|
196
|
+
rubygems_version: 3.1.6
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Run-time type checker and transformer for Ruby
|
200
200
|
test_files: []
|