custom_fields 2.10.0.beta2 → 2.12.0

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: 0b88b8f37bf162d1b2a3bb28e88fc97299498c018b546066cfb51ee23764f338
4
- data.tar.gz: b2085cf064dce105c4215155f51b9e2c4e1a84e688fadb8b9b460bf8dca36d8e
3
+ metadata.gz: a51660465e7fc7fcce0e0d68721fd629e3a7d970da166fda4166c964aa9c1c6a
4
+ data.tar.gz: 3dec7501714fa700975e47dfc2989e78ad31e070ec47cf7a0c79f30e4b64bd1c
5
5
  SHA512:
6
- metadata.gz: 075c7f7ee4b5af9a689810a55a3645aa894e4e64891c55596b83ad4e76b9fb57962bcb47a68375fa8a3864e735bbea088c3b18875fba25b7a6cfc0cf04c31dbb
7
- data.tar.gz: 618e69bd1b7e398499dc6db8eaed8b8e5a9cceff8166063e8e7120174d2c925df992c50e2150a86ed77ebc14cb2ba68035ced9f539eb9a15eee44c5ffd0ada7e
6
+ metadata.gz: 29c47fa50966d7c86e8a1ab6b92240f630ac471b0fa4c0824b0e7c63cd161c0d0d94566735689b98acd453dbfccca8de2fc59244619f3dc0b34456c025bf6f7e
7
+ data.tar.gz: ad06f66129e77dc3297256ba4645170040d408724deee848bc4cfbe119d4e52ab2e8a7aa11ad3e399544d2acfcfe7b6f0cd9defe90b44ab9729beb0f966e0154
@@ -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.12.0'
4
4
 
5
5
  end
data/lib/custom_fields.rb CHANGED
@@ -10,7 +10,7 @@ Money.locale_backend = :currency
10
10
  module CustomFields
11
11
 
12
12
  @@options = {
13
- reserved_names: Mongoid.destructive_fields + %w(id _id send class destroy),
13
+ reserved_names: Mongoid.destructive_fields + %w(id _id send class destroy system),
14
14
  default_currency: 'EUR'
15
15
  }
16
16
 
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.12.0
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: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.1.0
39
+ version: 1.3.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.1.0
46
+ version: 1.3.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -160,15 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - "~>"
162
162
  - !ruby/object:Gem::Version
163
- version: '2.3'
163
+ version: '2.6'
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: '0'
169
169
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.7.3
170
+ rubygems_version: 3.1.4
172
171
  signing_key:
173
172
  specification_version: 4
174
173
  summary: Custom fields extension for Mongoid.