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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fa0f66153a455f42150991660c75a1ce836918e054176f4043ad9d825c17a8a
4
- data.tar.gz: b1a36ab72f838da9622f96e8e3f9fc8b1946a78608cfdd28a8dae4bf23a4ef52
3
+ metadata.gz: 62e25eddc0fd59750f4eb166fe3cc3b9b70bde690bc203452749aa3c9961a5ee
4
+ data.tar.gz: 40dc524a36e3de7b399d1d3453b57a38a8ce52bceebe681fcf160c2590449fd2
5
5
  SHA512:
6
- metadata.gz: 278748204360c321e8bd91130bfc675183c4cf6a8fa8324c9383f678b6af1a70e06f11f0f9fc5ccbc34ee90f8c4a7d8caf36ff0240e6bb197de38e50a6742566
7
- data.tar.gz: d2123d32021a00f673c5851174dc1c82e646f82db20409c9949842014e4527057e0d8076d8b856c9511a360cbc956d88764360c7e50ae6e6b6560509aab205b6
6
+ metadata.gz: 1e09f2db0575da0e803ed76c5bd162416e91c15d9c308252d0aa1dc7e7cb85fd3e08bfeb253c95346e2780b3c5987710d07b71f89cecf858ca8b5c433339d5d9
7
+ data.tar.gz: 3251732d5e69e2f3da4260ce95988a0e647f978234785ff6d3a445d59541155f917d28a3e19efb00eea14bfe53f7432eb42b1c2517cfc32a66fd629558ebf30a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.114)
4
+ ree_lib (1.0.116)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -32,7 +32,7 @@ module ReeDao
32
32
  end
33
33
 
34
34
  def last(mapper: nil)
35
- with_mapper(mapper).__original_last
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::EntityDSL
78
+ include ReeDto::DSL
78
79
 
79
- properties(
80
- id: Nilor[Integer],
81
- project_id: Nilor[Integer]
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
- persist_assoc(project, TestPersistAssoc::ProjectUsersDao.new)
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)
@@ -28,6 +28,10 @@ class ReeDto::CollectionFilter
28
28
  count
29
29
  end
30
30
 
31
+ def inspect
32
+ to_a.inspect
33
+ end
34
+
31
35
  contract Any => Any
32
36
  def remove(item)
33
37
  check_item(item)
@@ -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 :#{name} not set for:#{self}")
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
- fields = self.class.fields
95
- max_length = fields.map(&:name).sort_by(&:size).last.size
96
- result = "\n#{self.class}\n"
97
-
98
- data = fields.select { has_value?(_1.name) }.map do |field|
99
- name = field.name.to_s
100
- extra_spaces = ' ' * (max_length - name.size)
101
- %Q( #{name}#{extra_spaces} = #{get_value(field.name).inspect})
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("\n")
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 :string not set for:\nReeDto::DtoClass\n with_default = 1")
59
+ expect(e.message).to eq("field `string` not set for: #<dto ReeDto::DtoClass with_default=1>")
60
60
  end
61
61
  }
62
62
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.114"
4
+ VERSION = "1.0.116"
5
5
  end
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.114
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-12 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree