ree_lib 1.0.115 → 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: 44a0cdf9f51bfc7d6e76013436bf67b352dd0dc5284794b508198a76e75bdc68
4
- data.tar.gz: 33bb2f9dcb901285290855138d473e287194faff1d4c05f0510310ec2884c756
3
+ metadata.gz: 62e25eddc0fd59750f4eb166fe3cc3b9b70bde690bc203452749aa3c9961a5ee
4
+ data.tar.gz: 40dc524a36e3de7b399d1d3453b57a38a8ce52bceebe681fcf160c2590449fd2
5
5
  SHA512:
6
- metadata.gz: a4190d2b5dfd5df12a00e642e9162c67212ec89f1c2498976c7a434070c17fae044cc7ca81219de997740b43987318bc19670fdd2f2d1571bef37f9df7fc8402
7
- data.tar.gz: b1740456bd572f10db6941a7a566047f6506bddbcf9469e1993352129df3a720088510efa9b94a3d0120d0d40f5145fda1ad3dc2f6df52456de0b03ca492ff88
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.115)
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)
@@ -46,10 +46,9 @@ module ReeDao
46
46
  # @args [ReeDto::Dto, ReeDto::DtoCollection]
47
47
  def persist(*args, set: nil)
48
48
  args.each do |arg|
49
- case arg
50
- when ReeDto::DSL
49
+ if arg.is_a?(ReeDto::DSL)
51
50
  put_or_update(arg, set: set)
52
- when ReeDto::DtoCollection, Array
51
+ elsif arg.is_a?(ReeDto::DtoCollection) || arg.is_a?(Array) || arg.is_a?(Enumerable)
53
52
  arg.each { put_or_update(_1, set: set) }
54
53
  end
55
54
  end
@@ -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.115"
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.115
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