custom_fields 2.10.0.beta2 → 2.10.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b88b8f37bf162d1b2a3bb28e88fc97299498c018b546066cfb51ee23764f338
4
- data.tar.gz: b2085cf064dce105c4215155f51b9e2c4e1a84e688fadb8b9b460bf8dca36d8e
3
+ metadata.gz: 92008a0e4adc50b36d45541d2e9a552f5a933c668fda3c563cb44f6da98938a8
4
+ data.tar.gz: 74b7e9231c7f25b2c814f24491a00228111c16002bf3f0a9c28ec1589db17536
5
5
  SHA512:
6
- metadata.gz: 075c7f7ee4b5af9a689810a55a3645aa894e4e64891c55596b83ad4e76b9fb57962bcb47a68375fa8a3864e735bbea088c3b18875fba25b7a6cfc0cf04c31dbb
7
- data.tar.gz: 618e69bd1b7e398499dc6db8eaed8b8e5a9cceff8166063e8e7120174d2c925df992c50e2150a86ed77ebc14cb2ba68035ced9f539eb9a15eee44c5ffd0ada7e
6
+ metadata.gz: 72cde13cf67b46cc86c44c858072d10e209e1e3496d1ae32e0ba9736aefac849003d830ad8b15562796b3a5d66251b276ec8a8aaa693ba97d277b9f528960f71
7
+ data.tar.gz: 7e55cb358cdca1cddacb4791f14eefa3cc67991765d1d27f17131a1bf7cf45093f2174c049b3e1ca85eac9c262975e35319b61483f71f6a3f4bff8a73a82a037
@@ -8,9 +8,10 @@ module CarrierWave
8
8
  mount_uploader_without_localization(column, uploader, options, &block)
9
9
 
10
10
  define_method(:read_uploader) do |name|
11
- # puts "read_uploader #{name} / #{read_attribute(name.to_sym).inspect}" # DEBUG
11
+ # puts "read_uploader #{name} / #{read_attribute(name.to_sym).inspect} / #{::Mongoid::Fields::I18n.locale.inspect}" # DEBUG
12
12
 
13
13
  value = read_attribute(name.to_sym)
14
+
14
15
  unless value.nil?
15
16
  self.class.fields[name.to_s].demongoize(value)
16
17
  else
@@ -26,15 +27,30 @@ module CarrierWave
26
27
 
27
28
  class Mounter
28
29
 
29
- def remove_previous_with_localization(before=nil, after=nil)
30
- _after = after
30
+ def remove_previous_with_localization(before = nil, after = nil)
31
+ _before, _after = before, after
32
+ locale = ::Mongoid::Fields::I18n.locale.to_s
33
+
34
+ # custom case:
35
+ # the record owns a localized file field. A new file has been attached to it
36
+ # in the default locale. Now, we want to upload a file in another locale with
37
+ # a different name.
38
+ # We absolutely don't want to erase the file in the default locale
39
+ if record.class.fields[column.to_s].localized? &&
40
+ record.changes[column]&.first == '_new_'
41
+ _before = [nil]
42
+ end
43
+
44
+ # FIXME: can't reproduce this behavior locally but it happens in production
45
+ if before && before.first.is_a?(Hash)
46
+ _before = [before.first[locale]]
47
+ end
31
48
 
32
49
  if after && after.first.is_a?(Hash)
33
- locale = ::Mongoid::Fields::I18n.locale.to_s
34
50
  _after = [after.first[locale]]
35
51
  end
36
52
 
37
- remove_previous_without_localization(before, _after)
53
+ remove_previous_without_localization(_before, _after)
38
54
  end
39
55
 
40
56
  alias_method :remove_previous_without_localization, :remove_previous
@@ -87,6 +87,15 @@ module CustomFields
87
87
 
88
88
  process :set_size_in_model
89
89
 
90
+ def filename
91
+ if original_filename && model.fields[mounted_as.to_s].localized?
92
+ _original_filename, extension = original_filename.split('.')
93
+ ["#{_original_filename}_#{::Mongoid::Fields::I18n.locale}", extension].compact.join('.')
94
+ else
95
+ original_filename
96
+ end
97
+ end
98
+
90
99
  def set_size_in_model
91
100
  size_field_name = :"#{mounted_as}_size"
92
101
 
@@ -1,5 +1,5 @@
1
1
  module CustomFields #:nodoc
2
2
 
3
- VERSION = '2.10.0.beta2'
3
+ VERSION = '2.10.0.beta3'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0.beta2
4
+ version: 2.10.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2019-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -163,12 +163,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  version: '2.3'
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - "~>"
166
+ - - ">"
167
167
  - !ruby/object:Gem::Version
168
- version: '2.4'
168
+ version: 1.3.1
169
169
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.7.3
170
+ rubygems_version: 3.0.1
172
171
  signing_key:
173
172
  specification_version: 4
174
173
  summary: Custom fields extension for Mongoid.