ree_lib 1.0.0 → 1.0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b78b5d2573b0674dc4f2eae170e408ac3f2fe18bb735be4fdd5ba8bbb7950e6
|
4
|
+
data.tar.gz: 253c3e28a517d3d14dd3110cd774f5ae4086c1ba5e0d19110de9f7d8c6f05bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c083f3c6b152024b97e90af5294db3aa0703fa7b0c50747de9596cbe7b4da7c87d8e190e68c25acc4a039ad00a7be549b2d0ad61bb05efd7d94cd6528d3dfecd
|
7
|
+
data.tar.gz: a337f004cc876ca1b1be5a0fb2187767d568a45a05b2e8926e4490acb34e7354b72f3c9ff453f9980043e38a56a09f8796da4ea0f92d938c762908370ba9438a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ree_lib (1.0.
|
4
|
+
ree_lib (1.0.1)
|
5
5
|
binding_of_caller (~> 1.0.0)
|
6
6
|
i18n (~> 1.12.0)
|
7
7
|
loofah (~> 2.18.0)
|
@@ -36,11 +36,11 @@ GEM
|
|
36
36
|
crass (~> 1.0.2)
|
37
37
|
nokogiri (>= 1.5.9)
|
38
38
|
msgpack (1.5.3)
|
39
|
-
nokogiri (1.13.
|
39
|
+
nokogiri (1.13.8-x86_64-darwin)
|
40
40
|
racc (~> 1.4)
|
41
|
-
nokogiri (1.13.
|
41
|
+
nokogiri (1.13.8-x86_64-linux)
|
42
42
|
racc (~> 1.4)
|
43
|
-
oj (3.13.
|
43
|
+
oj (3.13.19)
|
44
44
|
pg (1.4.1)
|
45
45
|
public_suffix (4.0.7)
|
46
46
|
racc (1.6.0)
|
@@ -22,80 +22,83 @@ module ReeEnum
|
|
22
22
|
Ree.container.compile(dsl.package, name)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def type_for_mapper
|
26
|
+
@type_for_mapper ||= begin
|
27
|
+
klass = Class.new(ReeMapper::AbstractType) do
|
28
|
+
def initialize(enum)
|
29
|
+
@enum = enum
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
contract(
|
33
|
+
ReeEnum::Value,
|
34
|
+
Kwargs[
|
35
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
36
|
+
] => String
|
37
|
+
)
|
38
|
+
def serialize(value, role: nil)
|
39
|
+
value.to_s
|
40
|
+
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
contract(
|
43
|
+
Any,
|
44
|
+
Kwargs[
|
45
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
46
|
+
] => ReeEnum::Value
|
47
|
+
).throws(ReeMapper::CoercionError)
|
48
|
+
def cast(value, role: nil)
|
49
|
+
if value.is_a?(String)
|
50
|
+
enum_val = @enum.values.all.detect { |v| v.to_s == value }
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if value.is_a?(String)
|
53
|
-
enum_val = @enum.values.all.detect { |v| v.to_s == value }
|
54
|
-
|
55
|
-
if !enum_val
|
56
|
-
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
57
|
-
end
|
52
|
+
if !enum_val
|
53
|
+
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
54
|
+
end
|
55
|
+
|
56
|
+
enum_val
|
57
|
+
elsif value.is_a?(Integer)
|
58
|
+
enum_val = @enum.values.all.detect { |v| v.to_i == value }
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
if !enum_val
|
61
|
+
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
+
enum_val
|
65
|
+
else
|
64
66
|
raise ReeMapper::CoercionError, "should be one of #{@enum.values.all.map(&:to_s).inspect}"
|
65
67
|
end
|
68
|
+
end
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
contract(
|
71
|
+
ReeEnum::Value,
|
72
|
+
Kwargs[
|
73
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
74
|
+
] => Integer
|
75
|
+
)
|
76
|
+
def db_dump(value, role: nil)
|
77
|
+
value.to_i
|
70
78
|
end
|
71
|
-
end
|
72
79
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
contract(
|
81
|
+
Integer,
|
82
|
+
Kwargs[
|
83
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
84
|
+
] => ReeEnum::Value
|
85
|
+
).throws(ReeMapper::TypeError)
|
86
|
+
def db_load(value, role: nil)
|
87
|
+
cast(value, role: role)
|
88
|
+
end
|
81
89
|
end
|
82
90
|
|
83
|
-
|
84
|
-
Integer,
|
85
|
-
Kwargs[
|
86
|
-
role: Nilor[Symbol, ArrayOf[Symbol]]
|
87
|
-
] => ReeEnum::Value
|
88
|
-
).throws(ReeMapper::TypeError)
|
89
|
-
def db_load(value, role: nil)
|
90
|
-
cast(value, role: role)
|
91
|
-
end
|
91
|
+
klass.new(self)
|
92
92
|
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def register_as_mapper_type
|
96
|
+
mapper_factory = ReeMapper.get_mapper_factory(
|
97
|
+
Object.const_get(self.name.split('::').first)
|
98
|
+
)
|
93
99
|
|
94
|
-
mapper_factory.
|
95
|
-
self.enum_name,
|
96
|
-
ReeMapper::Mapper.build(
|
97
|
-
mapper_factory.strategies, klass.new(self)
|
98
|
-
)
|
100
|
+
mapper_factory.register_type(
|
101
|
+
self.enum_name, type_for_mapper
|
99
102
|
)
|
100
103
|
end
|
101
104
|
end
|
@@ -11,6 +11,14 @@ class ReeMapper::MapperFactory
|
|
11
11
|
string: ReeMapper::StringKeyHashOutput
|
12
12
|
}.freeze
|
13
13
|
|
14
|
+
contract(Symbol, Any => Class).throws(ArgumentError)
|
15
|
+
def self.register_type(name, object_type)
|
16
|
+
register(
|
17
|
+
name,
|
18
|
+
ReeMapper::Mapper.build(strategies, object_type)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
14
22
|
contract(Symbol, Any => Class).throws(ArgumentError)
|
15
23
|
def self.register(name, type)
|
16
24
|
raise ArgumentError, "name of mapper type should not include `?`" if name.to_s.end_with?('?')
|
data/lib/ree_lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ree_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ree
|