globalize 5.2.0 → 6.0.1

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: 18d470a9030a9901a83b9d3c48080661b10000a20049f598eece0b41727d66dc
4
- data.tar.gz: b1ea4e1d1c0210271fede3bf8d7903ac658ace1af1742bf29980139efc555673
3
+ metadata.gz: 232c58a035dbc34d1e513c552d3d0a52a7b349c414fb8c8126c74bfa94831e5e
4
+ data.tar.gz: d25bd58906d809849ba3ef3ed393e80c599bab47e2115c25ff9f75e11d1a4c7c
5
5
  SHA512:
6
- metadata.gz: 70eaedf3edada661ab9495f31ec46544cc950ba4c6ff667c9d6e1bf699cd770de02ffab2783ba29735c39d35d6b92c9ab2b0f8061185a3e1f3469354f82e560a
7
- data.tar.gz: 1b255c9f3164165e76650a4b0fbbfbc989f87ec524a9c4bb1e70ea8fd54b3f16811a9c5a42cfe8f38df0d47ca00fd2632a95f0918c58bdb2e24b5c313b5d2508
6
+ metadata.gz: 5c8d6cb1111dddd8f36e3baf3ec053a4db7f1b76b302694a631e41dcb849506d351dd5c5562e513e864912a129b030ae5cf6a0c6378460e534812a65651a60ea
7
+ data.tar.gz: 43bafaeac8081685600f7201fb88ae5d2c4195ac0c5d40595d78d846deb578f6255c42c55a8b68aafc18dc76a32c0ac370330ecfc1ae3bc6a0379415edb65309
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/Appraisals CHANGED
@@ -1,31 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RAILS_VERSIONS = %w[
4
- 4.2.10
5
- 5.1.6
6
- 5.2.1
4
+ 4.2.11.3
5
+ 5.1.7
6
+ 5.2.5
7
+ 6.0.3.6
8
+ 6.1.3.1
7
9
  ]
8
10
 
9
11
  RAILS_VERSIONS.each do |version|
10
12
  appraise "rails_#{version}" do
11
13
  gem 'activemodel', version
12
14
  gem 'activerecord', version
15
+
16
+ if version =~ /^6/
17
+ gem 'sqlite3', '~> 1.4', platforms: [:ruby, :rbx]
18
+ elsif version =~ /^5/
19
+ gem 'sqlite3', '~> 1.3', '>= 1.3.6', platforms: [:ruby, :rbx]
20
+ else version =~ /^4/
21
+ gem 'sqlite3', '~> 1.3.6', platforms: [:ruby, :rbx]
22
+ end
13
23
 
14
- platforms :rbx do
15
- gem "rubysl", "~> 2.0"
16
- gem "rubinius-developer_tools"
24
+ if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
25
+ group :postgres, :postgresql do
26
+ if version =~ /^4/
27
+ gem 'pg', '< 1.0', platforms: [:ruby, :rbx]
28
+ else
29
+ gem 'pg', '~> 1.1', platforms: [:ruby, :rbx]
30
+ end
31
+ end
17
32
  end
18
33
 
19
34
  platforms :jruby do
20
- if !ENV['TRAVIS'] || ENV['DB'] == 'sqlite3'
35
+ if !ENV['CI'] || ENV['DB'] == 'sqlite3'
21
36
  gem 'activerecord-jdbcsqlite3-adapter', '~> 1'
22
37
  end
23
38
 
24
- if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
39
+ if !ENV['CI'] || ENV['DB'] == 'mysql'
25
40
  gem 'activerecord-jdbcmysql-adapter', '~> 1'
26
41
  end
27
42
 
28
- if !ENV['TRAVIS'] || %w(postgres postgresql).include?(ENV['DB'])
43
+ if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
29
44
  gem 'activerecord-jdbcpostgresql-adapter', '~> 1'
30
45
  end
31
46
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Globalize Changelog
2
2
 
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)
9
+
10
+ * Add `create_source_columns` option for migrations. [#715](https://github.com/globalize/globalize/pull/715) by [IlyasValiullov](https://github.com/IlyasValiullov)
11
+ * Autosave is now configurable, but defaults to false. [#736](https://github.com/globalize/globalize/pull/736) by [James Hart](https://github.com/hjhart)
12
+ * Fix foreign keys translation. [#769](https://github.com/globalize/globalize/pull/769) by [Sergey Tokarenko](https://github.com/stokarenko)
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
+
18
+ ## 5.3.0 (2019-05-14)
19
+
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)
21
+ * Pass the `:limit` option for the FK column. [#721](https://github.com/globalize/globalize/pull/721) by [Denis Demchenko](https://github.com/lancedikson)
22
+ * Add support for Rails 6.0. [#718](https://github.com/globalize/globalize/pull/718) by [Chrıs Seelus](https://github.com/cseelus)
23
+ * FIX: stop registering the attr for Rails 4.2. [#711](https://github.com/globalize/globalize/pull/711) by [Adam Fernung](https://github.com/akfernun)
24
+
25
+ ## 5.2.0 (2018-11-02)
26
+
27
+ * Add support for translated attributes to other QueryMethods and Calculations [#707](https://github.com/globalize/globalize/pull/707) by [kreintjes](https://github.com/kreintjes)
28
+ * Fix `read_attribute` for Rails changes. [#709](https://github.com/globalize/globalize/pull/709) by [ota42y](https://github.com/ota42y) and [nabuchi](https://github.com/nabuchi)
29
+ * Support array as an argument of order. [#675](https://github.com/globalize/globalize/pull/675) by [Maicol Bentancor](https://github.com/MaicolBen)
30
+ * `_reset_attribute` bugfix. [#674](https://github.com/globalize/globalize/pull/674) by [ota42y](https://github.com/ota42y)
31
+ * Add support for Rails 5.2 [#678](https://github.com/globalize/globalize/pull/678) by [kevin-jj](https://github.com/kevin-jj)
32
+ * Fix: wrong number of arguments for ActiveRecord 'attribute' method [#671](https://github.com/globalize/globalize/pull/671) by [Evgeny Danilov](https://github.com/jmelkor)
33
+ * Resolve deprecation warning: attribute is not an attribute known to Active Record. [#629](https://github.com/globalize/globalize/pull/629) by [Michael Rüffer](https://github.com/itschn)
34
+
3
35
  ## 5.1.0 (2018-01-15)
4
36
 
5
37
  * Replaced `after_` callbacks with `before_` callbacks and set `autosave: true` by default. [#341](https://github.com/globalize/globalize/pull/341) by [Andrew Volozhanin](https://github.com/scarfacedeb)
data/CONTRIBUTING.md CHANGED
@@ -34,7 +34,7 @@ Have a bug fix, code improvement or proposed feature? Do the following:
34
34
 
35
35
  For pull requests to Rails/ActiveRecord 4 version of Globalize (v3.x), post to the `master` 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
- When you submit the pull request, Travis CI will run the [test suite](https://travis-ci.org/globalize/globalize) 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.
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
 
39
39
  ## Testing
40
40
 
data/Gemfile CHANGED
@@ -1,3 +1,20 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ # Database Configuration
6
+ if !ENV['CI'] || ENV['DB'] == 'sqlite3'
7
+ gem 'sqlite3', platforms: [:ruby, :rbx]
8
+ end
9
+
10
+ if !ENV['CI'] || ENV['DB'] == 'mysql'
11
+ group :mysql do
12
+ gem 'mysql2', platforms: [:ruby, :rbx]
13
+ end
14
+ end
15
+
16
+ if !ENV['CI'] || %w(postgres postgresql).include?(ENV['DB'])
17
+ group :postgres, :postgresql do
18
+ gem 'pg', platforms: [:ruby, :rbx]
19
+ end
20
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![Globalize](http://globalize.github.io/globalize/images/globalize.png)
2
2
 
3
- [![Build Status](https://travis-ci.org/globalize/globalize.svg?branch=master)](https://travis-ci.org/globalize/globalize) [![Code Climate](https://codeclimate.com/github/globalize/globalize.svg)](https://codeclimate.com/github/globalize/globalize)
3
+ [![Build Status](https://github.com/globalize/globalize/workflows/CI/badge.svg)](https://github.com/globalize/globalize/actions) [![Code Climate](https://codeclimate.com/github/globalize/globalize.svg)](https://codeclimate.com/github/globalize/globalize)
4
4
  [![Open Source Helpers](https://www.codetriage.com/globalize/globalize/badges/users.svg)](https://www.codetriage.com/globalize/globalize)
5
5
 
6
6
  You can chat with us using Gitter:
@@ -12,6 +12,11 @@ to add model translations to ActiveRecord models.
12
12
 
13
13
  In other words, a way to translate actual user-generated content, for example; a single blog post with multiple translations.
14
14
 
15
+ ## Current state of the gem
16
+
17
+ Globalize is not very actively maintained. Pull Requests are welcome, especially for compatibility with new versions of Rails, but none of the maintainers actively use Globalize anymore. If you need a more actively maintained model translation gem, we recommend checking out [Mobility](https://github.com/shioyama/mobility), a natural successor of Globalize created by Chris Salzberg (one of Globalize maintainers) and inspired by the ideas discussed around Globalize. For a more up-to-date discussion of the current situation, see [issue #753](https://github.com/globalize/globalize/issues/753).
18
+
19
+
15
20
  ## Requirements
16
21
 
17
22
  * ActiveRecord >= 4.2.0 (see below for installation with ActiveRecord 3.x)
@@ -28,7 +33,7 @@ gem install globalize
28
33
  When using bundler put this in your Gemfile:
29
34
 
30
35
  ```ruby
31
- gem 'globalize', '~> 5.1.0'
36
+ gem 'globalize', '~> 5.3.0'
32
37
  ```
33
38
 
34
39
  Please help us by letting us know what works, and what doesn't, when using pre-release code.
@@ -271,6 +276,9 @@ You can enable them by adding the next line to `config/application.rb` (or only
271
276
  `config/environments/production.rb` if you only want them in production)
272
277
 
273
278
  ```ruby
279
+ # For version 1.1.0 and above of the `i18n` gem:
280
+ config.i18n.fallbacks = [I18n.default_locale]
281
+ # Below version 1.1.0 of the `i18n` gem:
274
282
  config.i18n.fallbacks = true
275
283
  ```
276
284
 
@@ -0,0 +1,22 @@
1
+ version: '3.7'
2
+ services:
3
+ postgres:
4
+ image: postgres:11
5
+ volumes:
6
+ - ./tmp/postgres:/var/lib/postgresql/data
7
+ ports:
8
+ - "5432:5432"
9
+ environment:
10
+ POSTGRES_USER: "postgres"
11
+ POSTGRES_PASSWORD: ""
12
+ mysql:
13
+ image: mysql:8.0
14
+ volumes:
15
+ - ./tmp/mysql:/var/lib/mysql
16
+ ports:
17
+ - "3306:3306"
18
+ environment:
19
+ MYSQL_USER: "root"
20
+ MYSQL_PASSWORD: ""
21
+ MYSQL_ROOT_PASSWORD: ""
22
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
data/globalize.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/globalize/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'globalize'
7
+ s.version = Globalize::Version
8
+ s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Clemens Kofler', 'John-Paul Bader', 'Tomasz Stachewicz', 'Philip Arndt', 'Chris Salzberg']
9
+ s.email = 'nobody@globalize-rails.org'
10
+ s.homepage = 'http://github.com/globalize/globalize'
11
+ s.summary = 'Rails I18n de-facto standard library for ActiveRecord model/data translation'
12
+ s.description = "#{s.summary}."
13
+ s.license = "MIT"
14
+
15
+ s.files = Dir['{lib/**/*,[A-Z]*}']
16
+ s.platform = Gem::Platform::RUBY
17
+ s.require_path = 'lib'
18
+ s.required_ruby_version = '>= 2.4.6'
19
+
20
+ s.add_dependency 'activerecord', '>= 4.2', '< 7.0'
21
+ s.add_dependency 'activemodel', '>= 4.2', '< 7.0'
22
+ s.add_dependency 'request_store', '~> 1.0'
23
+
24
+ s.add_development_dependency 'appraisal'
25
+ s.add_development_dependency 'database_cleaner'
26
+ s.add_development_dependency 'm'
27
+ s.add_development_dependency 'minitest'
28
+ s.add_development_dependency 'minitest-reporters'
29
+ s.add_development_dependency 'pry'
30
+ s.add_development_dependency 'rake'
31
+ s.add_development_dependency 'rdoc'
32
+
33
+ s.cert_chain = [File.expand_path('certs/parndt.pem', __dir__)]
34
+ if $PROGRAM_NAME =~ /gem\z/ && ARGV.include?('build') && ARGV.include?(__FILE__)
35
+ s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
36
+ end
37
+ end
data/issue_template.rb ADDED
@@ -0,0 +1,38 @@
1
+ # Activate the gem you are reporting the issue against.
2
+ gem 'activerecord', '4.2.0'
3
+ gem 'globalize', '5.0.1'
4
+ require 'active_record'
5
+ require 'globalize'
6
+ require 'minitest/autorun'
7
+ require 'logger'
8
+
9
+ # Ensure backward compatibility with Minitest 4
10
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
11
+
12
+ # This connection will do for database-independent bug reports.
13
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
14
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
15
+
16
+ ActiveRecord::Schema.define do
17
+ create_table :posts, force: true do |t|
18
+ end
19
+
20
+ create_table :post_translations, force: true do |t|
21
+ t.references :post
22
+ t.string :title
23
+ t.text :content
24
+ t.string :locale
25
+ end
26
+ end
27
+
28
+ class Post < ActiveRecord::Base
29
+ translates :content, :title
30
+ end
31
+
32
+ class BugTest < Minitest::Test
33
+ def test_association_stuff
34
+ post = Post.create!(title: 'HI')
35
+
36
+ assert_equal 'HI', post.title
37
+ end
38
+ end
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,12 +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 >= Gem::Version.new('5.1.0')
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 >= Gem::Version.new('5.2.0')
87
+ ::ActiveRecord.version >= ACTIVE_RECORD_52
88
+ end
89
+
90
+ def rails_6?
91
+ ::ActiveRecord.version >= ACTIVE_RECORD_60
92
+ end
93
+
94
+ def rails_61?
95
+ ::ActiveRecord.version >= ACTIVE_RECORD_61
67
96
  end
68
97
 
69
98
  protected
@@ -41,7 +41,7 @@ module Globalize
41
41
  end
42
42
 
43
43
  begin
44
- if ::ActiveRecord::VERSION::STRING > "5.0" && table_exists? && translation_class.table_exists?
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 ::ActiveRecord::VERSION::STRING < "5.0" && table_exists? && translation_class.table_exists?
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. ",
@@ -68,6 +68,7 @@ module Globalize
68
68
  def apply_globalize_options(options)
69
69
  options[:table_name] ||= "#{table_name.singularize}_translations"
70
70
  options[:foreign_key] ||= class_name.foreign_key
71
+ options[:autosave] ||= false
71
72
 
72
73
  class_attribute :translated_attribute_names, :translation_options, :fallbacks_for_empty_translations
73
74
  self.translated_attribute_names = []
@@ -99,7 +100,7 @@ module Globalize
99
100
  :foreign_key => options[:foreign_key],
100
101
  :dependent => :destroy,
101
102
  :extend => HasManyExtensions,
102
- :autosave => false,
103
+ :autosave => options[:autosave],
103
104
  :inverse_of => :globalized_model
104
105
 
105
106
  after_create :save_translations!
@@ -41,9 +41,17 @@ module Globalize
41
41
  self.dirty = {}
42
42
  end
43
43
 
44
- def _reset_attribute name
45
- record.send("#{name}=", record.changed_attributes[name])
46
- record.send(:clear_attribute_changes, [name])
44
+ if Globalize.rails_6?
45
+ def _reset_attribute name
46
+ record.send(:clear_attribute_changes, [name])
47
+ end
48
+ else
49
+ def _reset_attribute name
50
+ original_value = record.changed_attributes[name]
51
+ record.send(:clear_attribute_changes, [name])
52
+ record.send("#{name}=", original_value)
53
+ record.send(:clear_attribute_changes, [name])
54
+ end
47
55
  end
48
56
 
49
57
  def reset
@@ -51,6 +59,30 @@ module Globalize
51
59
  super
52
60
  end
53
61
 
62
+ def changed_attributes(locale)
63
+ Hash[changes(locale).map { |name, change| [name, change.first] }]
64
+ end
65
+
66
+ def changed
67
+ stash.keys.flat_map { |locale| changes(locale).keys }.uniq
68
+ end
69
+
70
+ def changes(locale)
71
+ stash[locale].keys.inject({}) do |hash, name|
72
+ next hash unless dirty[name].is_a?(Hash)
73
+ next hash unless dirty[name].key?(locale)
74
+
75
+ new_value = stash[locale][name]
76
+ old_value = dirty[name][locale]
77
+
78
+ unless new_value == old_value
79
+ hash[name] = [old_value, new_value]
80
+ end
81
+
82
+ hash
83
+ end
84
+ end
85
+
54
86
  end
55
87
  end
56
88
  end
@@ -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 ::ActiveRecord::VERSION::STRING < "5.0.0"
6
+ if Globalize.rails_42?
7
7
  def columns_hash
8
8
  super.except(*translated_attribute_names.map(&:to_s))
9
9
  end
@@ -98,7 +98,6 @@ module Globalize
98
98
  end
99
99
 
100
100
  def define_translated_attr_accessor(name)
101
- attribute(name, ::ActiveRecord::Type::Value.new)
102
101
  define_translated_attr_reader(name)
103
102
  define_translated_attr_writer(name)
104
103
  end
@@ -121,6 +120,7 @@ module Globalize
121
120
  end
122
121
 
123
122
  def define_translations_accessor(name)
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
@@ -66,7 +66,7 @@ module Globalize
66
66
  end
67
67
 
68
68
  def _read_attribute(attr_name, options = {}, &block)
69
- translated_value = read_translated_attribute(attr_name, options, &block)
69
+ translated_value = read_translated_attribute(attr_name, options)
70
70
  translated_value.nil? ? super(attr_name, &block) : translated_value
71
71
  end
72
72
 
@@ -158,17 +158,34 @@ module Globalize
158
158
  Globalize.fallbacks(locale)
159
159
  end
160
160
 
161
- def save(*)
162
- result = Globalize.with_locale(translation.locale || I18n.default_locale) do
163
- without_fallbacks do
164
- super
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
- result
187
+ result
188
+ end
172
189
  end
173
190
 
174
191
  def column_for_attribute name
@@ -185,6 +202,32 @@ 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
+
217
+ if Globalize.rails_6?
218
+ def changed_attributes
219
+ super.merge(globalize.changed_attributes(::Globalize.locale))
220
+ end
221
+
222
+ def changes
223
+ super.merge(globalize.changes(::Globalize.locale))
224
+ end
225
+
226
+ def changed
227
+ super.concat(globalize.changed).uniq
228
+ end
229
+ end
230
+
188
231
  # need to access instance variable directly since changed_attributes
189
232
  # is frozen as of Rails 4.2
190
233
  def original_changed_attributes
@@ -236,10 +279,7 @@ module Globalize
236
279
  return nil unless options[:translated]
237
280
  return nil unless translated?(name)
238
281
 
239
- value = globalize.fetch(options[:locale] || Globalize.locale, name)
240
- return nil if value.nil?
241
-
242
- block_given? ? yield(value) : value
282
+ globalize.fetch(options[:locale] || Globalize.locale, name)
243
283
  end
244
284
  end
245
285
  end
@@ -62,6 +62,7 @@ module Globalize
62
62
  end
63
63
 
64
64
  def drop_translation_table!(options = {})
65
+ add_missing_columns if options[:create_source_columns]
65
66
  move_data_to_model_table if options[:migrate_data]
66
67
  drop_translations_index
67
68
  drop_translation_table
@@ -78,19 +79,37 @@ module Globalize
78
79
 
79
80
  def create_translation_table
80
81
  connection.create_table(translations_table_name) do |t|
81
- t.references table_name.sub(/^#{table_name_prefix}/, '').singularize, :null => false, :index => false, :type => column_type(model.primary_key).to_sym
82
+ t.references table_name.sub(/^#{table_name_prefix}/, '').singularize,
83
+ :null => false,
84
+ :index => false,
85
+ :type => column_type(model.primary_key).try(:to_sym),
86
+ :limit => model.columns.detect { |c| c.name == model.primary_key }.try(:limit)
82
87
  t.string :locale, :null => false
83
88
  t.timestamps :null => false
84
89
  end
85
90
  end
86
91
 
87
- def add_translation_fields
88
- connection.change_table(translations_table_name) do |t|
89
- fields.each do |name, options|
90
- if options.is_a? Hash
91
- t.column name, options.delete(:type), options
92
- else
93
- t.column name, options
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
94
113
  end
95
114
  end
96
115
  end
@@ -144,8 +163,6 @@ module Globalize
144
163
  end
145
164
 
146
165
  def move_data_to_model_table
147
- add_missing_columns
148
-
149
166
  # Find all of the translated attributes for all records in the model.
150
167
  all_translated_attributes = model.all.collect{|m| m.attributes}
151
168
  all_translated_attributes.each do |translated_record|
@@ -99,7 +99,7 @@ module Globalize
99
99
  end
100
100
  end
101
101
 
102
- if ::ActiveRecord::VERSION::STRING < "5.0.0"
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Globalize
2
- Version = '5.2.0'
4
+ Version = '6.0.1'
3
5
  end
@@ -1,3 +1,3 @@
1
- if ::ActiveRecord::VERSION::STRING < "5.0.0"
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::VERSION::STRING >= "5.0.0"
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,5 +1,5 @@
1
- if ::ActiveRecord::VERSION::STRING < "5.1.0"
1
+ if ::ActiveRecord.version < Gem::Version.new("5.1.0")
2
2
  require_relative 'rails4/serialization'
3
3
  else
4
4
  require_relative 'rails5_1/serialization'
5
- end
5
+ end
@@ -1,7 +1,9 @@
1
- if ::ActiveRecord::VERSION::STRING < "5.0.0"
1
+ if ::ActiveRecord.version < Gem::Version.new("5.0.0")
2
2
  require_relative 'rails4/uniqueness_validator'
3
- elsif ::ActiveRecord::VERSION::STRING < "5.1.0"
3
+ elsif ::ActiveRecord.version < Gem::Version.new("5.1.0")
4
4
  require_relative 'rails5/uniqueness_validator'
5
- else
5
+ elsif ::ActiveRecord.version < Gem::Version.new("6.1.0")
6
6
  require_relative 'rails5_1/uniqueness_validator'
7
- end
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: 5.2.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -11,10 +11,36 @@ authors:
11
11
  - Tomasz Stachewicz
12
12
  - Philip Arndt
13
13
  - Chris Salzberg
14
- autorequire:
14
+ autorequire:
15
15
  bindir: bin
16
- cert_chain: []
17
- date: 2018-11-02 00:00:00.000000000 Z
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z
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
+ EQQTMBGBD2dlbXNAcC5hcm5kdC5pbzAaBgNVHRIEEzARgQ9nZW1zQHAuYXJuZHQu
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
+ -----END CERTIFICATE-----
43
+ date: 2021-06-23 00:00:00.000000000 Z
18
44
  dependencies:
19
45
  - !ruby/object:Gem::Dependency
20
46
  name: activerecord
@@ -25,7 +51,7 @@ dependencies:
25
51
  version: '4.2'
26
52
  - - "<"
27
53
  - !ruby/object:Gem::Version
28
- version: '5.3'
54
+ version: '7.0'
29
55
  type: :runtime
30
56
  prerelease: false
31
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -35,7 +61,7 @@ dependencies:
35
61
  version: '4.2'
36
62
  - - "<"
37
63
  - !ruby/object:Gem::Version
38
- version: '5.3'
64
+ version: '7.0'
39
65
  - !ruby/object:Gem::Dependency
40
66
  name: activemodel
41
67
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +71,7 @@ dependencies:
45
71
  version: '4.2'
46
72
  - - "<"
47
73
  - !ruby/object:Gem::Version
48
- version: '5.3'
74
+ version: '7.0'
49
75
  type: :runtime
50
76
  prerelease: false
51
77
  version_requirements: !ruby/object:Gem::Requirement
@@ -55,7 +81,7 @@ dependencies:
55
81
  version: '4.2'
56
82
  - - "<"
57
83
  - !ruby/object:Gem::Version
58
- version: '5.3'
84
+ version: '7.0'
59
85
  - !ruby/object:Gem::Dependency
60
86
  name: request_store
61
87
  requirement: !ruby/object:Gem::Requirement
@@ -182,20 +208,6 @@ dependencies:
182
208
  - - ">="
183
209
  - !ruby/object:Gem::Version
184
210
  version: '0'
185
- - !ruby/object:Gem::Dependency
186
- name: sqlite3
187
- requirement: !ruby/object:Gem::Requirement
188
- requirements:
189
- - - ">="
190
- - !ruby/object:Gem::Version
191
- version: '0'
192
- type: :development
193
- prerelease: false
194
- version_requirements: !ruby/object:Gem::Requirement
195
- requirements:
196
- - - ">="
197
- - !ruby/object:Gem::Version
198
- version: '0'
199
211
  description: Rails I18n de-facto standard library for ActiveRecord model/data translation.
200
212
  email: nobody@globalize-rails.org
201
213
  executables: []
@@ -206,10 +218,12 @@ files:
206
218
  - CHANGELOG.md
207
219
  - CONTRIBUTING.md
208
220
  - Gemfile
209
- - Gemfile.lock
210
221
  - LICENSE
211
222
  - README.md
212
223
  - Rakefile
224
+ - docker-compose.yml
225
+ - globalize.gemspec
226
+ - issue_template.rb
213
227
  - lib/globalize.rb
214
228
  - lib/globalize/active_record.rb
215
229
  - lib/globalize/active_record/act_macro.rb
@@ -234,6 +248,7 @@ files:
234
248
  - lib/patches/active_record/rails5/uniqueness_validator.rb
235
249
  - lib/patches/active_record/rails5_1/serialization.rb
236
250
  - lib/patches/active_record/rails5_1/uniqueness_validator.rb
251
+ - lib/patches/active_record/rails6_1/uniqueness_validator.rb
237
252
  - lib/patches/active_record/relation.rb
238
253
  - lib/patches/active_record/serialization.rb
239
254
  - lib/patches/active_record/uniqueness_validator.rb
@@ -242,7 +257,7 @@ homepage: http://github.com/globalize/globalize
242
257
  licenses:
243
258
  - MIT
244
259
  metadata: {}
245
- post_install_message:
260
+ post_install_message:
246
261
  rdoc_options: []
247
262
  require_paths:
248
263
  - lib
@@ -250,16 +265,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
265
  requirements:
251
266
  - - ">="
252
267
  - !ruby/object:Gem::Version
253
- version: 2.0.0
268
+ version: 2.4.6
254
269
  required_rubygems_version: !ruby/object:Gem::Requirement
255
270
  requirements:
256
271
  - - ">="
257
272
  - !ruby/object:Gem::Version
258
273
  version: '0'
259
274
  requirements: []
260
- rubyforge_project: "[none]"
261
- rubygems_version: 2.7.6
262
- signing_key:
275
+ rubygems_version: 3.1.6
276
+ signing_key:
263
277
  specification_version: 4
264
278
  summary: Rails I18n de-facto standard library for ActiveRecord model/data translation
265
279
  test_files: []
metadata.gz.sig ADDED
Binary file
data/Gemfile.lock DELETED
@@ -1,86 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- globalize (5.2.0)
5
- activemodel (>= 4.2, < 5.3)
6
- activerecord (>= 4.2, < 5.3)
7
- request_store (~> 1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (5.2.1)
13
- activesupport (= 5.2.1)
14
- activerecord (5.2.1)
15
- activemodel (= 5.2.1)
16
- activesupport (= 5.2.1)
17
- arel (>= 9.0)
18
- activesupport (5.2.1)
19
- concurrent-ruby (~> 1.0, >= 1.0.2)
20
- i18n (>= 0.7, < 2)
21
- minitest (~> 5.1)
22
- tzinfo (~> 1.1)
23
- ansi (1.5.0)
24
- appraisal (2.2.0)
25
- bundler
26
- rake
27
- thor (>= 0.14.0)
28
- arel (9.0.0)
29
- builder (3.2.3)
30
- coderay (1.1.2)
31
- concurrent-ruby (1.0.5)
32
- concurrent-ruby (1.0.5-java)
33
- database_cleaner (1.6.2)
34
- ffi (1.9.18-java)
35
- i18n (1.1.1)
36
- concurrent-ruby (~> 1.0)
37
- m (1.5.1)
38
- method_source (>= 0.6.7)
39
- rake (>= 0.9.2.2)
40
- method_source (0.9.0)
41
- minitest (5.11.1)
42
- minitest-reporters (1.1.19)
43
- ansi
44
- builder
45
- minitest (>= 5.0)
46
- ruby-progressbar
47
- pry (0.11.3)
48
- coderay (~> 1.1.0)
49
- method_source (~> 0.9.0)
50
- pry (0.11.3-java)
51
- coderay (~> 1.1.0)
52
- method_source (~> 0.9.0)
53
- spoon (~> 0.0)
54
- rack (2.0.5)
55
- rake (12.3.0)
56
- rdoc (6.0.1)
57
- request_store (1.4.1)
58
- rack (>= 1.4)
59
- ruby-progressbar (1.9.0)
60
- spoon (0.0.6)
61
- ffi
62
- sqlite3 (1.3.13)
63
- thor (0.20.0)
64
- thread_safe (0.3.6)
65
- thread_safe (0.3.6-java)
66
- tzinfo (1.2.5)
67
- thread_safe (~> 0.1)
68
-
69
- PLATFORMS
70
- java
71
- ruby
72
-
73
- DEPENDENCIES
74
- appraisal
75
- database_cleaner
76
- globalize!
77
- m
78
- minitest
79
- minitest-reporters
80
- pry
81
- rake
82
- rdoc
83
- sqlite3
84
-
85
- BUNDLED WITH
86
- 1.17.1