coaster 1.4.14 → 1.4.16

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: 7c1900122e65b530f6f0fa5a326066a732f5f4a9fb8b50321456d25648acceae
4
- data.tar.gz: 21cd9c962eadc7e375fd8c39fc03259f8aeee6efa525efd4c770ca3d5c8ece2b
3
+ metadata.gz: d9b06a2cf428c68aaa8d8a990cd3c7a38d33bb2ff6e032d12ee7aeb3e3816cd9
4
+ data.tar.gz: 638bf5a8d7a944c671b0b7e10f5308abff516d0b2ed98ac16279201131f394bf
5
5
  SHA512:
6
- metadata.gz: 0d1ab771e687cf80aae1c22cf1d4b37787354966d3465d0bd33f5a2dab498d4ef63cb4214ab6d331556d172ab889773dc9e584fd29d61837c05beec17f495b32
7
- data.tar.gz: 7e720f7287a730114f978a2a469ccb64099d809eec9c415d851efb9df5bcbc74f2d06b287e555f04c7bf0dc50566ad263538da6a79471d6a67bd721dac45c576
6
+ metadata.gz: a659d1d247a9294ee83e8a31bb7df3ab536bb043a5880dfebafe0dee3680ebc6edab51ea12c6c3894f2a6cc99af15a2e14a103a236326255d739f82f9ec2935c
7
+ data.tar.gz: c2fff3ed081673f46fbb7570f10ef7d080bf2fd35898676d536a373830c38cf8e909e92a73c818226344b6ea0ec8b359987e54f6953ce7444e1e5c692ddc0fe7
@@ -25,16 +25,16 @@ module Coaster
25
25
  cm || key.to_s
26
26
  end
27
27
 
28
- def serialized_property(serialize_column, key, type: nil, comment: nil, getter: nil, setter: nil, setter_callback: nil, default: nil)
28
+ def serialized_property(serialize_column, key, type: nil, comment: nil, getter: nil, setter: nil, setter_callback: nil, default: nil, rescuer: nil)
29
29
  raise DuplicatedProperty, "#{self.name}##{key} duplicated\n#{caller[0..5].join("\n")}" if serialized_property_settings[key.to_sym]
30
- serialized_property_settings[key.to_sym] = {type: type, comment: comment, getter: getter, setter: setter, setter_callback: setter_callback, default: default}
31
- _typed_serialized_property(serialize_column, key, type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default)
30
+ serialized_property_settings[key.to_sym] = {type: type, comment: comment, getter: getter, setter: setter, setter_callback: setter_callback, default: default, rescuer: rescuer}
31
+ _typed_serialized_property(serialize_column, key, type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default, rescuer: rescuer)
32
32
  end
33
33
 
34
- def serialized_properties(serialize_column, *keys, type: nil, getter: nil, setter: nil, setter_callback: nil, default: nil)
34
+ def serialized_properties(serialize_column, *keys, type: nil, getter: nil, setter: nil, setter_callback: nil, default: nil, rescuer: nil)
35
35
  keys.flatten.each do |key|
36
36
  key_name = key
37
- prop_hash = {type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default}
37
+ prop_hash = {type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default, rescuer: rescuer}
38
38
  if key.is_a? Hash
39
39
  key_name = key[:key]
40
40
  prop_hash = {type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default}.merge(key)
@@ -46,7 +46,7 @@ module Coaster
46
46
 
47
47
  private
48
48
 
49
- def _typed_serialized_property(serialize_column, key, type: nil, getter: nil, setter: nil, setter_callback: nil, default: nil)
49
+ def _typed_serialized_property(serialize_column, key, type: nil, getter: nil, setter: nil, setter_callback: nil, default: nil, rescuer: nil)
50
50
  case type
51
51
  when String then
52
52
  # String은 나중에 eval해서 가져옴,
@@ -55,14 +55,25 @@ module Coaster
55
55
  if type.is_a?(String)
56
56
  begin
57
57
  type = eval(type)
58
- raise InvalidProperty, "#{self.name}##{key} type string is return string #{type}" if type.is_a?(String)
58
+ raise InvalidProperty, m: "#{self.name}##{key} type string is return string #{type}", type: type if type.is_a?(String)
59
59
  rescue InvalidProperty => e
60
- raise
60
+ if rescuer
61
+ type = rescuer.call(e)
62
+ else
63
+ raise
64
+ end
61
65
  rescue => e
62
- raise InvalidProperty, "#{self.name}##{key} eval failed: type:[#{type}] [#{e.class.name}] #{e.message}"
66
+ e.attributes[:type] = type
67
+ if rescuer
68
+ type = rescuer.call(e)
69
+ else
70
+ raise InvalidProperty, "#{self.name}##{key} eval failed: type:[#{type}] [#{e.class.name}] #{e.message}"
71
+ end
72
+ end
73
+ if type
74
+ serialized_property_setting(key.to_sym)[:type] = type
75
+ _typed_serialized_property serialize_column, key, type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default
63
76
  end
64
- serialized_property_setting(key.to_sym)[:type] = type
65
- _typed_serialized_property serialize_column, key, type: type, getter: getter, setter: setter, setter_callback: setter_callback, default: default
66
77
  end
67
78
  }
68
79
  when Array then
data/lib/coaster/util.rb CHANGED
@@ -52,7 +52,8 @@ module Coaster
52
52
  end
53
53
 
54
54
  array_keys = (array_start...(step2.keys.size+array_start)).to_a
55
- if array_keys == step2.keys.map(&:to_i).sort
55
+ step2_keys = step2.keys.map {|k| Integer(k)} rescue nil
56
+ if array_keys == step2_keys
56
57
  step3 = []
57
58
  array_keys.map(&:to_s).each do |k|
58
59
  step3 << step2[k]
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.4.14'
2
+ VERSION = '1.4.16'
3
3
  end
data/test/test_util.rb CHANGED
@@ -38,5 +38,12 @@ module Coaster
38
38
  b = Util.roughen_hashify(res, array_start: 1, delimiter: '/')
39
39
  assert_equal(a, b)
40
40
  end
41
+
42
+ def test_roughen_hashify
43
+ assert_equal({'a'=> [2, 3]}, Util.roughen_hashify({'a.0' => 2, 'a.1' => 3}))
44
+ assert_equal({'a'=> [2, 3]}, Util.roughen_hashify({'a.1' => 2, 'a.2' => 3}, array_start: 1))
45
+ res = Util.roughen_hashify({"1.a"=>1, "2"=>22, "3.1"=>33, "3.2"=>44, "4.b.c.1"=>33, "4.b.c.2.d"=>4}, array_start: 1)
46
+ assert_equal([{"a"=>1}, 22, [33, 44], {"b"=>{"c"=>[33, {"d"=>4}]}}], res)
47
+ end
41
48
  end
42
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.14
4
+ version: 1.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzz jung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 3.3.27
249
+ rubygems_version: 3.4.19
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: A little convenient feature for standard library