ree_lib 1.0.72 → 1.0.74
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb +47 -0
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/dsl.rb +36 -83
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/enumerable.rb +24 -9
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/integer_value_enum_mapper.rb +42 -0
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb +37 -0
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb +6 -10
- data/lib/ree_lib/packages/ree_enum/package/ree_enum/values.rb +17 -5
- data/lib/ree_lib/packages/ree_enum/spec/ree_enum/dsl_spec.rb +61 -6
- data/lib/ree_lib/packages/ree_hash/package/ree_hash/functions/slice.rb +4 -3
- data/lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/set_locale.schema.json +1 -1
- data/lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/integer.rb +3 -3
- data/lib/ree_lib/packages/ree_object/package/ree_object/functions/to_hash.rb +3 -3
- data/lib/ree_lib/ree.setup.rb +0 -6
- data/lib/ree_lib/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db0e9f5e3c64d69ff4f6d4d4550ab6563bfe0bc9529333e21a1251503ad562b2
|
4
|
+
data.tar.gz: 02abcd3afb9f8155666b98abdb5a9f833b3affca8038c19b2322ab60be82e2db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f42d6c784721984a1729cd38412c946fd8924982d98eff0158a91c4ce9f5c80ef94561e0ea9801a0e1df3baa177ef6bf7ae0db5c177c1f2960f118a339d797
|
7
|
+
data.tar.gz: 25c0ae598cdbfee90f4ea991705fd73328188f64f33bd2895635bff5d98dc527c2a209b40fa286208d327f0f50cd6e03e36b192b3b8ea2076166d685b9c227ac
|
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.73)
|
5
5
|
binding_of_caller (~> 1.0.0)
|
6
6
|
i18n (~> 1.12.0)
|
7
7
|
loofah (~> 2.18.0)
|
@@ -51,7 +51,7 @@ GEM
|
|
51
51
|
rack (>= 1.3)
|
52
52
|
rainbow (3.1.1)
|
53
53
|
rake (13.0.6)
|
54
|
-
ree (1.0.
|
54
|
+
ree (1.0.31)
|
55
55
|
commander (~> 4.6.0)
|
56
56
|
rexml (3.2.5)
|
57
57
|
roda (3.58.0)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "value"
|
3
|
+
|
4
|
+
class ReeEnum::BaseEnumMapper < ReeMapper::AbstractType
|
5
|
+
def initialize(enum)
|
6
|
+
@enum = enum
|
7
|
+
end
|
8
|
+
|
9
|
+
contract(
|
10
|
+
ReeEnum::Value,
|
11
|
+
Kwargs[
|
12
|
+
name: String,
|
13
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
14
|
+
] => Or[Integer, String]
|
15
|
+
)
|
16
|
+
def db_dump(value, name:, role: nil)
|
17
|
+
value.mapped_value
|
18
|
+
end
|
19
|
+
|
20
|
+
contract(
|
21
|
+
Or[Integer, String],
|
22
|
+
Kwargs[
|
23
|
+
name: String,
|
24
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
25
|
+
] => ReeEnum::Value
|
26
|
+
).throws(ReeMapper::CoercionError)
|
27
|
+
def db_load(value, name:, role: nil)
|
28
|
+
enum_val = @enum.get_values.by_mapped_value(value)
|
29
|
+
|
30
|
+
if !enum_val
|
31
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
32
|
+
end
|
33
|
+
|
34
|
+
enum_val
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def enum_inspection
|
40
|
+
@enum_inspection ||= truncate(@enum.get_values.each.map(&:to_s).inspect)
|
41
|
+
end
|
42
|
+
|
43
|
+
def truncate(str, limit = 180)
|
44
|
+
return str if str.length <= limit
|
45
|
+
"#{str[0..limit]}..."
|
46
|
+
end
|
47
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
package_require 'ree_swagger/functions/register_type'
|
2
3
|
|
4
|
+
require_relative 'integer_value_enum_mapper'
|
5
|
+
require_relative 'string_value_enum_mapper'
|
6
|
+
|
3
7
|
module ReeEnum
|
4
8
|
module DSL
|
5
9
|
def self.included(base)
|
@@ -27,100 +31,32 @@ module ReeEnum
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def type_for_mapper
|
30
|
-
@type_for_mapper
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
role: Nilor[Symbol, ArrayOf[Symbol]]
|
41
|
-
] => String
|
42
|
-
)
|
43
|
-
def serialize(value, name:, role: nil)
|
44
|
-
value.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
contract(
|
48
|
-
Any,
|
49
|
-
Kwargs[
|
50
|
-
name: String,
|
51
|
-
role: Nilor[Symbol, ArrayOf[Symbol]]
|
52
|
-
] => ReeEnum::Value
|
53
|
-
).throws(ReeMapper::CoercionError)
|
54
|
-
def cast(value, name:, role: nil)
|
55
|
-
enum_value = if value.is_a?(String)
|
56
|
-
@enum.get_values.by_value(value)
|
57
|
-
elsif value.is_a?(ReeEnum::Value)
|
58
|
-
@enum.get_values.each.find { _1 == value }
|
59
|
-
end
|
60
|
-
|
61
|
-
if enum_value.nil?
|
62
|
-
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
63
|
-
end
|
64
|
-
|
65
|
-
enum_value
|
66
|
-
end
|
67
|
-
|
68
|
-
contract(
|
69
|
-
ReeEnum::Value,
|
70
|
-
Kwargs[
|
71
|
-
name: String,
|
72
|
-
role: Nilor[Symbol, ArrayOf[Symbol]]
|
73
|
-
] => Or[Integer, String]
|
74
|
-
)
|
75
|
-
def db_dump(value, name:, role: nil)
|
76
|
-
value.mapped_value
|
77
|
-
end
|
78
|
-
|
79
|
-
contract(
|
80
|
-
Or[Integer, String],
|
81
|
-
Kwargs[
|
82
|
-
name: String,
|
83
|
-
role: Nilor[Symbol, ArrayOf[Symbol]]
|
84
|
-
] => ReeEnum::Value
|
85
|
-
).throws(ReeMapper::CoercionError)
|
86
|
-
def db_load(value, name:, role: nil)
|
87
|
-
enum_val = @enum.get_values.by_mapped_value(value)
|
88
|
-
|
89
|
-
if !enum_val
|
90
|
-
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
91
|
-
end
|
92
|
-
|
93
|
-
enum_val
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def enum_inspection
|
99
|
-
@enum_inspect ||= truncate(@enum.get_values.each.map(&:to_s).inspect)
|
100
|
-
end
|
101
|
-
|
102
|
-
def truncate(str, limit = 180)
|
103
|
-
return str if str.length <= limit
|
104
|
-
"#{str[0..limit]}..."
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
klass.new(self)
|
34
|
+
return @type_for_mapper if defined? @type_for_mapper
|
35
|
+
|
36
|
+
value_type = get_values.value_type
|
37
|
+
|
38
|
+
klass = if value_type == String
|
39
|
+
StringValueEnumMapper
|
40
|
+
elsif value_type == Integer
|
41
|
+
IntegerValueEnumMapper
|
42
|
+
else
|
43
|
+
raise NotImplementedError, "value_type #{value_type} is not supported"
|
109
44
|
end
|
45
|
+
|
46
|
+
@type_for_mapper = klass.new(self)
|
110
47
|
end
|
111
48
|
|
112
49
|
def register_as_swagger_type
|
113
50
|
swagger_type_registrator = ReeSwagger::RegisterType.new
|
114
51
|
|
52
|
+
definition = swagger_definition
|
53
|
+
|
115
54
|
[:casters, :serializers].each do |kind|
|
116
55
|
swagger_type_registrator.call(
|
117
56
|
kind,
|
118
57
|
type_for_mapper.class,
|
119
58
|
->(*) {
|
120
|
-
|
121
|
-
type: 'string',
|
122
|
-
enum: get_values.each.map(&:to_s)
|
123
|
-
}
|
59
|
+
definition
|
124
60
|
}
|
125
61
|
)
|
126
62
|
end
|
@@ -137,6 +73,23 @@ module ReeEnum
|
|
137
73
|
self.get_enum_name, type_for_mapper
|
138
74
|
)
|
139
75
|
end
|
76
|
+
|
77
|
+
def swagger_definition
|
78
|
+
value_type = get_values.value_type
|
79
|
+
|
80
|
+
type = if value_type == String
|
81
|
+
"string"
|
82
|
+
elsif value_type == Integer
|
83
|
+
"integer"
|
84
|
+
else
|
85
|
+
raise NotImplementedError, "value_type #{value_type} is not supported"
|
86
|
+
end
|
87
|
+
|
88
|
+
{
|
89
|
+
type: type,
|
90
|
+
enum: get_values.each.map(&:value)
|
91
|
+
}
|
92
|
+
end
|
140
93
|
end
|
141
94
|
end
|
142
95
|
end
|
@@ -13,10 +13,16 @@ module ReeEnum::Enumerable
|
|
13
13
|
include ReeEnum::Contractable
|
14
14
|
|
15
15
|
RESTRICTED_METHODS = [
|
16
|
-
:setup_enum, :get_values, :get_enum_name,
|
17
|
-
:
|
16
|
+
:setup_enum, :get_values, :get_enum_name, :val,
|
17
|
+
:__ENCODING__, :__LINE__, :__FILE__, :BEGIN, :END,
|
18
|
+
:alias, :and, :begin, :break, :case, :class, :def, :defined?,
|
19
|
+
:do, :else, :elsif, :end, :ensure, :false, :for, :if, :in,
|
20
|
+
:module, :next, :nil, :not, :or, :redo, :rescue, :retry, :return,
|
21
|
+
:self, :super, :then, :true, :undef, :unless, :until, :when, :while, :yield
|
18
22
|
].freeze
|
19
23
|
|
24
|
+
ALLOWED_VALUE_TO_METHOD_REGEXP = /^[a-z_]\w*[?!]?$/
|
25
|
+
|
20
26
|
def setup_enum(enum_name)
|
21
27
|
@values ||= ReeEnum::Values.new(self, enum_name)
|
22
28
|
end
|
@@ -29,8 +35,13 @@ module ReeEnum::Enumerable
|
|
29
35
|
@values&.enum_name
|
30
36
|
end
|
31
37
|
|
32
|
-
def val(value, mapped_value =
|
33
|
-
value = value.to_s
|
38
|
+
def val(value, mapped_value = nil, method: nil)
|
39
|
+
value = value.to_s if value.is_a?(Symbol)
|
40
|
+
mapped_value ||= value
|
41
|
+
|
42
|
+
if method.nil? && value.is_a?(String) && value.match?(ALLOWED_VALUE_TO_METHOD_REGEXP)
|
43
|
+
method = value.to_sym
|
44
|
+
end
|
34
45
|
|
35
46
|
if RESTRICTED_METHODS.include?(method)
|
36
47
|
raise ArgumentError.new("#{method.inspect} is not allowed as enum method")
|
@@ -38,12 +49,16 @@ module ReeEnum::Enumerable
|
|
38
49
|
|
39
50
|
enum_value = @values.add(value, mapped_value, method)
|
40
51
|
|
41
|
-
|
42
|
-
|
43
|
-
|
52
|
+
if !method.nil?
|
53
|
+
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
54
|
+
def #{method}
|
55
|
+
get_values.by_value(#{value.inspect}.freeze)
|
56
|
+
end
|
44
57
|
|
45
|
-
|
46
|
-
|
58
|
+
def self.#{method}
|
59
|
+
get_values.by_value(#{value.inspect}.freeze)
|
60
|
+
end
|
61
|
+
RUBY
|
47
62
|
end
|
48
63
|
|
49
64
|
enum_value
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "base_enum_mapper"
|
3
|
+
|
4
|
+
class ReeEnum::IntegerValueEnumMapper < ReeEnum::BaseEnumMapper
|
5
|
+
contract(
|
6
|
+
ReeEnum::Value,
|
7
|
+
Kwargs[
|
8
|
+
name: String,
|
9
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
10
|
+
] => Integer
|
11
|
+
)
|
12
|
+
def serialize(value, name:, role: nil)
|
13
|
+
value.value
|
14
|
+
end
|
15
|
+
|
16
|
+
contract(
|
17
|
+
Any,
|
18
|
+
Kwargs[
|
19
|
+
name: String,
|
20
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
21
|
+
] => ReeEnum::Value
|
22
|
+
).throws(ReeMapper::CoercionError)
|
23
|
+
def cast(value, name:, role: nil)
|
24
|
+
enum_value = case value
|
25
|
+
when Integer
|
26
|
+
@enum.get_values.by_value(value)
|
27
|
+
when String
|
28
|
+
value = Integer(value, exception: false)
|
29
|
+
if !value.nil?
|
30
|
+
@enum.get_values.by_value(value)
|
31
|
+
end
|
32
|
+
when ReeEnum::Value
|
33
|
+
@enum.get_values.each.find { _1 == value }
|
34
|
+
end
|
35
|
+
|
36
|
+
if enum_value.nil?
|
37
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
38
|
+
end
|
39
|
+
|
40
|
+
enum_value
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "base_enum_mapper"
|
3
|
+
|
4
|
+
class ReeEnum::StringValueEnumMapper < ReeEnum::BaseEnumMapper
|
5
|
+
contract(
|
6
|
+
ReeEnum::Value,
|
7
|
+
Kwargs[
|
8
|
+
name: String,
|
9
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
10
|
+
] => String
|
11
|
+
)
|
12
|
+
def serialize(value, name:, role: nil)
|
13
|
+
value.value
|
14
|
+
end
|
15
|
+
|
16
|
+
contract(
|
17
|
+
Any,
|
18
|
+
Kwargs[
|
19
|
+
name: String,
|
20
|
+
role: Nilor[Symbol, ArrayOf[Symbol]]
|
21
|
+
] => ReeEnum::Value
|
22
|
+
).throws(ReeMapper::CoercionError)
|
23
|
+
def cast(value, name:, role: nil)
|
24
|
+
enum_value = case value
|
25
|
+
when String
|
26
|
+
@enum.get_values.by_value(value)
|
27
|
+
when ReeEnum::Value
|
28
|
+
@enum.get_values.each.find { _1 == value }
|
29
|
+
end
|
30
|
+
|
31
|
+
if enum_value.nil?
|
32
|
+
raise ReeMapper::CoercionError, "`#{name}` should be one of #{enum_inspection}"
|
33
|
+
end
|
34
|
+
|
35
|
+
enum_value
|
36
|
+
end
|
37
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
class ReeEnum::Value
|
4
4
|
attr_reader :enum_class, :enum_name, :value, :method, :mapped_value
|
5
5
|
|
6
|
-
contract(Class, Symbol, String, Or[Integer, String], Symbol => Any)
|
6
|
+
contract(Class, Symbol, Or[String, Integer], Or[Integer, String], Nilor[Symbol] => Any)
|
7
7
|
def initialize(enum_class, enum_name, value, mapped_value, method)
|
8
8
|
@enum_class = enum_class
|
9
9
|
@enum_name = enum_name
|
@@ -13,25 +13,21 @@ class ReeEnum::Value
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
value
|
16
|
+
value.to_s
|
17
17
|
end
|
18
18
|
|
19
19
|
def as_json(*args)
|
20
|
-
|
20
|
+
value
|
21
21
|
end
|
22
22
|
|
23
23
|
contract(Or[ReeEnum::Value, String, Symbol, Integer, Any] => Bool)
|
24
24
|
def ==(compare)
|
25
25
|
if compare.is_a?(self.class)
|
26
26
|
value == compare.value
|
27
|
-
elsif compare.is_a?(Symbol)
|
28
|
-
value == compare
|
29
|
-
elsif compare.is_a?(String)
|
30
|
-
value == compare || mapped_value == compare
|
31
|
-
elsif compare.is_a?(Integer)
|
32
|
-
mapped_value == compare
|
27
|
+
elsif compare.is_a?(Symbol) && value.is_a?(String)
|
28
|
+
value.to_sym == compare
|
33
29
|
else
|
34
|
-
|
30
|
+
value == compare || mapped_value == compare
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
@@ -11,6 +11,11 @@ class ReeEnum::Values
|
|
11
11
|
@collection_by_mapped_value = {}
|
12
12
|
end
|
13
13
|
|
14
|
+
def value_type
|
15
|
+
raise ArgumentError, "value_type is not defined" unless defined?(@value_type)
|
16
|
+
@value_type
|
17
|
+
end
|
18
|
+
|
14
19
|
def to_a
|
15
20
|
@collection
|
16
21
|
end
|
@@ -19,12 +24,13 @@ class ReeEnum::Values
|
|
19
24
|
@collection.each(&)
|
20
25
|
end
|
21
26
|
|
22
|
-
contract(Or[Symbol, String] => Nilor[ReeEnum::Value])
|
27
|
+
contract(Or[Symbol, String, Integer] => Nilor[ReeEnum::Value])
|
23
28
|
def by_value(value)
|
24
|
-
|
29
|
+
value = value.to_s if value.is_a?(Symbol)
|
30
|
+
@collection_by_value[value]
|
25
31
|
end
|
26
32
|
|
27
|
-
contract(Or[Symbol, String] => ReeEnum::Value).throws(ArgumentError)
|
33
|
+
contract(Or[Symbol, String, Integer] => ReeEnum::Value).throws(ArgumentError)
|
28
34
|
def by_value!(value)
|
29
35
|
by_value(value) ||
|
30
36
|
(raise ArgumentError.new("constant for value #{value.inspect} is not found in #{self.inspect}"))
|
@@ -45,9 +51,15 @@ class ReeEnum::Values
|
|
45
51
|
@collection.map(&:inspect).inspect
|
46
52
|
end
|
47
53
|
|
48
|
-
contract(String, Or[Integer, String], Symbol => ReeEnum::Value)
|
54
|
+
contract(Or[String, Integer], Or[Integer, String], Nilor[Symbol] => ReeEnum::Value)
|
49
55
|
def add(value, mapped_value, method)
|
50
|
-
if @
|
56
|
+
if @value_type.nil?
|
57
|
+
@value_type = value.class
|
58
|
+
elsif @value_type != value.class
|
59
|
+
raise ArgumentError, "#{@klass}: value types should be the same for all enum values"
|
60
|
+
end
|
61
|
+
|
62
|
+
if !method.nil? && @collection.any? { _1.method == method }
|
51
63
|
raise ArgumentError, "#{@klass}: method #{method.inspect} was already added"
|
52
64
|
end
|
53
65
|
|
@@ -37,6 +37,17 @@ RSpec.describe ReeEnum::DSL do
|
|
37
37
|
register_as_mapper_type
|
38
38
|
end
|
39
39
|
|
40
|
+
class Numbers
|
41
|
+
include ReeEnum::DSL
|
42
|
+
|
43
|
+
enum :numbers
|
44
|
+
|
45
|
+
val 0, method: :zero
|
46
|
+
val 1, method: :one
|
47
|
+
|
48
|
+
register_as_mapper_type
|
49
|
+
end
|
50
|
+
|
40
51
|
class Reflexives
|
41
52
|
include ReeEnum::DSL
|
42
53
|
|
@@ -46,25 +57,39 @@ RSpec.describe ReeEnum::DSL do
|
|
46
57
|
val :yourself
|
47
58
|
end
|
48
59
|
|
60
|
+
class ContentTypes
|
61
|
+
include ReeEnum::DSL
|
62
|
+
|
63
|
+
enum :content_types
|
64
|
+
|
65
|
+
val "video/mp4"
|
66
|
+
val "image/png"
|
67
|
+
|
68
|
+
register_as_mapper_type
|
69
|
+
end
|
70
|
+
|
49
71
|
class TestMapper
|
50
72
|
include ReeMapper::DSL
|
51
73
|
|
52
74
|
mapper :test_mapper do
|
75
|
+
link :numbers
|
53
76
|
link :states
|
54
77
|
link :types
|
55
78
|
end
|
56
79
|
|
57
80
|
class Dto
|
58
|
-
attr_reader :type, :state
|
59
|
-
def initialize(type, state)
|
81
|
+
attr_reader :type, :state, :number
|
82
|
+
def initialize(type, state, number)
|
60
83
|
@type = type
|
61
84
|
@state = state
|
85
|
+
@number = number
|
62
86
|
end
|
63
87
|
end
|
64
88
|
|
65
89
|
build_mapper.use(:serialize).use(:cast).use(:db_dump).use(:db_load, dto: Dto) do
|
66
90
|
types :type
|
67
91
|
states :state
|
92
|
+
numbers :number
|
68
93
|
end
|
69
94
|
end
|
70
95
|
|
@@ -86,6 +111,8 @@ RSpec.describe ReeEnum::DSL do
|
|
86
111
|
expect(o.second).to eq(1)
|
87
112
|
expect(o.get_values.by_value(:first)).to eq(o.first)
|
88
113
|
expect(o.get_values.by_value(:second)).to eq(o.second)
|
114
|
+
expect(o.get_values.by_value("first")).to eq(o.first)
|
115
|
+
expect(o.get_values.by_value("second")).to eq(o.second)
|
89
116
|
expect(o.get_values.by_mapped_value(0)).to eq(o.first)
|
90
117
|
expect(o.get_values.by_mapped_value(1)).to eq(o.second)
|
91
118
|
expect(o.get_values.to_a).to eq([o.first, o.second])
|
@@ -108,11 +135,13 @@ RSpec.describe ReeEnum::DSL do
|
|
108
135
|
mapper.serialize({
|
109
136
|
state: TestReeEnum::States.first,
|
110
137
|
type: TestReeEnum::Types.account,
|
138
|
+
number: TestReeEnum::Numbers.zero,
|
111
139
|
})
|
112
140
|
).to eq(
|
113
141
|
{
|
114
142
|
state: 'first',
|
115
|
-
type: 'account'
|
143
|
+
type: 'account',
|
144
|
+
number: 0,
|
116
145
|
}
|
117
146
|
)
|
118
147
|
|
@@ -120,6 +149,7 @@ RSpec.describe ReeEnum::DSL do
|
|
120
149
|
mapper.cast({
|
121
150
|
state: 'first',
|
122
151
|
type: 'invalid',
|
152
|
+
number: 0,
|
123
153
|
})
|
124
154
|
}.to raise_error(ReeMapper::CoercionError, '`type` should be one of ["account"]')
|
125
155
|
|
@@ -127,11 +157,13 @@ RSpec.describe ReeEnum::DSL do
|
|
127
157
|
mapper.cast({
|
128
158
|
state: 'first',
|
129
159
|
type: 'account',
|
160
|
+
number: 0,
|
130
161
|
})
|
131
162
|
).to eq(
|
132
163
|
{
|
133
164
|
state: TestReeEnum::States.first,
|
134
|
-
type: TestReeEnum::Types.account
|
165
|
+
type: TestReeEnum::Types.account,
|
166
|
+
number: TestReeEnum::Numbers.zero,
|
135
167
|
}
|
136
168
|
)
|
137
169
|
|
@@ -139,11 +171,27 @@ RSpec.describe ReeEnum::DSL do
|
|
139
171
|
mapper.cast({
|
140
172
|
state: TestReeEnum::States.first,
|
141
173
|
type: TestReeEnum::Types.account,
|
174
|
+
number: TestReeEnum::Numbers.zero,
|
142
175
|
})
|
143
176
|
).to eq(
|
144
177
|
{
|
145
178
|
state: TestReeEnum::States.first,
|
146
|
-
type: TestReeEnum::Types.account
|
179
|
+
type: TestReeEnum::Types.account,
|
180
|
+
number: TestReeEnum::Numbers.zero,
|
181
|
+
}
|
182
|
+
)
|
183
|
+
|
184
|
+
expect(
|
185
|
+
mapper.cast({
|
186
|
+
state: TestReeEnum::States.first,
|
187
|
+
type: TestReeEnum::Types.account,
|
188
|
+
number: TestReeEnum::Numbers.zero,
|
189
|
+
})
|
190
|
+
).to eq(
|
191
|
+
{
|
192
|
+
state: "first",
|
193
|
+
type: "account",
|
194
|
+
number: 0,
|
147
195
|
}
|
148
196
|
)
|
149
197
|
|
@@ -151,24 +199,31 @@ RSpec.describe ReeEnum::DSL do
|
|
151
199
|
mapper.db_dump({
|
152
200
|
state: TestReeEnum::States.first,
|
153
201
|
type: TestReeEnum::Types.account,
|
202
|
+
number: TestReeEnum::Numbers.zero,
|
154
203
|
})
|
155
204
|
).to eq(
|
156
205
|
{
|
157
206
|
state: 0,
|
158
|
-
type: "account"
|
207
|
+
type: "account",
|
208
|
+
number: 0,
|
159
209
|
}
|
160
210
|
)
|
161
211
|
|
162
212
|
dto = mapper.db_load({
|
163
213
|
state: 0,
|
164
214
|
type: "account",
|
215
|
+
number: 0,
|
165
216
|
})
|
166
217
|
|
167
218
|
expect(dto.state).to eq(TestReeEnum::States.first)
|
168
219
|
expect(dto.state).to be_a(ReeEnum::Value)
|
169
220
|
expect(dto.type).to eq(TestReeEnum::Types.account)
|
170
221
|
expect(dto.type).to be_a(ReeEnum::Value)
|
222
|
+
expect(dto.number).to eq(TestReeEnum::Numbers.zero)
|
223
|
+
expect(dto.number).to be_a(ReeEnum::Value)
|
171
224
|
|
172
225
|
expect(TestReeEnum::Reflexives.myself).to eq(:self)
|
226
|
+
|
227
|
+
expect(TestReeEnum::ContentTypes.method_defined?(:"video/mp4")).to be_falsey
|
173
228
|
}
|
174
229
|
end
|
@@ -6,14 +6,15 @@ class ReeHash::Slice
|
|
6
6
|
fn :slice do
|
7
7
|
link :build_filter_keys
|
8
8
|
link 'ree_hash/contracts/hash_keys_contract', -> { HashKeysContract }
|
9
|
-
def_error { MissingKeyErr }
|
10
|
-
def_error { InvalidFilterKey }
|
11
9
|
end
|
12
10
|
|
11
|
+
MissingKeyErr = Class.new(ArgumentError)
|
12
|
+
InvalidFilterKey = Class.new(ArgumentError)
|
13
|
+
|
13
14
|
doc(<<~DOC)
|
14
15
|
Replaces the hash with only the given keys.
|
15
16
|
Returns a hash containing the removed key/value pairs.
|
16
|
-
|
17
|
+
|
17
18
|
hash = { a: 1, b: {e: 2, f: 1}, c: 3, d: 4 }
|
18
19
|
slice(hash, [:a, :b]) # => {a: 1, b: 2}
|
19
20
|
slice(hash, [:a, b: [:e]]) # => {a: 1, b: {e: 2}}
|
@@ -15,11 +15,11 @@ class ReeMapper::Integer < ReeMapper::AbstractType
|
|
15
15
|
if value.is_a?(Integer)
|
16
16
|
value
|
17
17
|
elsif value.is_a?(String)
|
18
|
-
|
19
|
-
|
20
|
-
rescue ArgumentError => e
|
18
|
+
value = Integer(value, exception: false)
|
19
|
+
if value.nil?
|
21
20
|
raise ReeMapper::CoercionError, "`#{name}` is invalid integer"
|
22
21
|
end
|
22
|
+
value
|
23
23
|
else
|
24
24
|
raise ReeMapper::TypeError, "`#{name}` should be an integer"
|
25
25
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
class ReeObject::ToHash
|
4
4
|
include Ree::FnDSL
|
5
5
|
|
6
|
-
fn :to_hash
|
7
|
-
|
8
|
-
|
6
|
+
fn :to_hash
|
7
|
+
|
8
|
+
RecursiveObjectErr = Class.new(ArgumentError)
|
9
9
|
|
10
10
|
BASIC_TYPES = [
|
11
11
|
Date, Time, Numeric, String, FalseClass, TrueClass, NilClass, Symbol,
|
data/lib/ree_lib/ree.setup.rb
CHANGED
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.74
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ree
|
@@ -809,9 +809,12 @@ files:
|
|
809
809
|
- lib/ree_lib/packages/ree_enum/Package.schema.json
|
810
810
|
- lib/ree_lib/packages/ree_enum/bin/console
|
811
811
|
- lib/ree_lib/packages/ree_enum/package/ree_enum.rb
|
812
|
+
- lib/ree_lib/packages/ree_enum/package/ree_enum/base_enum_mapper.rb
|
812
813
|
- lib/ree_lib/packages/ree_enum/package/ree_enum/contractable.rb
|
813
814
|
- lib/ree_lib/packages/ree_enum/package/ree_enum/dsl.rb
|
814
815
|
- lib/ree_lib/packages/ree_enum/package/ree_enum/enumerable.rb
|
816
|
+
- lib/ree_lib/packages/ree_enum/package/ree_enum/integer_value_enum_mapper.rb
|
817
|
+
- lib/ree_lib/packages/ree_enum/package/ree_enum/string_value_enum_mapper.rb
|
815
818
|
- lib/ree_lib/packages/ree_enum/package/ree_enum/value.rb
|
816
819
|
- lib/ree_lib/packages/ree_enum/package/ree_enum/values.rb
|
817
820
|
- lib/ree_lib/packages/ree_enum/spec/package_schema_spec.rb
|