morpher 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/morpher.rb +2 -0
- data/lib/morpher/record.rb +9 -0
- data/lib/morpher/transform.rb +48 -3
- metadata +3 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f68237f24a5ee7b113c26e9f21c4a7765568b18ba0262dc86a7db3f437205ac
|
4
|
+
data.tar.gz: e861789e9b539d77aecbf81b12add653f5ac4f679c55ad9bed37ca4ccb50bc51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3adaf243ef357354e7f2b76e80ae4cfdf65f7913d13a0aa6f125656466da971758f03a71632ed5c944be289195d776b0addbc636277beb75a7312b7bfae45b9
|
7
|
+
data.tar.gz: aa3411aaf134378b122051c8365d54f08ad5db213fec95d7ff886c10e04ef5656fa2926c298938139b7fe8537f488eaeafafe5ec998e60e95c0cd0aad14a2e31
|
data/lib/morpher.rb
CHANGED
data/lib/morpher/record.rb
CHANGED
@@ -3,8 +3,17 @@
|
|
3
3
|
module Morpher
|
4
4
|
# Generator for struct a-like wrappers
|
5
5
|
class Record < Module
|
6
|
+
DEFAULTS = {
|
7
|
+
required: EMPTY_HASH,
|
8
|
+
optional: EMPTY_HASH
|
9
|
+
}.freeze
|
10
|
+
|
6
11
|
include Anima.new(:required, :optional)
|
7
12
|
|
13
|
+
def self.new(**attributes)
|
14
|
+
super(DEFAULTS.merge(attributes))
|
15
|
+
end
|
16
|
+
|
8
17
|
# rubocop:disable Metrics/AbcSize
|
9
18
|
# rubocop:disable Metrics/MethodLength
|
10
19
|
def included(host)
|
data/lib/morpher/transform.rb
CHANGED
@@ -20,6 +20,29 @@ module Morpher
|
|
20
20
|
# @return [Either<Error, Object>]
|
21
21
|
abstract_method :call
|
22
22
|
|
23
|
+
# Build sequence
|
24
|
+
#
|
25
|
+
# @param [Transform] transform
|
26
|
+
#
|
27
|
+
# @return [Transform]
|
28
|
+
def seq(transform)
|
29
|
+
Sequence.new([self, transform])
|
30
|
+
end
|
31
|
+
|
32
|
+
# Build array transform
|
33
|
+
#
|
34
|
+
# @return [Transform]
|
35
|
+
def array
|
36
|
+
Array.new(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Build maybe transform
|
40
|
+
#
|
41
|
+
# @return [Transform]
|
42
|
+
def maybe
|
43
|
+
Maybe.new(self)
|
44
|
+
end
|
45
|
+
|
23
46
|
# Deep error data structure
|
24
47
|
class Error
|
25
48
|
include Anima.new(
|
@@ -59,13 +82,13 @@ module Morpher
|
|
59
82
|
|
60
83
|
# Wrapper adding a name to a transformation
|
61
84
|
class Named < self
|
62
|
-
include Concord.new(:name, :
|
85
|
+
include Concord.new(:name, :transform)
|
63
86
|
|
64
87
|
# Apply transformation to input
|
65
88
|
#
|
66
89
|
# @return [Either<Error, Object>]
|
67
90
|
def call(input)
|
68
|
-
|
91
|
+
transform.call(input).lmap(&method(:wrap_error))
|
69
92
|
end
|
70
93
|
|
71
94
|
# Named slug
|
@@ -419,6 +442,15 @@ module Morpher
|
|
419
442
|
class Sequence < self
|
420
443
|
include Concord.new(:steps)
|
421
444
|
|
445
|
+
# Build sequence
|
446
|
+
#
|
447
|
+
# @param [Transform] transform
|
448
|
+
#
|
449
|
+
# @return [Transform]
|
450
|
+
def seq(transform)
|
451
|
+
self.class.new(steps + [transform])
|
452
|
+
end
|
453
|
+
|
422
454
|
# Apply transformation to input
|
423
455
|
#
|
424
456
|
# @param [Object]
|
@@ -437,7 +469,7 @@ module Morpher
|
|
437
469
|
end
|
438
470
|
end # Sequence
|
439
471
|
|
440
|
-
# Generic exception
|
472
|
+
# Generic exception transform
|
441
473
|
class Exception < self
|
442
474
|
include Concord.new(:error_class, :block)
|
443
475
|
|
@@ -467,6 +499,19 @@ module Morpher
|
|
467
499
|
end
|
468
500
|
end # Success
|
469
501
|
|
502
|
+
# Transform accepting nil values
|
503
|
+
class Maybe < Transform
|
504
|
+
include Concord.new(:transform)
|
505
|
+
|
506
|
+
def call(input)
|
507
|
+
if input.nil?
|
508
|
+
success(nil)
|
509
|
+
else
|
510
|
+
transform.call(input).lmap(&method(:wrap_error))
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end # Maybe
|
514
|
+
|
470
515
|
BOOLEAN = Transform::Boolean.new
|
471
516
|
FLOAT = Transform::Primitive.new(Float)
|
472
517
|
INTEGER = Transform::Primitive.new(Integer)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.3.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: ast
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.2'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.2'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: concord
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +80,6 @@ dependencies:
|
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: 0.0.9
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: ice_nine
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.11.0
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.11.0
|
111
83
|
- !ruby/object:Gem::Dependency
|
112
84
|
name: mprelude
|
113
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -251,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
223
|
- !ruby/object:Gem::Version
|
252
224
|
version: '0'
|
253
225
|
requirements: []
|
254
|
-
rubygems_version: 3.
|
226
|
+
rubygems_version: 3.2.18
|
255
227
|
signing_key:
|
256
228
|
specification_version: 4
|
257
229
|
summary: Domain Transformation Algebra
|