globalize 6.0.0 → 6.2.0
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/Appraisals +8 -12
- data/CHANGELOG.md +18 -1
- data/CONTRIBUTING.md +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +86 -0
- data/globalize.gemspec +2 -2
- data/lib/globalize/active_record/act_macro.rb +3 -2
- data/lib/globalize/active_record/class_methods.rb +16 -2
- data/lib/globalize/active_record/instance_methods.rb +39 -10
- data/lib/globalize/active_record/migration.rb +23 -7
- data/lib/globalize/active_record/translated_attributes_query.rb +1 -1
- data/lib/globalize/version.rb +1 -1
- data/lib/globalize.rb +26 -4
- 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
- data/lib/patches/active_support/inflections.rb +14 -0
- data.tar.gz.sig +0 -0
- metadata +31 -28
- 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: cabd646999269152beb8dc97eafa531bdd0627206b113c8ce7e90a17343a0369
|
4
|
+
data.tar.gz: 8fa08f217088f91bcb62e2b1667feefbc0833de0406b353890ba75568f506681
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbf148ebedffe9847a05e31053400cbe0d3e4292689704143b68ca2884a8464d4703fb6bd4ef142551b8ddd3091c650da0142a75eca871d348d9576861d855ce
|
7
|
+
data.tar.gz: a408491fb728aa2692f1ee7b71cb546ad0fc747f1f754bf779221af51b122c2442b530efc067b00fc768d56e1b80a2b09fcc0f124e2eaae7bffcca3a6af3d106
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Appraisals
CHANGED
@@ -3,9 +3,10 @@
|
|
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
|
+
7.0.0
|
9
10
|
]
|
10
11
|
|
11
12
|
RAILS_VERSIONS.each do |version|
|
@@ -13,12 +14,12 @@ RAILS_VERSIONS.each do |version|
|
|
13
14
|
gem 'activemodel', version
|
14
15
|
gem 'activerecord', version
|
15
16
|
|
16
|
-
if version =~ /^
|
17
|
-
gem 'sqlite3', '~> 1.
|
17
|
+
if version =~ /^4/
|
18
|
+
gem 'sqlite3', '~> 1.3.6', platforms: [:ruby, :rbx]
|
18
19
|
elsif version =~ /^5/
|
19
20
|
gem 'sqlite3', '~> 1.3', '>= 1.3.6', platforms: [:ruby, :rbx]
|
20
|
-
else
|
21
|
-
gem 'sqlite3', '~> 1.
|
21
|
+
else
|
22
|
+
gem 'sqlite3', '~> 1.4', platforms: [:ruby, :rbx]
|
22
23
|
end
|
23
24
|
|
24
25
|
if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
|
@@ -31,11 +32,6 @@ RAILS_VERSIONS.each do |version|
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
platforms :rbx do
|
35
|
-
gem "rubysl", "~> 2.0"
|
36
|
-
gem "rubinius-developer_tools"
|
37
|
-
end
|
38
|
-
|
39
35
|
platforms :jruby do
|
40
36
|
if !ENV['CI'] || ENV['DB'] == 'sqlite3'
|
41
37
|
gem 'activerecord-jdbcsqlite3-adapter', '~> 1'
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,28 @@
|
|
1
1
|
# Globalize Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 6.2.0 (2022-05-24)
|
4
|
+
|
5
|
+
* Fix asset precompile in docker build workflow [#799](https://github.com/globalize/globalize/pull/799) by [Diefferson Koderer Môro](https://github.com/djpremier)
|
6
|
+
|
7
|
+
## 6.1.0 (2022-02-25)
|
8
|
+
|
9
|
+
* Patch ActiveSupport in Rails 7.0.0+ [#792](https://github.com/globalize/globalize/pull/792) by [Daniel Chan](https://github.com/mynameisdaniel) and [Artis Raugulis](https://github.com/artisr)
|
10
|
+
|
11
|
+
## 6.0.1 (2021-06-23)
|
12
|
+
|
13
|
+
* 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)
|
14
|
+
* Track `saved_changes` for Rails 5.1 and above [#780](https://github.com/globalize/globalize/pull/780) by [Peter Postma](https://github.com/ppostma)
|
15
|
+
|
16
|
+
## 6.0.0 (2021-01-11)
|
4
17
|
|
5
18
|
* Add `create_source_columns` option for migrations. [#715](https://github.com/globalize/globalize/pull/715) by [IlyasValiullov](https://github.com/IlyasValiullov)
|
6
19
|
* Autosave is now configurable, but defaults to false. [#736](https://github.com/globalize/globalize/pull/736) by [James Hart](https://github.com/hjhart)
|
7
20
|
* Fix foreign keys translation. [#769](https://github.com/globalize/globalize/pull/769) by [Sergey Tokarenko](https://github.com/stokarenko)
|
8
21
|
|
22
|
+
## 5.3.1 (2021-01-11)
|
23
|
+
|
24
|
+
* Fix foreign keys translation. [#773](https://github.com/globalize/globalize/pull/773) by [Sergey Tokarenko](https://github.com/stokarenko)
|
25
|
+
|
9
26
|
## 5.3.0 (2019-05-14)
|
10
27
|
|
11
28
|
* 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/CONTRIBUTING.md
CHANGED
@@ -4,7 +4,7 @@ Globalize is a community project, and would not be here today if it were not for
|
|
4
4
|
|
5
5
|
## Bugs
|
6
6
|
|
7
|
-
If you find a bug or something is not working as expected, please search through the [github issues](https://github.com/globalize/globalize/issues) and on [stackoverflow](http://stackoverflow.com/questions/tagged/globalize) first. If you cannot find any answers related to your issue, post a new one and we will try to address it as soon as we can. Note that we prioritize Rails 4 issues (`
|
7
|
+
If you find a bug or something is not working as expected, please search through the [github issues](https://github.com/globalize/globalize/issues) and on [stackoverflow](http://stackoverflow.com/questions/tagged/globalize) first. If you cannot find any answers related to your issue, post a new one and we will try to address it as soon as we can. Note that we prioritize Rails 4 issues (`main` branch) over Rails 3 issues (`3-0-stable` branch).
|
8
8
|
|
9
9
|
If you also have some idea how to fix the bug, then by all means post a pull request (see below).
|
10
10
|
|
@@ -12,11 +12,11 @@ If you also have some idea how to fix the bug, then by all means post a pull req
|
|
12
12
|
|
13
13
|
Have an idea for a new feature? Great! Keep in mind though that we are trying to cut down on non-core functionality in the Globalize core and push it to separate extensions, such as [globalize-accessors](https://github.com/globalize/globalize-accessors). If you are proposing something like this, we would prefer you to create a separate repository and gem for it.
|
14
14
|
|
15
|
-
If however your feature would improve the core functionality of Globalize, please do submit a PR, preferably to the `
|
15
|
+
If however your feature would improve the core functionality of Globalize, please do submit a PR, preferably to the `main` branch.
|
16
16
|
|
17
17
|
## Refactoring
|
18
18
|
|
19
|
-
Have some free time? Help us improve our [code climate score](https://codeclimate.com/github/globalize/globalize) by refactoring the codebase. If the tests still pass and the changes seem reasonable, we will happily merge them. As elsewhere, priority always goes to the Rails/AR 4 series (`
|
19
|
+
Have some free time? Help us improve our [code climate score](https://codeclimate.com/github/globalize/globalize) by refactoring the codebase. If the tests still pass and the changes seem reasonable, we will happily merge them. As elsewhere, priority always goes to the Rails/AR 4 series (`main` branch).
|
20
20
|
|
21
21
|
## Documentation
|
22
22
|
|
@@ -32,7 +32,7 @@ Have a bug fix, code improvement or proposed feature? Do the following:
|
|
32
32
|
4. Push to the branch: `git push origin my_new_feature`
|
33
33
|
5. Submit a pull request.
|
34
34
|
|
35
|
-
For pull requests to Rails/ActiveRecord 4 version of Globalize (v3.x), post to the `
|
35
|
+
For pull requests to Rails/ActiveRecord 4 version of Globalize (v3.x), post to the `main` branch. For pull requests to the Rails/ActiveRecord 3.x version of Globalize (3.x), post to the `3-0-stable` branch.
|
36
36
|
|
37
37
|
When you submit the pull request, GitHub Actions will run the [test suite](https://github.com/globalize/globalize/actions) against your branch and will highlight any failures. Unless there is a good reason for it, we do not generally accept pull requests that take Globalize from green to red.
|
38
38
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
globalize (6.2.0)
|
5
|
+
activemodel (>= 4.2, < 7.1)
|
6
|
+
activerecord (>= 4.2, < 7.1)
|
7
|
+
request_store (~> 1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (7.0.3)
|
13
|
+
activesupport (= 7.0.3)
|
14
|
+
activerecord (7.0.3)
|
15
|
+
activemodel (= 7.0.3)
|
16
|
+
activesupport (= 7.0.3)
|
17
|
+
activesupport (7.0.3)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 1.6, < 2)
|
20
|
+
minitest (>= 5.1)
|
21
|
+
tzinfo (~> 2.0)
|
22
|
+
ansi (1.5.0)
|
23
|
+
appraisal (2.4.1)
|
24
|
+
bundler
|
25
|
+
rake
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
builder (3.2.4)
|
28
|
+
coderay (1.1.3)
|
29
|
+
concurrent-ruby (1.1.10)
|
30
|
+
database_cleaner (2.0.1)
|
31
|
+
database_cleaner-active_record (~> 2.0.0)
|
32
|
+
database_cleaner-active_record (2.0.1)
|
33
|
+
activerecord (>= 5.a)
|
34
|
+
database_cleaner-core (~> 2.0.0)
|
35
|
+
database_cleaner-core (2.0.1)
|
36
|
+
i18n (1.10.0)
|
37
|
+
concurrent-ruby (~> 1.0)
|
38
|
+
m (1.6.0)
|
39
|
+
method_source (>= 0.6.7)
|
40
|
+
rake (>= 0.9.2.2)
|
41
|
+
method_source (1.0.0)
|
42
|
+
minitest (5.15.0)
|
43
|
+
minitest-reporters (1.5.0)
|
44
|
+
ansi
|
45
|
+
builder
|
46
|
+
minitest (>= 5.0)
|
47
|
+
ruby-progressbar
|
48
|
+
mysql2 (0.5.4)
|
49
|
+
pg (1.3.5)
|
50
|
+
pry (0.14.1)
|
51
|
+
coderay (~> 1.1)
|
52
|
+
method_source (~> 1.0)
|
53
|
+
psych (4.0.4)
|
54
|
+
stringio
|
55
|
+
rack (2.2.3)
|
56
|
+
rake (13.0.6)
|
57
|
+
rdoc (6.4.0)
|
58
|
+
psych (>= 4.0.0)
|
59
|
+
request_store (1.5.1)
|
60
|
+
rack (>= 1.4)
|
61
|
+
ruby-progressbar (1.11.0)
|
62
|
+
sqlite3 (1.4.2)
|
63
|
+
stringio (3.0.2)
|
64
|
+
thor (1.2.1)
|
65
|
+
tzinfo (2.0.4)
|
66
|
+
concurrent-ruby (~> 1.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
arm64-darwin-21
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
appraisal
|
73
|
+
database_cleaner
|
74
|
+
globalize!
|
75
|
+
m
|
76
|
+
minitest
|
77
|
+
minitest-reporters
|
78
|
+
mysql2
|
79
|
+
pg
|
80
|
+
pry
|
81
|
+
rake
|
82
|
+
rdoc
|
83
|
+
sqlite3
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
2.3.13
|
data/globalize.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_path = 'lib'
|
18
18
|
s.required_ruby_version = '>= 2.4.6'
|
19
19
|
|
20
|
-
s.add_dependency 'activerecord', '>= 4.2', '< 7.
|
21
|
-
s.add_dependency 'activemodel', '>= 4.2', '< 7.
|
20
|
+
s.add_dependency 'activerecord', '>= 4.2', '< 7.1'
|
21
|
+
s.add_dependency 'activemodel', '>= 4.2', '< 7.1'
|
22
22
|
s.add_dependency 'request_store', '~> 1.0'
|
23
23
|
|
24
24
|
s.add_development_dependency 'appraisal'
|
@@ -41,7 +41,7 @@ module Globalize
|
|
41
41
|
end
|
42
42
|
|
43
43
|
begin
|
44
|
-
if
|
44
|
+
if Globalize.rails_5? && database_connection_possible?
|
45
45
|
self.ignored_columns += translated_attribute_names.map(&:to_s)
|
46
46
|
reset_column_information
|
47
47
|
end
|
@@ -52,7 +52,8 @@ 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? && database_connection_possible?
|
56
|
+
|
56
57
|
if (overlap = attr_names.map(&:to_s) & column_names).present?
|
57
58
|
ActiveSupport::Deprecation.warn(
|
58
59
|
["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,10 +120,24 @@ 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
|
127
|
+
|
128
|
+
def database_connection_possible?
|
129
|
+
begin
|
130
|
+
# Without a connection tentative, the `connected?` function can responds with a false negative
|
131
|
+
::ActiveRecord::Base.connection
|
132
|
+
rescue
|
133
|
+
# Ignore connection fail because in docker build hasn't a database connection
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
|
137
|
+
::ActiveRecord::Base.connected? &&
|
138
|
+
table_exists? &&
|
139
|
+
translation_class.table_exists?
|
140
|
+
end
|
127
141
|
end
|
128
142
|
end
|
129
143
|
end
|
@@ -21,7 +21,7 @@ module Globalize
|
|
21
21
|
|
22
22
|
# In Rails 5.2 we need to override *_assign_attributes* as it's called earlier
|
23
23
|
# in the stack (before *assign_attributes*)
|
24
|
-
# See https://github.com/rails/rails/blob/
|
24
|
+
# See https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/attribute_assignment.rb#L12
|
25
25
|
def _assign_attributes(new_attributes)
|
26
26
|
attributes = new_attributes.stringify_keys
|
27
27
|
with_given_locale(attributes) { super(attributes.except("locale")) }
|
@@ -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
|
@@ -155,6 +169,8 @@ module Globalize
|
|
155
169
|
# Create a hash containing the translated column names and their values.
|
156
170
|
translated_attribute_names.inject(fields_to_update={}) do |f, name|
|
157
171
|
f.update({name.to_sym => translated_record[name.to_s]})
|
172
|
+
# Remove attributes that will no longer be translated
|
173
|
+
translated_attribute_names.delete(name)
|
158
174
|
end
|
159
175
|
|
160
176
|
# Now, update the actual model's record with the hash.
|
@@ -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
data/lib/globalize.rb
CHANGED
@@ -6,11 +6,21 @@ require 'patches/active_record/relation'
|
|
6
6
|
require 'patches/active_record/serialization'
|
7
7
|
require 'patches/active_record/uniqueness_validator'
|
8
8
|
require 'patches/active_record/persistence'
|
9
|
+
require 'patches/active_support/inflections'
|
9
10
|
|
10
11
|
module Globalize
|
11
12
|
autoload :ActiveRecord, 'globalize/active_record'
|
12
13
|
autoload :Interpolation, 'globalize/interpolation'
|
13
14
|
|
15
|
+
ACTIVE_RECORD_50 = Gem::Version.new('5.0.0')
|
16
|
+
ACTIVE_RECORD_51 = Gem::Version.new('5.1.0')
|
17
|
+
ACTIVE_RECORD_52 = Gem::Version.new('5.2.0')
|
18
|
+
ACTIVE_RECORD_60 = Gem::Version.new('6.0.0')
|
19
|
+
ACTIVE_RECORD_61 = Gem::Version.new('6.1.0')
|
20
|
+
|
21
|
+
CURRENT_RUBY = Gem::Version.new(RUBY_VERSION)
|
22
|
+
RUBY_VERSION_27 = Gem::Version.new('2.7.0')
|
23
|
+
|
14
24
|
class << self
|
15
25
|
def locale
|
16
26
|
read_locale || I18n.locale
|
@@ -58,20 +68,32 @@ module Globalize
|
|
58
68
|
RequestStore.store
|
59
69
|
end
|
60
70
|
|
71
|
+
def ruby_27?
|
72
|
+
CURRENT_RUBY >= RUBY_VERSION_27
|
73
|
+
end
|
74
|
+
|
75
|
+
def rails_42?
|
76
|
+
::ActiveRecord.version < ACTIVE_RECORD_50
|
77
|
+
end
|
78
|
+
|
61
79
|
def rails_5?
|
62
|
-
::ActiveRecord.version >=
|
80
|
+
::ActiveRecord.version >= ACTIVE_RECORD_50
|
81
|
+
end
|
82
|
+
|
83
|
+
def rails_51?
|
84
|
+
::ActiveRecord.version >= ACTIVE_RECORD_51
|
63
85
|
end
|
64
86
|
|
65
87
|
def rails_52?
|
66
|
-
::ActiveRecord.version >=
|
88
|
+
::ActiveRecord.version >= ACTIVE_RECORD_52
|
67
89
|
end
|
68
90
|
|
69
91
|
def rails_6?
|
70
|
-
::ActiveRecord.version >=
|
92
|
+
::ActiveRecord.version >= ACTIVE_RECORD_60
|
71
93
|
end
|
72
94
|
|
73
95
|
def rails_61?
|
74
|
-
::ActiveRecord.version >=
|
96
|
+
::ActiveRecord.version >= ACTIVE_RECORD_61
|
75
97
|
end
|
76
98
|
|
77
99
|
protected
|
@@ -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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
if ::ActiveSupport.version >= Gem::Version.new("7.0.0")
|
2
|
+
module Globalize
|
3
|
+
module Inflections
|
4
|
+
def instance_or_fallback(locale)
|
5
|
+
I18n.respond_to?(:fallbacks) && I18n.fallbacks[locale].each do |k|
|
6
|
+
return @__instance__[k] if @__instance__.key?(k)
|
7
|
+
end
|
8
|
+
instance(locale)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveSupport::Inflector::Inflections.singleton_class.send :prepend, Globalize::Inflections
|
14
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
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.
|
4
|
+
version: 6.2.0
|
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
|
+
anv0M+9v3wCLyZSC5BQIWpoduFM/fuvLoDUJDWxL50RjwMS0qo2x2LvfQdHN8gn3
|
25
|
+
JdSIV5WLJKIvlmIl9S3pw0JO5KRUGn1PcBO7C0S0SlbhVjRHtlao1ycWUULsX109
|
26
|
+
hCh39MPGtnZpdCcxheh0TH/UA/jV0/du9/rQdoidkNHkaC24pPfBJ3nS+rAbWaHP
|
27
|
+
WmP+0rjfk/XnGBu/HZpKvlnwQjP3QdK4UMtWl8zewqFMNcIiBRALQugnL/SfrP/4
|
28
|
+
CSlha9LwkiE6ByeY4WGnNjNqpi5J3IzjEkZRAxG7u9gCB3FzTaBTyXZYI6jplYNw
|
29
|
+
TcCJIBHuoPaa+m9brpjb3Uv94nfM97ZP+OmpGYCCAMq4TT7OOV+t8wJc0w8bb0FO
|
30
|
+
ROhmVNTxrBaNcl6MkZn88EMRCsGgoWklOG0CAwEAAaNxMG8wCQYDVR0TBAIwADAL
|
31
|
+
BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu7pbmeILyHnBmannuaNRfdN8MsMBoGA1Ud
|
32
32
|
EQQTMBGBD2dlbXNAcC5hcm5kdC5pbzAaBgNVHRIEEzARgQ9nZW1zQHAuYXJuZHQu
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
aW8wDQYJKoZIhvcNAQELBQADggGBANlxc4uAnkPC3zbztG7uZfBfn4HSuvv655Pa
|
34
|
+
UaYZ6hNETFrqg78mGs3PkFe2Ru7cVWwckbmH46aq50QoNnx4ClxT03vr03n76Jg1
|
35
|
+
8WWHkf0+rcINFlbtIFcmcFrois5Ow3n7pH+xstDtzoWcbh41WwuZStNhrIYsnjAK
|
36
|
+
/ovz8D5JlboxceOpVLB/0NiqNEWltK+EMQHmX25Sqf/r5o5rAL9zwEKPFp1Y5X+z
|
37
|
+
t2jBjYt2ymr1eMWxux6e+N2uKZL4MblHawxvKlI8UHsIiV9xrc4BwlwlbitcvNIL
|
38
|
+
ZykdSlpTJd0Guy92iYjCJMC09tMRUNxiVBwD3jRGSeW9YAPIZGXIcVlm6srIRDjJ
|
39
|
+
o8wB6oOvHAkRXnntOo/4bBDH+ehmgvhh/O/mI+au6C0M430fv+ooH0w08LEXLx1k
|
40
|
+
e17ZNASZffbQRP09MH2GZ2AOlkildTX6looWRforZEZi+qamognrozd3MI5QHi1W
|
41
|
+
UAZUzHLrrFu7gnkFvLVpxOUf4ItOkA==
|
42
42
|
-----END CERTIFICATE-----
|
43
|
-
date:
|
43
|
+
date: 2022-05-24 00:00:00.000000000 Z
|
44
44
|
dependencies:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: activerecord
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
version: '4.2'
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '7.
|
54
|
+
version: '7.1'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -61,7 +61,7 @@ dependencies:
|
|
61
61
|
version: '4.2'
|
62
62
|
- - "<"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '7.
|
64
|
+
version: '7.1'
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
name: activemodel
|
67
67
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
version: '4.2'
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '7.
|
74
|
+
version: '7.1'
|
75
75
|
type: :runtime
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
version: '4.2'
|
82
82
|
- - "<"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '7.
|
84
|
+
version: '7.1'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: request_store
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- CHANGELOG.md
|
219
219
|
- CONTRIBUTING.md
|
220
220
|
- Gemfile
|
221
|
+
- Gemfile.lock
|
221
222
|
- LICENSE
|
222
223
|
- README.md
|
223
224
|
- Rakefile
|
@@ -248,10 +249,12 @@ files:
|
|
248
249
|
- lib/patches/active_record/rails5/uniqueness_validator.rb
|
249
250
|
- lib/patches/active_record/rails5_1/serialization.rb
|
250
251
|
- lib/patches/active_record/rails5_1/uniqueness_validator.rb
|
252
|
+
- lib/patches/active_record/rails6_1/uniqueness_validator.rb
|
251
253
|
- lib/patches/active_record/relation.rb
|
252
254
|
- lib/patches/active_record/serialization.rb
|
253
255
|
- lib/patches/active_record/uniqueness_validator.rb
|
254
256
|
- lib/patches/active_record/xml_attribute_serializer.rb
|
257
|
+
- lib/patches/active_support/inflections.rb
|
255
258
|
homepage: http://github.com/globalize/globalize
|
256
259
|
licenses:
|
257
260
|
- MIT
|
@@ -271,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
274
|
- !ruby/object:Gem::Version
|
272
275
|
version: '0'
|
273
276
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.3.7
|
275
278
|
signing_key:
|
276
279
|
specification_version: 4
|
277
280
|
summary: Rails I18n de-facto standard library for ActiveRecord model/data translation
|
metadata.gz.sig
CHANGED
Binary file
|