ree_lib 1.0.114 → 1.0.116
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ree_lib/packages/ree_dao/package/ree_dao/dataset_extensions.rb +26 -1
- data/lib/ree_lib/packages/ree_dao/spec/ree_dao/functions/persist_assoc_spec.rb +11 -10
- data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/collection_filter.rb +4 -0
- data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_collection.rb +10 -0
- data/lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_instance_methods.rb +22 -10
- data/lib/ree_lib/packages/ree_dto/spec/ree_dto/dsl_spec.rb +1 -1
- data/lib/ree_lib/version.rb +1 -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: 62e25eddc0fd59750f4eb166fe3cc3b9b70bde690bc203452749aa3c9961a5ee
|
4
|
+
data.tar.gz: 40dc524a36e3de7b399d1d3453b57a38a8ce52bceebe681fcf160c2590449fd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e09f2db0575da0e803ed76c5bd162416e91c15d9c308252d0aa1dc7e7cb85fd3e08bfeb253c95346e2780b3c5987710d07b71f89cecf858ca8b5c433339d5d9
|
7
|
+
data.tar.gz: 3251732d5e69e2f3da4260ce95988a0e647f978234785ff6d3a445d59541155f917d28a3e19efb00eea14bfe53f7432eb42b1c2517cfc32a66fd629558ebf30a
|
data/Gemfile.lock
CHANGED
@@ -32,7 +32,7 @@ module ReeDao
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def last(mapper: nil)
|
35
|
-
with_mapper(mapper).
|
35
|
+
with_mapper(mapper).reverse_order(:id).first
|
36
36
|
end
|
37
37
|
|
38
38
|
def all(mapper: nil)
|
@@ -43,6 +43,31 @@ module ReeDao
|
|
43
43
|
where({}).__original_delete
|
44
44
|
end
|
45
45
|
|
46
|
+
# @args [ReeDto::Dto, ReeDto::DtoCollection]
|
47
|
+
def persist(*args, set: nil)
|
48
|
+
args.each do |arg|
|
49
|
+
if arg.is_a?(ReeDto::DSL)
|
50
|
+
put_or_update(arg, set: set)
|
51
|
+
elsif arg.is_a?(ReeDto::DtoCollection) || arg.is_a?(Array) || arg.is_a?(Enumerable)
|
52
|
+
arg.each { put_or_update(_1, set: set) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def put_or_update(entity, set: nil)
|
58
|
+
if set
|
59
|
+
set.each do |key, val|
|
60
|
+
entity.send("#{key}=", val)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if entity.id
|
65
|
+
update(entity)
|
66
|
+
else
|
67
|
+
put(entity)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
46
71
|
def put(entity)
|
47
72
|
raw = dump_entity(entity)
|
48
73
|
|
@@ -40,6 +40,7 @@ RSpec.describe :persist_assoc do
|
|
40
40
|
|
41
41
|
package do
|
42
42
|
depends_on :ree_dao
|
43
|
+
depends_on :ree_dto
|
43
44
|
end
|
44
45
|
|
45
46
|
class Db
|
@@ -74,16 +75,11 @@ RSpec.describe :persist_assoc do
|
|
74
75
|
end
|
75
76
|
|
76
77
|
class ProjectUser
|
77
|
-
include ReeDto::
|
78
|
+
include ReeDto::DSL
|
78
79
|
|
79
|
-
|
80
|
-
id
|
81
|
-
project_id
|
82
|
-
)
|
83
|
-
|
84
|
-
contract Integer => Integer
|
85
|
-
def project_id=(id)
|
86
|
-
@project_id = id
|
80
|
+
build_dto do
|
81
|
+
field :id, Nilor[Integer], default: nil
|
82
|
+
field :project_id, Integer
|
87
83
|
end
|
88
84
|
end
|
89
85
|
|
@@ -125,7 +121,12 @@ RSpec.describe :persist_assoc do
|
|
125
121
|
|
126
122
|
TestPersistAssoc::ProjectsDao.new.put(project)
|
127
123
|
|
128
|
-
|
124
|
+
TestPersistAssoc::ProjectUsersDao.new.persist(
|
125
|
+
project.project_users.first,
|
126
|
+
project.project_users,
|
127
|
+
project.project_users.to_a,
|
128
|
+
set: {project_id: project.id}
|
129
|
+
)
|
129
130
|
|
130
131
|
expect(project.id).to be_a(Integer)
|
131
132
|
expect(project.project_users.first.id).to be_a(Integer)
|
@@ -23,6 +23,16 @@ class ReeDto::DtoCollection
|
|
23
23
|
@list.each(&block)
|
24
24
|
end
|
25
25
|
|
26
|
+
contract None => String
|
27
|
+
def to_s
|
28
|
+
inspect
|
29
|
+
end
|
30
|
+
|
31
|
+
contract None => String
|
32
|
+
def inspect
|
33
|
+
@list.inspect
|
34
|
+
end
|
35
|
+
|
26
36
|
class << self
|
27
37
|
def filter(name, filter_proc)
|
28
38
|
define_method name do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "./field_meta"
|
2
|
+
require "date"
|
2
3
|
|
3
4
|
module ReeDto::DtoInstanceMethods
|
4
5
|
include Ree::Contracts::Core
|
@@ -43,7 +44,7 @@ module ReeDto::DtoInstanceMethods
|
|
43
44
|
meta = get_meta(name)
|
44
45
|
|
45
46
|
if !meta.has_default?
|
46
|
-
raise FieldNotSetError.new("field
|
47
|
+
raise FieldNotSetError.new("field `#{name}` not set for: #{self}")
|
47
48
|
else
|
48
49
|
@_attrs[name] = meta.default
|
49
50
|
end
|
@@ -91,21 +92,32 @@ module ReeDto::DtoInstanceMethods
|
|
91
92
|
|
92
93
|
contract None => String
|
93
94
|
def to_s
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
95
|
+
result = "#<dto #{self.class} "
|
96
|
+
|
97
|
+
data = self.class.fields.select { has_value?(_1.name) }.map do |field|
|
98
|
+
"#{field.name}=#{inspect_value(get_value(field.name))}"
|
99
|
+
end
|
100
|
+
|
101
|
+
data += self.class.collections.select { send(_1.name).size > 0 }.map do |col|
|
102
|
+
"#{col.name}=#{send(col.name).inspect}"
|
102
103
|
end
|
103
104
|
|
104
|
-
result << data.join("
|
105
|
+
result << data.join(", ")
|
106
|
+
result << ">"
|
105
107
|
end
|
106
108
|
|
107
109
|
contract None => String
|
108
110
|
def inspect
|
109
111
|
to_s
|
110
112
|
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def inspect_value(v)
|
117
|
+
if v.is_a?(DateTime) || v.is_a?(Date) || v.is_a?(Time)
|
118
|
+
v.to_s.inspect
|
119
|
+
else
|
120
|
+
v.inspect
|
121
|
+
end
|
122
|
+
end
|
111
123
|
end
|
@@ -56,7 +56,7 @@ RSpec.describe ReeDto::DSL do
|
|
56
56
|
expect {
|
57
57
|
dto.string
|
58
58
|
}.to raise_error do |e|
|
59
|
-
expect(e.message).to eq("field
|
59
|
+
expect(e.message).to eq("field `string` not set for: #<dto ReeDto::DtoClass with_default=1>")
|
60
60
|
end
|
61
61
|
}
|
62
62
|
|
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.116
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ree
|