globalize 6.0.0 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Appraisals +3 -8
- data/CHANGELOG.md +10 -1
- data/Gemfile +1 -1
- data/lib/globalize.rb +25 -4
- data/lib/globalize/active_record/act_macro.rb +2 -2
- data/lib/globalize/active_record/class_methods.rb +2 -2
- data/lib/globalize/active_record/instance_methods.rb +38 -9
- data/lib/globalize/active_record/migration.rb +21 -7
- data/lib/globalize/active_record/translated_attributes_query.rb +1 -1
- data/lib/globalize/version.rb +1 -1
- data/lib/patches/active_record/query_method.rb +2 -2
- data/lib/patches/active_record/rails6_1/uniqueness_validator.rb +45 -0
- data/lib/patches/active_record/relation.rb +9 -2
- data/lib/patches/active_record/serialization.rb +2 -2
- data/lib/patches/active_record/uniqueness_validator.rb +6 -4
- metadata +25 -24
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 232c58a035dbc34d1e513c552d3d0a52a7b349c414fb8c8126c74bfa94831e5e
|
4
|
+
data.tar.gz: d25bd58906d809849ba3ef3ed393e80c599bab47e2115c25ff9f75e11d1a4c7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c8d6cb1111dddd8f36e3baf3ec053a4db7f1b76b302694a631e41dcb849506d351dd5c5562e513e864912a129b030ae5cf6a0c6378460e534812a65651a60ea
|
7
|
+
data.tar.gz: 43bafaeac8081685600f7201fb88ae5d2c4195ac0c5d40595d78d846deb578f6255c42c55a8b68aafc18dc76a32c0ac370330ecfc1ae3bc6a0379415edb65309
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Appraisals
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
RAILS_VERSIONS = %w[
|
4
4
|
4.2.11.3
|
5
5
|
5.1.7
|
6
|
-
5.2.
|
7
|
-
6.0.3.
|
8
|
-
6.1.
|
6
|
+
5.2.5
|
7
|
+
6.0.3.6
|
8
|
+
6.1.3.1
|
9
9
|
]
|
10
10
|
|
11
11
|
RAILS_VERSIONS.each do |version|
|
@@ -31,11 +31,6 @@ RAILS_VERSIONS.each do |version|
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
platforms :rbx do
|
35
|
-
gem "rubysl", "~> 2.0"
|
36
|
-
gem "rubinius-developer_tools"
|
37
|
-
end
|
38
|
-
|
39
34
|
platforms :jruby do
|
40
35
|
if !ENV['CI'] || ENV['DB'] == 'sqlite3'
|
41
36
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 1'
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
# Globalize Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 6.0.1 (2021-06-23)
|
4
|
+
|
5
|
+
* Fix errors with Rails 6.1 and Ruby 3.0 [#778](https://github.com/globalize/globalize/pull/778) by [Andrew White](https://github.com/pixeltrix)
|
6
|
+
* Track `saved_changes` for Rails 5.1 and above [#780](https://github.com/globalize/globalize/pull/780) by [Peter Postma](https://github.com/ppostma)
|
7
|
+
|
8
|
+
## 6.0.0 (2021-01-11)
|
4
9
|
|
5
10
|
* Add `create_source_columns` option for migrations. [#715](https://github.com/globalize/globalize/pull/715) by [IlyasValiullov](https://github.com/IlyasValiullov)
|
6
11
|
* Autosave is now configurable, but defaults to false. [#736](https://github.com/globalize/globalize/pull/736) by [James Hart](https://github.com/hjhart)
|
7
12
|
* Fix foreign keys translation. [#769](https://github.com/globalize/globalize/pull/769) by [Sergey Tokarenko](https://github.com/stokarenko)
|
8
13
|
|
14
|
+
## 5.3.1 (2021-01-11)
|
15
|
+
|
16
|
+
* Fix foreign keys translation. [#773](https://github.com/globalize/globalize/pull/773) by [Sergey Tokarenko](https://github.com/stokarenko)
|
17
|
+
|
9
18
|
## 5.3.0 (2019-05-14)
|
10
19
|
|
11
20
|
* Prevent 'SystemStackError: stack level too deep' error on attribute reset. [#722](https://github.com/globalize/globalize/pull/722) by [Reinier de Lange](https://github.com/moiristo)
|
data/Gemfile
CHANGED
data/lib/globalize.rb
CHANGED
@@ -11,6 +11,15 @@ module Globalize
|
|
11
11
|
autoload :ActiveRecord, 'globalize/active_record'
|
12
12
|
autoload :Interpolation, 'globalize/interpolation'
|
13
13
|
|
14
|
+
ACTIVE_RECORD_50 = Gem::Version.new('5.0.0')
|
15
|
+
ACTIVE_RECORD_51 = Gem::Version.new('5.1.0')
|
16
|
+
ACTIVE_RECORD_52 = Gem::Version.new('5.2.0')
|
17
|
+
ACTIVE_RECORD_60 = Gem::Version.new('6.0.0')
|
18
|
+
ACTIVE_RECORD_61 = Gem::Version.new('6.1.0')
|
19
|
+
|
20
|
+
CURRENT_RUBY = Gem::Version.new(RUBY_VERSION)
|
21
|
+
RUBY_VERSION_27 = Gem::Version.new('2.7.0')
|
22
|
+
|
14
23
|
class << self
|
15
24
|
def locale
|
16
25
|
read_locale || I18n.locale
|
@@ -58,20 +67,32 @@ module Globalize
|
|
58
67
|
RequestStore.store
|
59
68
|
end
|
60
69
|
|
70
|
+
def ruby_27?
|
71
|
+
CURRENT_RUBY >= RUBY_VERSION_27
|
72
|
+
end
|
73
|
+
|
74
|
+
def rails_42?
|
75
|
+
::ActiveRecord.version < ACTIVE_RECORD_50
|
76
|
+
end
|
77
|
+
|
61
78
|
def rails_5?
|
62
|
-
::ActiveRecord.version >=
|
79
|
+
::ActiveRecord.version >= ACTIVE_RECORD_50
|
80
|
+
end
|
81
|
+
|
82
|
+
def rails_51?
|
83
|
+
::ActiveRecord.version >= ACTIVE_RECORD_51
|
63
84
|
end
|
64
85
|
|
65
86
|
def rails_52?
|
66
|
-
::ActiveRecord.version >=
|
87
|
+
::ActiveRecord.version >= ACTIVE_RECORD_52
|
67
88
|
end
|
68
89
|
|
69
90
|
def rails_6?
|
70
|
-
::ActiveRecord.version >=
|
91
|
+
::ActiveRecord.version >= ACTIVE_RECORD_60
|
71
92
|
end
|
72
93
|
|
73
94
|
def rails_61?
|
74
|
-
::ActiveRecord.version >=
|
95
|
+
::ActiveRecord.version >= ACTIVE_RECORD_61
|
75
96
|
end
|
76
97
|
|
77
98
|
protected
|
@@ -41,7 +41,7 @@ module Globalize
|
|
41
41
|
end
|
42
42
|
|
43
43
|
begin
|
44
|
-
if
|
44
|
+
if Globalize.rails_5? && table_exists? && translation_class.table_exists?
|
45
45
|
self.ignored_columns += translated_attribute_names.map(&:to_s)
|
46
46
|
reset_column_information
|
47
47
|
end
|
@@ -52,7 +52,7 @@ module Globalize
|
|
52
52
|
|
53
53
|
def check_columns!(attr_names)
|
54
54
|
# If tables do not exist or Rails version is greater than 5, do not warn about conflicting columns
|
55
|
-
return unless
|
55
|
+
return unless Globalize.rails_42? && table_exists? && translation_class.table_exists?
|
56
56
|
if (overlap = attr_names.map(&:to_s) & column_names).present?
|
57
57
|
ActiveSupport::Deprecation.warn(
|
58
58
|
["You have defined one or more translated attributes with names that conflict with column(s) on the model table. ",
|
@@ -3,7 +3,7 @@ module Globalize
|
|
3
3
|
module ClassMethods
|
4
4
|
delegate :translated_locales, :set_translations_table_name, :to => :translation_class
|
5
5
|
|
6
|
-
if
|
6
|
+
if Globalize.rails_42?
|
7
7
|
def columns_hash
|
8
8
|
super.except(*translated_attribute_names.map(&:to_s))
|
9
9
|
end
|
@@ -120,7 +120,7 @@ module Globalize
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def define_translations_accessor(name)
|
123
|
-
attribute(name, ::ActiveRecord::Type::Value.new) if
|
123
|
+
attribute(name, ::ActiveRecord::Type::Value.new) if Globalize.rails_5?
|
124
124
|
define_translations_reader(name)
|
125
125
|
define_translations_writer(name)
|
126
126
|
end
|
@@ -158,17 +158,34 @@ module Globalize
|
|
158
158
|
Globalize.fallbacks(locale)
|
159
159
|
end
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
161
|
+
if Globalize.ruby_27?
|
162
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
163
|
+
def save(...)
|
164
|
+
result = Globalize.with_locale(translation.locale || I18n.default_locale) do
|
165
|
+
without_fallbacks do
|
166
|
+
super
|
167
|
+
end
|
168
|
+
end
|
169
|
+
if result
|
170
|
+
globalize.clear_dirty
|
171
|
+
end
|
172
|
+
|
173
|
+
result
|
174
|
+
end
|
175
|
+
RUBY
|
176
|
+
else
|
177
|
+
def save(*)
|
178
|
+
result = Globalize.with_locale(translation.locale || I18n.default_locale) do
|
179
|
+
without_fallbacks do
|
180
|
+
super
|
181
|
+
end
|
182
|
+
end
|
183
|
+
if result
|
184
|
+
globalize.clear_dirty
|
165
185
|
end
|
166
|
-
end
|
167
|
-
if result
|
168
|
-
globalize.clear_dirty
|
169
|
-
end
|
170
186
|
|
171
|
-
|
187
|
+
result
|
188
|
+
end
|
172
189
|
end
|
173
190
|
|
174
191
|
def column_for_attribute name
|
@@ -185,6 +202,18 @@ module Globalize
|
|
185
202
|
changed_attributes.present? || translations.any?(&:changed?)
|
186
203
|
end
|
187
204
|
|
205
|
+
if Globalize.rails_51?
|
206
|
+
def saved_changes
|
207
|
+
super.tap do |changes|
|
208
|
+
translation = translation_for(::Globalize.locale, false)
|
209
|
+
if translation
|
210
|
+
translation_changes = translation.saved_changes.select { |name| translated?(name) }
|
211
|
+
changes.merge!(translation_changes) if translation_changes.any?
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
188
217
|
if Globalize.rails_6?
|
189
218
|
def changed_attributes
|
190
219
|
super.merge(globalize.changed_attributes(::Globalize.locale))
|
@@ -89,13 +89,27 @@ module Globalize
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
92
|
+
if Globalize.rails_6?
|
93
|
+
def add_translation_fields
|
94
|
+
connection.change_table(translations_table_name) do |t|
|
95
|
+
fields.each do |name, options|
|
96
|
+
if options.is_a? Hash
|
97
|
+
t.column name, options.delete(:type), **options
|
98
|
+
else
|
99
|
+
t.column name, options
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
else
|
105
|
+
def add_translation_fields
|
106
|
+
connection.change_table(translations_table_name) do |t|
|
107
|
+
fields.each do |name, options|
|
108
|
+
if options.is_a? Hash
|
109
|
+
t.column name, options.delete(:type), options
|
110
|
+
else
|
111
|
+
t.column name, options
|
112
|
+
end
|
99
113
|
end
|
100
114
|
end
|
101
115
|
end
|
@@ -99,7 +99,7 @@ module Globalize
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
if
|
102
|
+
if Globalize.rails_42?
|
103
103
|
def where_values_hash(*args)
|
104
104
|
return super unless respond_to?(:translations_table_name)
|
105
105
|
equalities = respond_to?(:with_default_scope) ? with_default_scope.where_values : where_values
|
data/lib/globalize/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
if ::ActiveRecord
|
1
|
+
if ::ActiveRecord.version < Gem::Version.new("5.0.0")
|
2
2
|
require_relative 'rails4/query_method'
|
3
|
-
end
|
3
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Globalize
|
2
|
+
module Validations
|
3
|
+
module UniquenessValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
klass = record.class
|
6
|
+
if klass.translates? && klass.translated?(attribute)
|
7
|
+
finder_class = klass.translation_class
|
8
|
+
relation = build_relation(finder_class, attribute, value).where(locale: Globalize.locale)
|
9
|
+
relation = relation.where.not(klass.reflect_on_association(:translations).foreign_key => record.send(:id)) if record.persisted?
|
10
|
+
|
11
|
+
|
12
|
+
translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
|
13
|
+
untranslated_scopes = Array(options[:scope]) - translated_scopes
|
14
|
+
|
15
|
+
relation = relation.joins(:globalized_model) if untranslated_scopes.present?
|
16
|
+
untranslated_scopes.each do |scope_item|
|
17
|
+
scope_value = record.send(scope_item)
|
18
|
+
reflection = klass.reflect_on_association(scope_item)
|
19
|
+
if reflection
|
20
|
+
scope_value = record.send(reflection.foreign_key)
|
21
|
+
scope_item = reflection.foreign_key
|
22
|
+
end
|
23
|
+
relation = relation.where(find_finder_class_for(record).table_name => { scope_item => scope_value })
|
24
|
+
end
|
25
|
+
|
26
|
+
translated_scopes.each do |scope_item|
|
27
|
+
scope_value = record.send(scope_item)
|
28
|
+
relation = relation.where(scope_item => scope_value)
|
29
|
+
end
|
30
|
+
relation = relation.merge(options[:conditions]) if options[:conditions]
|
31
|
+
|
32
|
+
if relation.exists?
|
33
|
+
error_options = options.except(:case_sensitive, :scope, :conditions)
|
34
|
+
error_options[:value] = value
|
35
|
+
record.errors.add(attribute, :taken, **error_options)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
super(record, attribute, value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
ActiveRecord::Validations::UniquenessValidator.prepend Globalize::Validations::UniquenessValidator
|
@@ -1,12 +1,19 @@
|
|
1
|
-
if ::ActiveRecord
|
1
|
+
if ::ActiveRecord.version >= Gem::Version.new("5.0.0")
|
2
2
|
module Globalize
|
3
3
|
module Relation
|
4
4
|
def where_values_hash(relation_table_name = table_name)
|
5
5
|
return super unless respond_to?(:translations_table_name)
|
6
6
|
super.merge(super(translations_table_name))
|
7
7
|
end
|
8
|
+
|
9
|
+
if ::ActiveRecord.version >= Gem::Version.new("6.1.3")
|
10
|
+
def scope_for_create
|
11
|
+
return super unless respond_to?(:translations_table_name)
|
12
|
+
super.merge(where_values_hash(translations_table_name))
|
13
|
+
end
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
|
11
18
|
ActiveRecord::Relation.prepend Globalize::Relation
|
12
|
-
end
|
19
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
if ::ActiveRecord
|
1
|
+
if ::ActiveRecord.version < Gem::Version.new("5.0.0")
|
2
2
|
require_relative 'rails4/uniqueness_validator'
|
3
|
-
elsif ::ActiveRecord
|
3
|
+
elsif ::ActiveRecord.version < Gem::Version.new("5.1.0")
|
4
4
|
require_relative 'rails5/uniqueness_validator'
|
5
|
-
|
5
|
+
elsif ::ActiveRecord.version < Gem::Version.new("6.1.0")
|
6
6
|
require_relative 'rails5_1/uniqueness_validator'
|
7
|
-
|
7
|
+
else
|
8
|
+
require_relative 'rails6_1/uniqueness_validator'
|
9
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
@@ -17,30 +17,30 @@ cert_chain:
|
|
17
17
|
- |
|
18
18
|
-----BEGIN CERTIFICATE-----
|
19
19
|
MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMjEwNjIzMDkyNzU2WhcNMjIwNjIzMDky
|
21
|
+
NzU2WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G
|
22
|
+
CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQD0CYnD37uLlJ3Urla2EnnUQ8S6s16k
|
23
|
+
AGMpAzpmARo8YwSqtYMJVGyBzUeI7y93Fk9ncswhIFSH/hnh/Ouat/ki9flHlZ+w
|
24
|
+
anv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xrc4BwlwlbitcvNIL
|
38
|
+
ZykdSlpTJd0Guy92iYjCJMC09tMRUNxiVBwD3jRGSeW9YAPIZGXIcVlm6srIRDjJ
|
39
|
+
o8wB6oOvHAkRXnntOo/4bBDH+ehmgvhh/O/mI+au6C0M430fv+ooH0w08LEXLx1k
|
40
|
+
e17ZNASZffbQRP09MH2GZ2AOlkildTX6looWRforZEZi+qamognrozd3MI5QHi1W
|
41
|
+
UAZUzHLrrFu7gnkFvLVpxOUf4ItOkA==
|
42
42
|
-----END CERTIFICATE-----
|
43
|
-
date: 2021-
|
43
|
+
date: 2021-06-23 00:00:00.000000000 Z
|
44
44
|
dependencies:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: activerecord
|
@@ -248,6 +248,7 @@ files:
|
|
248
248
|
- lib/patches/active_record/rails5/uniqueness_validator.rb
|
249
249
|
- lib/patches/active_record/rails5_1/serialization.rb
|
250
250
|
- lib/patches/active_record/rails5_1/uniqueness_validator.rb
|
251
|
+
- lib/patches/active_record/rails6_1/uniqueness_validator.rb
|
251
252
|
- lib/patches/active_record/relation.rb
|
252
253
|
- lib/patches/active_record/serialization.rb
|
253
254
|
- lib/patches/active_record/uniqueness_validator.rb
|
@@ -271,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
272
|
- !ruby/object:Gem::Version
|
272
273
|
version: '0'
|
273
274
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
275
|
+
rubygems_version: 3.1.6
|
275
276
|
signing_key:
|
276
277
|
specification_version: 4
|
277
278
|
summary: Rails I18n de-facto standard library for ActiveRecord model/data translation
|
metadata.gz.sig
CHANGED
Binary file
|