custom_fields 2.6.0 → 2.7.0.rc1

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
  SHA1:
3
- metadata.gz: 1e33b47ab6170cca8bcce7196f00f81d1b7fbf6d
4
- data.tar.gz: e604ee4eea1a252ebf53ea0155f6b146e5bc8427
3
+ metadata.gz: bc70111716eabee45d9c1d76bbca61109a7085ac
4
+ data.tar.gz: e41472ca2346957d15cdb72fedb1dc3772a0ff7a
5
5
  SHA512:
6
- metadata.gz: 61d40ce45b216bf05e9187571bbeec95d29cad9af0fb776d73358b8fd912b85ea23a5ededc74b2ecd9a6584d27771d6549252cc79745a4e0392146fed8d80974
7
- data.tar.gz: ffa68d31f8e3167147e9a5a7ca8fb7acbe3d7943bdcd49254f0878199ef4fd0199f417370082761a2735218a639c75cd490ff476d69a802a57bbdbb0134f9f29
6
+ metadata.gz: c9f2dd50ac8ba4e204442b2452e48544a2d79635bbf94d7298a916804a0a22de68a0368df68bc3091d7836bd2a5e6c7aad45f6f65f192ea339595a698057440b
7
+ data.tar.gz: dca236e8c22c611a111556e8050e8dfeae26ec2e5308d2d5344f60a0e1575a56a3328958a012ac1fea646c88d428a2d03e5500b1a1051f6abb6e523e0a52ec74
@@ -35,7 +35,7 @@ module Mongoid #:nodoc
35
35
  end
36
36
 
37
37
  def self.fallbacks?
38
- !self.instance.fallbacks.blank? || ::I18n.respond_to?(:fallbacks)
38
+ !self.instance.fallbacks.blank? || (::I18n.respond_to?(:fallbacks) && !::I18n.fallbacks.blank?)
39
39
  end
40
40
 
41
41
  def self.clear_fallbacks
@@ -21,6 +21,7 @@ module CustomFields
21
21
  name = rule['name']
22
22
 
23
23
  klass.mount_uploader name, FileUploader
24
+ klass.field :"#{name}_size", type: ::Hash, default: {}
24
25
 
25
26
  if rule['localized'] == true
26
27
  klass.replace_field name, ::String, true
@@ -83,6 +84,21 @@ module CustomFields
83
84
  end
84
85
 
85
86
  class FileUploader < ::CarrierWave::Uploader::Base
87
+
88
+ process :set_size_in_model
89
+
90
+ def set_size_in_model
91
+ size_field_name = :"#{mounted_as}_size"
92
+
93
+ if model.respond_to?(size_field_name)
94
+ is_localized = model.fields[mounted_as.to_s].options[:localize]
95
+ key = is_localized ? ::Mongoid::Fields::I18n.locale.to_s : 'default'
96
+ values = model.send(size_field_name)
97
+
98
+ values[key] = file.size
99
+ end
100
+ end
101
+
86
102
  end
87
103
 
88
104
  end
@@ -164,10 +164,12 @@ module CustomFields
164
164
 
165
165
  name = if !option['name'].respond_to?(:merge)
166
166
  option['name']
167
+ elsif option['name'].has_key?(locale)
168
+ option['name'][locale.to_s]
167
169
  elsif Mongoid::Fields::I18n.fallbacks?
168
170
  option['name'][Mongoid::Fields::I18n.fallbacks[locale.to_sym].map(&:to_s).find { |loc| !option['name'][loc].nil? }]
169
171
  else
170
- option['name'][locale.to_s]
172
+ nil
171
173
  end
172
174
 
173
175
  { '_id' => option['_id'], 'name' => name }
@@ -1,5 +1,5 @@
1
1
  module CustomFields #:nodoc
2
2
 
3
- VERSION = '2.6.0'
3
+ VERSION = '2.7.0.rc1'
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.6.0
4
+ version: 2.7.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.2
19
+ version: 5.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.2
26
+ version: 5.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: carrierwave-mongoid
29
29
  requirement: !ruby/object:Gem::Requirement