morpher 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/morpher/record.rb +13 -6
- data/lib/morpher/transform.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc9380b32ac09b2e3765666a2c56baeb3aef272d22be1f7043f1977c9da1d815
|
4
|
+
data.tar.gz: 0736e2646b93e59dc8fb2bf992bdf7729431260a08f3b158dd1eaf1324a657f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 496748be0cfeae869808cb58aead93df98b270020b93310bba695ce03bea0cbc14b7451a881ce3b3e9280acbbf2155caaba7bfba827896bd79dd1119d9fa7fc0
|
7
|
+
data.tar.gz: 0fc7f421fb376af18c2f1ea41eebf2b44350236e453a38878b1f015cb7cb15794d9e897de66c27c00143e1ce44b9271cc3f69be1ae79cb76f61f68a887e1c305
|
data/lib/morpher/record.rb
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
module Morpher
|
4
4
|
# Generator for struct a-like wrappers
|
5
5
|
class Record < Module
|
6
|
-
include
|
6
|
+
include Anima.new(:required, :optional)
|
7
7
|
|
8
|
+
# rubocop:disable Metrics/AbcSize
|
8
9
|
# rubocop:disable Metrics/MethodLength
|
9
10
|
def included(host)
|
10
|
-
|
11
|
-
|
11
|
+
optional = optional()
|
12
|
+
optional_transform = transform(optional)
|
13
|
+
required = required()
|
14
|
+
required_transform = transform(required)
|
12
15
|
|
13
16
|
host.class_eval do
|
14
|
-
include Adamantium::Flat, Anima.new(*
|
17
|
+
include Adamantium::Flat, Anima.new(*(required.keys + optional.keys))
|
15
18
|
|
16
19
|
const_set(
|
17
20
|
:TRANSFORM,
|
@@ -19,18 +22,22 @@ module Morpher
|
|
19
22
|
[
|
20
23
|
Transform::Primitive.new(Hash),
|
21
24
|
Transform::Hash::Symbolize.new,
|
22
|
-
Transform::Hash.new(
|
25
|
+
Transform::Hash.new(
|
26
|
+
required: required_transform,
|
27
|
+
optional: optional_transform
|
28
|
+
),
|
23
29
|
Transform::Success.new(public_method(:new))
|
24
30
|
]
|
25
31
|
)
|
26
32
|
)
|
27
33
|
end
|
28
34
|
end
|
35
|
+
# rubocop:enable Metrics/AbcSize
|
29
36
|
# rubocop:enable Metrics/MethodLength
|
30
37
|
|
31
38
|
private
|
32
39
|
|
33
|
-
def
|
40
|
+
def transform(attributes)
|
34
41
|
attributes.map do |name, transform|
|
35
42
|
Transform::Hash::Key.new(name, transform)
|
36
43
|
end
|
data/lib/morpher/transform.rb
CHANGED
@@ -350,11 +350,16 @@ module Morpher
|
|
350
350
|
transform_keys(required, input)
|
351
351
|
end
|
352
352
|
|
353
|
+
def defaults
|
354
|
+
optional.map(&:value).product([nil]).to_h
|
355
|
+
end
|
356
|
+
memoize :defaults
|
357
|
+
|
353
358
|
def transform_optional(input)
|
354
359
|
transform_keys(
|
355
360
|
optional.select { |key| input.key?(key.value) },
|
356
361
|
input
|
357
|
-
)
|
362
|
+
).fmap(&defaults.public_method(:merge))
|
358
363
|
end
|
359
364
|
|
360
365
|
# rubocop:disable Metrics/MethodLength
|
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
|
+
version: 0.4.0
|
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-03-
|
11
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|