coaster 1.3.23 → 1.3.25

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: b0dc7311128a11f50e6fbc0c3971f5819f00ea0dc86e04e187004b30b98b2d97
4
- data.tar.gz: 3364c39308fb0a192f58523115b359bf9ff1653edd3a0a4dd6a93aa9abb7c37d
3
+ metadata.gz: 937a250b10e75a66027e94673abfb0c5c4526597d18b8bf4af679c5cd2582e3d
4
+ data.tar.gz: e774a2bc8281fe395a26887ff77b425256df396681e80994607791227701cc79
5
5
  SHA512:
6
- metadata.gz: 2bf9af511c19b64ab2990965300644cd75954b1f03414815c39d87e0f9de3416da3870e3a521f489ca72602b823f38884700caa7395285da3f01a6ffb5ad7270
7
- data.tar.gz: 32ab934501eab4fc6a8703ab2397e7e715496b819cc1621cb978fc74bfe5b47606ab20402e6f9812dc0e181d73ced0a6ed170e35b07e7c2d4429407e56230b5f
6
+ metadata.gz: 9a1484f822734c3018002842a45604669f461eb37d287f7fb63d51c2f0cf169f6d4fcd63b64e4fa6335c0cfcea95dd14255e56f556f0179f5fcecc7db845999d
7
+ data.tar.gz: 2ad1d5bdc02cf154c4e9215d11287885fa1897b9a0b76533d95f528065ce7870101babdb65622c39541e26ee417a4c0d28f7a1a401b0d908c9459fa0f3acc857
@@ -45,6 +45,11 @@ class Object
45
45
 
46
46
  if key_class.superclass == Object || key_class == Object
47
47
  return options[:description] if options[:description].present?
48
+ case options[:fallback]
49
+ when Proc then return options[:fallback].call(self)
50
+ when Symbol then return self.send(options[:fallback])
51
+ when String then return options[:fallback]
52
+ end
48
53
  if Coaster.logger
49
54
  Coaster.logger.info(options[:original_missing])
50
55
  Coaster.logger.debug(caller.join("\n"))
@@ -73,7 +73,8 @@ module Coaster
73
73
  },
74
74
  getter: proc { |val|
75
75
  type.include?(val) ? val : nil
76
- }
76
+ },
77
+ default: default
77
78
  else
78
79
  if type == Time
79
80
  _define_serialized_property serialize_column, key,
@@ -82,18 +83,20 @@ module Coaster
82
83
  if val.is_a?(Time)
83
84
  val.respond_to?(:to_fs) ? val.to_fs(:default_tz) : val.to_s(:default_tz)
84
85
  end
85
- }
86
+ },
87
+ default: default
86
88
  elsif type == Integer
87
89
  _define_serialized_property serialize_column, key,
88
90
  setter: proc { |val|
89
91
  val = val.blank? ? nil : Integer(val)
90
92
  val = setter.call(val) if setter
91
93
  val
92
- }
94
+ },
95
+ default: default
93
96
  elsif type == Array
94
- _define_serialized_property(serialize_column, key, default: [])
97
+ _define_serialized_property(serialize_column, key, default: default || [])
95
98
  elsif type && type < ActiveRecord::Base
96
- _define_serialized_property serialize_column, "#{key}_id"
99
+ _define_serialized_property serialize_column, "#{key}_id", default: default
97
100
 
98
101
  define_method key.to_sym do
99
102
  instance_val = instance_variable_get("@#{key}".to_sym)
@@ -1,3 +1,3 @@
1
1
  module Coaster
2
- VERSION = '1.3.23'
2
+ VERSION = '1.3.25'
3
3
  end
@@ -27,6 +27,12 @@ module Coaster
27
27
  assert_equal 'translation missing: en.class.Coaster.NotTranslated.self', NotTranslated._translate
28
28
  end
29
29
 
30
+ def test_fallback
31
+ assert_equal 'Coaster::NotTranslated', NotTranslated._translate(fallback: :name)
32
+ assert_equal 'aabbcc', NotTranslated._translate(fallback: 'aabbcc')
33
+ assert_equal 'Coaster::NotTranslated..aabb', NotTranslated._translate(fallback: proc{|klass| "#{klass.name}..aabb"})
34
+ end
35
+
30
36
  def test_raise_translation_missing
31
37
  exception = catch(:exception) do
32
38
  NotTranslated._translate(throw: true)
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.3.23
4
+ version: 1.3.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - buzz jung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-22 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n