globalize 5.1.0 → 5.2.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
- SHA1:
3
- metadata.gz: 57f25eaab88304fdb368cbbf71aba41413e20a49
4
- data.tar.gz: 074e1bb69520bbf7b7dd658beaede38b8f58fcbc
2
+ SHA256:
3
+ metadata.gz: 18d470a9030a9901a83b9d3c48080661b10000a20049f598eece0b41727d66dc
4
+ data.tar.gz: b1ea4e1d1c0210271fede3bf8d7903ac658ace1af1742bf29980139efc555673
5
5
  SHA512:
6
- metadata.gz: 6793d5894ce36c34d65b8c59b0c26d12f268cfe27a0fdcba0bde632df9c0418af1c975c71ef14f56bcbcc0749b726f8d751c2e02b64e173b457e3a240527dfa7
7
- data.tar.gz: b718eed39f3683df1faa47828c5535b8c50466b6fed9c15f17cd670e6597c7cbc749db725cdbeb7c711044b1a25b92d1c9042d90cfa6d71b424adbef7ffe9eec
6
+ metadata.gz: 70eaedf3edada661ab9495f31ec46544cc950ba4c6ff667c9d6e1bf699cd770de02ffab2783ba29735c39d35d6b92c9ab2b0f8061185a3e1f3469354f82e560a
7
+ data.tar.gz: 1b255c9f3164165e76650a4b0fbbfbc989f87ec524a9c4bb1e70ea8fd54b3f16811a9c5a42cfe8f38df0d47ca00fd2632a95f0918c58bdb2e24b5c313b5d2508
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ RAILS_VERSIONS = %w[
4
+ 4.2.10
5
+ 5.1.6
6
+ 5.2.1
7
+ ]
8
+
9
+ RAILS_VERSIONS.each do |version|
10
+ appraise "rails_#{version}" do
11
+ gem 'activemodel', version
12
+ gem 'activerecord', version
13
+
14
+ platforms :rbx do
15
+ gem "rubysl", "~> 2.0"
16
+ gem "rubinius-developer_tools"
17
+ end
18
+
19
+ platforms :jruby do
20
+ if !ENV['TRAVIS'] || ENV['DB'] == 'sqlite3'
21
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1'
22
+ end
23
+
24
+ if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
25
+ gem 'activerecord-jdbcmysql-adapter', '~> 1'
26
+ end
27
+
28
+ if !ENV['TRAVIS'] || %w(postgres postgresql).include?(ENV['DB'])
29
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,6 @@
1
1
  # Globalize Changelog
2
2
 
3
- ## 5.1.0 (unreleased)
3
+ ## 5.1.0 (2018-01-15)
4
4
 
5
5
  * 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)
6
6
  * Add [RequestStore](https://github.com/steveklabnik/request_store) to make Globalize thread-safe again [#420](https://github.com/globalize/globalize/pull/420)
@@ -35,3 +35,18 @@ Have a bug fix, code improvement or proposed feature? Do the following:
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
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.
38
+
39
+ ## Testing
40
+
41
+ ### Requirements
42
+
43
+ - Ruby
44
+ - Bundler
45
+ - SQLite
46
+ - You can switch the database by adding an environment variable. See `test/support/database.rb`.
47
+ - You can also configure your database configurations. See `test/support/database.yml`.
48
+
49
+ ### Run tests on your local machine
50
+
51
+ - `bundle install`
52
+ - `bundle exec rake`
data/Gemfile CHANGED
@@ -1,26 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "pry"
6
-
7
- eval File.read(File.expand_path("../gemfiles/.gemfile.database-config.rb", __FILE__))
8
-
9
- platforms :rbx do
10
- gem "rubysl", "~> 2.0"
11
- gem "rubinius-developer_tools"
12
- end
13
-
14
- platforms :jruby do
15
- if !ENV['TRAVIS'] || ENV['DB'] == 'sqlite3'
16
- gem 'activerecord-jdbcsqlite3-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
17
- end
18
-
19
- if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
20
- gem 'activerecord-jdbcmysql-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
21
- end
22
-
23
- if !ENV['TRAVIS'] || %w(postgres postgresql).include?(ENV['DB'])
24
- gem 'activerecord-jdbcpostgresql-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
25
- end
26
- end
@@ -1,55 +1,42 @@
1
- GIT
2
- remote: https://github.com/jruby/activerecord-jdbc-adapter
3
- revision: 4ae8a3c4d4b00d1c33ef6b9099f63a3f78da21ad
4
- specs:
5
- activerecord-jdbc-adapter (51.0)
6
- activerecord (~> 5.1.0)
7
- activerecord-jdbcmysql-adapter (51.0)
8
- activerecord-jdbc-adapter (~> 51.0)
9
- jdbc-mysql (~> 5.1.36)
10
- activerecord-jdbcpostgresql-adapter (51.0)
11
- activerecord-jdbc-adapter (~> 51.0)
12
- jdbc-postgres (>= 9.4, < 43)
13
- activerecord-jdbcsqlite3-adapter (51.0)
14
- activerecord-jdbc-adapter (~> 51.0)
15
- jdbc-sqlite3 (~> 3.8, < 3.30)
16
- jdbc-mysql (5.1.44)
17
- jdbc-postgres (42.1.4)
18
- jdbc-sqlite3 (3.20.1)
19
-
20
1
  PATH
21
2
  remote: .
22
3
  specs:
23
- globalize (5.1.0)
24
- activemodel (>= 4.2, < 5.2)
25
- activerecord (>= 4.2, < 5.2)
4
+ globalize (5.2.0)
5
+ activemodel (>= 4.2, < 5.3)
6
+ activerecord (>= 4.2, < 5.3)
26
7
  request_store (~> 1.0)
27
8
 
28
9
  GEM
29
10
  remote: https://rubygems.org/
30
11
  specs:
31
- activemodel (5.1.4)
32
- activesupport (= 5.1.4)
33
- activerecord (5.1.4)
34
- activemodel (= 5.1.4)
35
- activesupport (= 5.1.4)
36
- arel (~> 8.0)
37
- activesupport (5.1.4)
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)
38
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
39
- i18n (~> 0.7)
20
+ i18n (>= 0.7, < 2)
40
21
  minitest (~> 5.1)
41
22
  tzinfo (~> 1.1)
42
23
  ansi (1.5.0)
43
- arel (8.0.0)
24
+ appraisal (2.2.0)
25
+ bundler
26
+ rake
27
+ thor (>= 0.14.0)
28
+ arel (9.0.0)
44
29
  builder (3.2.3)
45
30
  coderay (1.1.2)
46
31
  concurrent-ruby (1.0.5)
47
32
  concurrent-ruby (1.0.5-java)
48
33
  database_cleaner (1.6.2)
49
34
  ffi (1.9.18-java)
50
- ffi2-generators (0.1.1)
51
- i18n (0.9.1)
35
+ i18n (1.1.1)
52
36
  concurrent-ruby (~> 1.0)
37
+ m (1.5.1)
38
+ method_source (>= 0.6.7)
39
+ rake (>= 0.9.2.2)
53
40
  method_source (0.9.0)
54
41
  minitest (5.11.1)
55
42
  minitest-reporters (1.1.19)
@@ -57,8 +44,6 @@ GEM
57
44
  builder
58
45
  minitest (>= 5.0)
59
46
  ruby-progressbar
60
- mysql2 (0.4.10)
61
- pg (1.0.0)
62
47
  pry (0.11.3)
63
48
  coderay (~> 1.1.0)
64
49
  method_source (~> 0.9.0)
@@ -66,227 +51,19 @@ GEM
66
51
  coderay (~> 1.1.0)
67
52
  method_source (~> 0.9.0)
68
53
  spoon (~> 0.0)
69
- rack (2.0.3)
54
+ rack (2.0.5)
70
55
  rake (12.3.0)
71
56
  rdoc (6.0.1)
72
- request_store (1.4.0)
57
+ request_store (1.4.1)
73
58
  rack (>= 1.4)
74
- rubinius-coverage (2.1)
75
- rubinius-debugger (2.6)
76
- rubinius-developer_tools (2.0.0)
77
- rubinius-coverage (~> 2.0)
78
- rubinius-debugger (~> 2.0)
79
- rubinius-profiler (~> 2.0)
80
- rubinius-profiler (2.1)
81
59
  ruby-progressbar (1.9.0)
82
- rubysl (2.2.0)
83
- rubysl-abbrev (~> 2.0)
84
- rubysl-base64 (~> 2.0)
85
- rubysl-benchmark (~> 2.0)
86
- rubysl-bigdecimal (~> 2.0)
87
- rubysl-cgi (~> 2.0)
88
- rubysl-cgi-session (~> 2.0)
89
- rubysl-cmath (~> 2.0)
90
- rubysl-complex (~> 2.0)
91
- rubysl-continuation (~> 2.0)
92
- rubysl-coverage (~> 2.0)
93
- rubysl-csv (~> 2.0)
94
- rubysl-curses (~> 2.0)
95
- rubysl-date (~> 2.0)
96
- rubysl-delegate (~> 2.0)
97
- rubysl-digest (~> 2.0)
98
- rubysl-drb (~> 2.0)
99
- rubysl-e2mmap (~> 2.0)
100
- rubysl-english (~> 2.0)
101
- rubysl-enumerator (~> 2.0)
102
- rubysl-erb (~> 2.0)
103
- rubysl-etc (~> 2.0)
104
- rubysl-expect (~> 2.0)
105
- rubysl-fcntl (~> 2.0)
106
- rubysl-fiber (~> 2.0)
107
- rubysl-fileutils (~> 2.0)
108
- rubysl-find (~> 2.0)
109
- rubysl-forwardable (~> 2.0)
110
- rubysl-getoptlong (~> 2.0)
111
- rubysl-gserver (~> 2.0)
112
- rubysl-io-console (~> 2.0)
113
- rubysl-io-nonblock (~> 2.0)
114
- rubysl-io-wait (~> 2.0)
115
- rubysl-ipaddr (~> 2.0)
116
- rubysl-irb (~> 2.1)
117
- rubysl-logger (~> 2.0)
118
- rubysl-mathn (~> 2.0)
119
- rubysl-matrix (~> 2.0)
120
- rubysl-mkmf (~> 2.0)
121
- rubysl-monitor (~> 2.0)
122
- rubysl-mutex_m (~> 2.0)
123
- rubysl-net-ftp (~> 2.0)
124
- rubysl-net-http (~> 2.0)
125
- rubysl-net-imap (~> 2.0)
126
- rubysl-net-pop (~> 2.0)
127
- rubysl-net-protocol (~> 2.0)
128
- rubysl-net-smtp (~> 2.0)
129
- rubysl-net-telnet (~> 2.0)
130
- rubysl-nkf (~> 2.0)
131
- rubysl-observer (~> 2.0)
132
- rubysl-open-uri (~> 2.0)
133
- rubysl-open3 (~> 2.0)
134
- rubysl-openssl (~> 2.0)
135
- rubysl-optparse (~> 2.0)
136
- rubysl-ostruct (~> 2.0)
137
- rubysl-pathname (~> 2.0)
138
- rubysl-prettyprint (~> 2.0)
139
- rubysl-prime (~> 2.0)
140
- rubysl-profile (~> 2.0)
141
- rubysl-profiler (~> 2.0)
142
- rubysl-pstore (~> 2.0)
143
- rubysl-pty (~> 2.0)
144
- rubysl-rational (~> 2.0)
145
- rubysl-resolv (~> 2.0)
146
- rubysl-rexml (~> 2.0)
147
- rubysl-rinda (~> 2.0)
148
- rubysl-rss (~> 2.0)
149
- rubysl-scanf (~> 2.0)
150
- rubysl-securerandom (~> 2.0)
151
- rubysl-set (~> 2.0)
152
- rubysl-shellwords (~> 2.0)
153
- rubysl-singleton (~> 2.0)
154
- rubysl-socket (~> 2.0)
155
- rubysl-stringio (~> 2.0)
156
- rubysl-strscan (~> 2.0)
157
- rubysl-sync (~> 2.0)
158
- rubysl-syslog (~> 2.0)
159
- rubysl-tempfile (~> 2.0)
160
- rubysl-thread (~> 2.0)
161
- rubysl-thwait (~> 2.0)
162
- rubysl-time (~> 2.0)
163
- rubysl-timeout (~> 2.0)
164
- rubysl-tmpdir (~> 2.0)
165
- rubysl-tsort (~> 2.0)
166
- rubysl-un (~> 2.0)
167
- rubysl-unicode_normalize (~> 2.0)
168
- rubysl-uri (~> 2.0)
169
- rubysl-weakref (~> 2.0)
170
- rubysl-webrick (~> 2.0)
171
- rubysl-xmlrpc (~> 2.0)
172
- rubysl-yaml (~> 2.0)
173
- rubysl-zlib (~> 2.0)
174
- rubysl-abbrev (2.0.4)
175
- rubysl-base64 (2.0.0)
176
- rubysl-benchmark (2.0.1)
177
- rubysl-bigdecimal (2.0.2)
178
- rubysl-cgi (2.0.1)
179
- rubysl-cgi-session (2.1.0)
180
- rubysl-cmath (2.0.0)
181
- rubysl-complex (2.0.0)
182
- rubysl-continuation (2.0.0)
183
- rubysl-coverage (2.1)
184
- rubysl-csv (2.0.2)
185
- rubysl-english (~> 2.0)
186
- rubysl-curses (2.0.1)
187
- rubysl-date (2.0.9)
188
- rubysl-delegate (2.0.1)
189
- rubysl-digest (2.0.8)
190
- rubysl-drb (2.0.1)
191
- rubysl-e2mmap (2.0.0)
192
- rubysl-english (2.0.0)
193
- rubysl-enumerator (2.0.0)
194
- rubysl-erb (2.0.2)
195
- rubysl-etc (2.0.3)
196
- ffi2-generators (~> 0.1)
197
- rubysl-expect (2.0.0)
198
- rubysl-fcntl (2.0.4)
199
- ffi2-generators (~> 0.1)
200
- rubysl-fiber (2.0.0)
201
- rubysl-fileutils (2.0.3)
202
- rubysl-find (2.0.1)
203
- rubysl-forwardable (2.0.1)
204
- rubysl-getoptlong (2.0.0)
205
- rubysl-gserver (2.0.0)
206
- rubysl-socket (~> 2.0)
207
- rubysl-thread (~> 2.0)
208
- rubysl-io-console (2.0.0)
209
- rubysl-io-nonblock (2.0.0)
210
- rubysl-io-wait (2.0.0)
211
- rubysl-ipaddr (2.0.0)
212
- rubysl-irb (2.1.1)
213
- rubysl-e2mmap (~> 2.0)
214
- rubysl-mathn (~> 2.0)
215
- rubysl-thread (~> 2.0)
216
- rubysl-logger (2.1.0)
217
- rubysl-mathn (2.0.0)
218
- rubysl-matrix (2.1.0)
219
- rubysl-e2mmap (~> 2.0)
220
- rubysl-mkmf (2.1)
221
- rubysl-fileutils (~> 2.0)
222
- rubysl-shellwords (~> 2.0)
223
- rubysl-monitor (2.1)
224
- rubysl-mutex_m (2.0.0)
225
- rubysl-net-ftp (2.0.1)
226
- rubysl-net-http (2.0.4)
227
- rubysl-cgi (~> 2.0)
228
- rubysl-erb (~> 2.0)
229
- rubysl-singleton (~> 2.0)
230
- rubysl-net-imap (2.0.1)
231
- rubysl-net-pop (2.0.1)
232
- rubysl-net-protocol (2.0.1)
233
- rubysl-net-smtp (2.0.1)
234
- rubysl-net-telnet (2.0.0)
235
- rubysl-nkf (2.0.1)
236
- rubysl-observer (2.0.0)
237
- rubysl-open-uri (2.0.0)
238
- rubysl-open3 (2.0.0)
239
- rubysl-openssl (2.9)
240
- rubysl-optparse (2.0.1)
241
- rubysl-shellwords (~> 2.0)
242
- rubysl-ostruct (2.1.0)
243
- rubysl-pathname (2.3)
244
- rubysl-prettyprint (2.0.3)
245
- rubysl-prime (2.0.1)
246
- rubysl-profile (2.0.0)
247
- rubysl-profiler (2.1)
248
- rubysl-pstore (2.0.0)
249
- rubysl-pty (2.0.3)
250
- rubysl-rational (2.0.1)
251
- rubysl-resolv (2.1.2)
252
- rubysl-rexml (2.0.4)
253
- rubysl-rinda (2.0.1)
254
- rubysl-rss (2.0.0)
255
- rubysl-scanf (2.0.0)
256
- rubysl-securerandom (2.0.0)
257
- rubysl-set (2.0.1)
258
- rubysl-shellwords (2.0.0)
259
- rubysl-singleton (2.0.0)
260
- rubysl-socket (2.2.1)
261
- rubysl-fcntl (~> 2.0)
262
- rubysl-stringio (2.2)
263
- rubysl-strscan (2.0.0)
264
- rubysl-sync (2.0.0)
265
- rubysl-syslog (2.1.0)
266
- ffi2-generators (~> 0.1)
267
- rubysl-tempfile (2.0.1)
268
- rubysl-thread (2.1)
269
- rubysl-thwait (2.0.0)
270
- rubysl-time (2.0.3)
271
- rubysl-timeout (2.0.0)
272
- rubysl-tmpdir (2.0.1)
273
- rubysl-tsort (2.0.1)
274
- rubysl-un (2.0.0)
275
- rubysl-fileutils (~> 2.0)
276
- rubysl-optparse (~> 2.0)
277
- rubysl-unicode_normalize (2.0)
278
- rubysl-uri (2.0.0)
279
- rubysl-weakref (2.0.0)
280
- rubysl-webrick (2.0.0)
281
- rubysl-xmlrpc (2.0.0)
282
- rubysl-yaml (2.1.0)
283
- rubysl-zlib (2.0.1)
284
60
  spoon (0.0.6)
285
61
  ffi
286
62
  sqlite3 (1.3.13)
63
+ thor (0.20.0)
287
64
  thread_safe (0.3.6)
288
65
  thread_safe (0.3.6-java)
289
- tzinfo (1.2.4)
66
+ tzinfo (1.2.5)
290
67
  thread_safe (~> 0.1)
291
68
 
292
69
  PLATFORMS
@@ -294,21 +71,16 @@ PLATFORMS
294
71
  ruby
295
72
 
296
73
  DEPENDENCIES
297
- activerecord-jdbcmysql-adapter!
298
- activerecord-jdbcpostgresql-adapter!
299
- activerecord-jdbcsqlite3-adapter!
74
+ appraisal
300
75
  database_cleaner
301
76
  globalize!
77
+ m
302
78
  minitest
303
79
  minitest-reporters
304
- mysql2
305
- pg
306
80
  pry
307
81
  rake
308
82
  rdoc
309
- rubinius-developer_tools
310
- rubysl (~> 2.0)
311
83
  sqlite3
312
84
 
313
85
  BUNDLED WITH
314
- 1.16.1
86
+ 1.17.1
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ![Globalize](http://globalize.github.io/globalize/images/globalize.png)
2
2
 
3
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)
4
+ [![Open Source Helpers](https://www.codetriage.com/globalize/globalize/badges/users.svg)](https://www.codetriage.com/globalize/globalize)
4
5
 
5
6
  You can chat with us using Gitter:
6
7
 
@@ -27,13 +28,7 @@ gem install globalize
27
28
  When using bundler put this in your Gemfile:
28
29
 
29
30
  ```ruby
30
- gem 'globalize', '~> 5.0.0'
31
- ```
32
-
33
- You have to use the **master** branch to work with Rails 5, or you can use a pre-release gem:
34
-
35
- ```ruby
36
- gem 'globalize', '~> 5.1.0.beta2'
31
+ gem 'globalize', '~> 5.1.0'
37
32
  ```
38
33
 
39
34
  Please help us by letting us know what works, and what doesn't, when using pre-release code.
@@ -58,6 +58,14 @@ module Globalize
58
58
  RequestStore.store
59
59
  end
60
60
 
61
+ def rails_5?
62
+ ::ActiveRecord.version >= Gem::Version.new('5.1.0')
63
+ end
64
+
65
+ def rails_52?
66
+ ::ActiveRecord.version >= Gem::Version.new('5.2.0')
67
+ end
68
+
61
69
  protected
62
70
 
63
71
  def read_locale
@@ -1,14 +1,14 @@
1
1
  module Globalize
2
2
  module ActiveRecord
3
- autoload :ActMacro, 'globalize/active_record/act_macro'
4
- autoload :Adapter, 'globalize/active_record/adapter'
5
- autoload :AdapterDirty, 'globalize/active_record/adapter_dirty'
6
- autoload :Attributes, 'globalize/active_record/attributes'
7
- autoload :ClassMethods, 'globalize/active_record/class_methods'
8
- autoload :Exceptions, 'globalize/active_record/exceptions'
9
- autoload :InstanceMethods, 'globalize/active_record/instance_methods'
10
- autoload :Migration, 'globalize/active_record/migration'
11
- autoload :Translation, 'globalize/active_record/translation'
12
- autoload :QueryMethods, 'globalize/active_record/query_methods'
3
+ autoload :ActMacro, 'globalize/active_record/act_macro'
4
+ autoload :Adapter, 'globalize/active_record/adapter'
5
+ autoload :AdapterDirty, 'globalize/active_record/adapter_dirty'
6
+ autoload :Attributes, 'globalize/active_record/attributes'
7
+ autoload :ClassMethods, 'globalize/active_record/class_methods'
8
+ autoload :Exceptions, 'globalize/active_record/exceptions'
9
+ autoload :InstanceMethods, 'globalize/active_record/instance_methods'
10
+ autoload :Migration, 'globalize/active_record/migration'
11
+ autoload :Translation, 'globalize/active_record/translation'
12
+ autoload :TranslatedAttributesQuery, 'globalize/active_record/translated_attributes_query'
13
13
  end
14
14
  end
@@ -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 ::ActiveRecord::VERSION::STRING > "5.0" && 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
@@ -99,11 +99,11 @@ module Globalize
99
99
  :foreign_key => options[:foreign_key],
100
100
  :dependent => :destroy,
101
101
  :extend => HasManyExtensions,
102
- :autosave => true,
102
+ :autosave => false,
103
103
  :inverse_of => :globalized_model
104
104
 
105
- before_create :save_translations!
106
- before_update :save_translations!
105
+ after_create :save_translations!
106
+ after_update :save_translations!
107
107
  end
108
108
  end
109
109
 
@@ -43,6 +43,9 @@ module Globalize
43
43
  value = value.val if value.is_a?(Arel::Nodes::Casted)
44
44
  translation[name] = value
45
45
  end
46
+
47
+ ensure_foreign_key_for(translation)
48
+ translation.save!
46
49
  end
47
50
 
48
51
  reset
@@ -54,6 +57,12 @@ module Globalize
54
57
 
55
58
  protected
56
59
 
60
+ # Sometimes the translation is initialised before a foreign key can be set.
61
+ def ensure_foreign_key_for(translation)
62
+ # AR >= 4.1 reflections renamed to _reflections
63
+ translation[translation.class.reflections.stringify_keys["globalized_model"].foreign_key] = record.id
64
+ end
65
+
57
66
  def type_cast(name, value)
58
67
  return value.presence unless column = column_for_attribute(name)
59
68
 
@@ -36,19 +36,21 @@ module Globalize
36
36
  dirty[name][locale] = old
37
37
  end
38
38
  end
39
+
39
40
  def clear_dirty
40
41
  self.dirty = {}
41
42
  end
42
43
 
43
44
  def _reset_attribute name
44
45
  record.send("#{name}=", record.changed_attributes[name])
45
- record.original_changed_attributes.except!(name)
46
+ record.send(:clear_attribute_changes, [name])
46
47
  end
47
48
 
48
49
  def reset
49
50
  clear_dirty
50
51
  super
51
52
  end
53
+
52
54
  end
53
55
  end
54
56
  end
@@ -76,10 +76,10 @@ module Globalize
76
76
  private
77
77
 
78
78
  # Override the default relation method in order to return a subclass
79
- # of ActiveRecord::Relation with custom finder methods for translated
80
- # attributes.
79
+ # of ActiveRecord::Relation with custom finder and calculation methods
80
+ # for translated attributes.
81
81
  def relation
82
- super.extending!(QueryMethods)
82
+ super.extending!(TranslatedAttributesQuery)
83
83
  end
84
84
 
85
85
  protected
@@ -98,6 +98,7 @@ module Globalize
98
98
  end
99
99
 
100
100
  def define_translated_attr_accessor(name)
101
+ attribute(name, ::ActiveRecord::Type::Value.new)
101
102
  define_translated_attr_reader(name)
102
103
  define_translated_attr_writer(name)
103
104
  end
@@ -17,10 +17,24 @@ module Globalize
17
17
  with_given_locale(attributes) { super(attributes.except("locale"), *options) }
18
18
  end
19
19
 
20
- def assign_attributes(new_attributes, *options)
21
- super unless new_attributes.respond_to?(:stringify_keys) && new_attributes.present?
22
- attributes = new_attributes.stringify_keys
23
- with_given_locale(attributes) { super(attributes.except("locale"), *options) }
20
+ if Globalize.rails_52?
21
+
22
+ # In Rails 5.2 we need to override *_assign_attributes* as it's called earlier
23
+ # in the stack (before *assign_attributes*)
24
+ # See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_assignment.rb#L11
25
+ def _assign_attributes(new_attributes)
26
+ attributes = new_attributes.stringify_keys
27
+ with_given_locale(attributes) { super(attributes.except("locale")) }
28
+ end
29
+
30
+ else
31
+
32
+ def assign_attributes(new_attributes, *options)
33
+ super unless new_attributes.respond_to?(:stringify_keys) && new_attributes.present?
34
+ attributes = new_attributes.stringify_keys
35
+ with_given_locale(attributes) { super(attributes.except("locale"), *options) }
36
+ end
37
+
24
38
  end
25
39
 
26
40
  def write_attribute(name, value, *args, &block)
@@ -39,19 +53,21 @@ module Globalize
39
53
  end
40
54
  end
41
55
 
42
- def read_attribute(name, options = {}, &block)
43
- options = {:translated => true, :locale => nil}.merge(options)
44
- return super(name, &block) unless options[:translated]
56
+ def read_attribute(attr_name, options = {}, &block)
57
+ name = if self.class.attribute_alias?(attr_name)
58
+ self.class.attribute_alias(attr_name).to_s
59
+ else
60
+ attr_name.to_s
61
+ end
45
62
 
46
- if translated?(name)
47
- if !(value = globalize.fetch(options[:locale] || Globalize.locale, name)).nil?
48
- value
49
- else
50
- super(name, &block)
51
- end
52
- else
53
- super(name, &block)
54
- end
63
+ name = self.class.primary_key if name == "id".freeze && self.class.primary_key
64
+
65
+ _read_attribute(name, options, &block)
66
+ end
67
+
68
+ def _read_attribute(attr_name, options = {}, &block)
69
+ translated_value = read_translated_attribute(attr_name, options, &block)
70
+ translated_value.nil? ? super(attr_name, &block) : translated_value
55
71
  end
56
72
 
57
73
  def attribute_names
@@ -213,6 +229,18 @@ module Globalize
213
229
  ensure
214
230
  self.fallbacks_for_empty_translations = before
215
231
  end
232
+
233
+ # nil or value
234
+ def read_translated_attribute(name, options)
235
+ options = {:translated => true, :locale => nil}.merge(options)
236
+ return nil unless options[:translated]
237
+ return nil unless translated?(name)
238
+
239
+ value = globalize.fetch(options[:locale] || Globalize.locale, name)
240
+ return nil if value.nil?
241
+
242
+ block_given? ? yield(value) : value
243
+ end
216
244
  end
217
245
  end
218
246
  end
@@ -166,7 +166,7 @@ module Globalize
166
166
  end
167
167
 
168
168
  def column_type(name)
169
- columns.detect { |c| c.name == name.to_s }.try(:type)
169
+ columns.detect { |c| c.name == name.to_s }.try(:type) || :string
170
170
  end
171
171
 
172
172
  def valid_field_name?(name)
@@ -1,6 +1,6 @@
1
1
  module Globalize
2
2
  module ActiveRecord
3
- module QueryMethods
3
+ module TranslatedAttributesQuery
4
4
  class WhereChain < ::ActiveRecord::QueryMethods::WhereChain
5
5
  def not(opts, *rest)
6
6
  if parsed = @scope.clone.parse_translated_conditions(opts)
@@ -21,6 +21,14 @@ module Globalize
21
21
  end
22
22
  end
23
23
 
24
+ def having(opts, *rest)
25
+ if parsed = parse_translated_conditions(opts)
26
+ join_translations(super(parsed, *rest))
27
+ else
28
+ super
29
+ end
30
+ end
31
+
24
32
  def order(opts, *rest)
25
33
  if respond_to?(:translated_attribute_names) && parsed = parse_translated_order(opts)
26
34
  join_translations super(parsed)
@@ -29,6 +37,30 @@ module Globalize
29
37
  end
30
38
  end
31
39
 
40
+ def reorder(opts, *rest)
41
+ if respond_to?(:translated_attribute_names) && parsed = parse_translated_order(opts)
42
+ join_translations super(parsed)
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def group(*columns)
49
+ if respond_to?(:translated_attribute_names) && parsed = parse_translated_columns(columns)
50
+ join_translations super(parsed)
51
+ else
52
+ super
53
+ end
54
+ end
55
+
56
+ def select(*columns)
57
+ if respond_to?(:translated_attribute_names) && parsed = parse_translated_columns(columns)
58
+ join_translations super(parsed)
59
+ else
60
+ super
61
+ end
62
+ end
63
+
32
64
  def exists?(conditions = :none)
33
65
  if parsed = parse_translated_conditions(conditions)
34
66
  with_translations_in_fallbacks.exists?(parsed)
@@ -37,6 +69,24 @@ module Globalize
37
69
  end
38
70
  end
39
71
 
72
+ def calculate(*args)
73
+ column_name = args[1]
74
+ if respond_to?(:translated_attribute_names) && translated_column?(column_name)
75
+ args[1] = translated_column_name(column_name)
76
+ join_translations.calculate(*args)
77
+ else
78
+ super
79
+ end
80
+ end
81
+
82
+ def pluck(*column_names)
83
+ if respond_to?(:translated_attribute_names) && parsed = parse_translated_columns(column_names)
84
+ join_translations.pluck(*parsed)
85
+ else
86
+ super
87
+ end
88
+ end
89
+
40
90
  def with_translations_in_fallbacks
41
91
  with_translations(Globalize.fallbacks)
42
92
  end
@@ -110,11 +160,19 @@ module Globalize
110
160
  order(ordering).order_values
111
161
  when Symbol
112
162
  parse_translated_order({ opts => :asc })
163
+ when Array
164
+ parse_translated_order(Hash[opts.collect { |opt| [opt, :asc] } ])
113
165
  else # failsafe returns nothing
114
166
  nil
115
167
  end
116
168
  end
117
169
 
170
+ def parse_translated_columns(columns)
171
+ if columns.is_a?(Array) && (columns.flatten & translated_attribute_names).present?
172
+ columns.flatten.map { |column| translated_column?(column) ? translated_column_name(column) : column }
173
+ end
174
+ end
175
+
118
176
  def translated_column?(column)
119
177
  translated_attribute_names.include?(column)
120
178
  end
@@ -1,3 +1,3 @@
1
1
  module Globalize
2
- Version = '5.1.0'
2
+ Version = '5.2.0'
3
3
  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.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2018-01-15 00:00:00.000000000 Z
17
+ date: 2018-11-02 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -25,7 +25,7 @@ dependencies:
25
25
  version: '4.2'
26
26
  - - "<"
27
27
  - !ruby/object:Gem::Version
28
- version: '5.2'
28
+ version: '5.3'
29
29
  type: :runtime
30
30
  prerelease: false
31
31
  version_requirements: !ruby/object:Gem::Requirement
@@ -35,7 +35,7 @@ dependencies:
35
35
  version: '4.2'
36
36
  - - "<"
37
37
  - !ruby/object:Gem::Version
38
- version: '5.2'
38
+ version: '5.3'
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: activemodel
41
41
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '4.2'
46
46
  - - "<"
47
47
  - !ruby/object:Gem::Version
48
- version: '5.2'
48
+ version: '5.3'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '4.2'
56
56
  - - "<"
57
57
  - !ruby/object:Gem::Version
58
- version: '5.2'
58
+ version: '5.3'
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: request_store
61
61
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +70,20 @@ dependencies:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '1.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: appraisal
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
73
87
  - !ruby/object:Gem::Dependency
74
88
  name: database_cleaner
75
89
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +98,20 @@ dependencies:
84
98
  - - ">="
85
99
  - !ruby/object:Gem::Version
86
100
  version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: m
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
87
115
  - !ruby/object:Gem::Dependency
88
116
  name: minitest
89
117
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +141,7 @@ dependencies:
113
141
  - !ruby/object:Gem::Version
114
142
  version: '0'
115
143
  - !ruby/object:Gem::Dependency
116
- name: rdoc
144
+ name: pry
117
145
  requirement: !ruby/object:Gem::Requirement
118
146
  requirements:
119
147
  - - ">="
@@ -140,12 +168,41 @@ dependencies:
140
168
  - - ">="
141
169
  - !ruby/object:Gem::Version
142
170
  version: '0'
171
+ - !ruby/object:Gem::Dependency
172
+ name: rdoc
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ type: :development
179
+ prerelease: false
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ 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'
143
199
  description: Rails I18n de-facto standard library for ActiveRecord model/data translation.
144
200
  email: nobody@globalize-rails.org
145
201
  executables: []
146
202
  extensions: []
147
203
  extra_rdoc_files: []
148
204
  files:
205
+ - Appraisals
149
206
  - CHANGELOG.md
150
207
  - CONTRIBUTING.md
151
208
  - Gemfile
@@ -163,7 +220,7 @@ files:
163
220
  - lib/globalize/active_record/exceptions.rb
164
221
  - lib/globalize/active_record/instance_methods.rb
165
222
  - lib/globalize/active_record/migration.rb
166
- - lib/globalize/active_record/query_methods.rb
223
+ - lib/globalize/active_record/translated_attributes_query.rb
167
224
  - lib/globalize/active_record/translation.rb
168
225
  - lib/globalize/interpolation.rb
169
226
  - lib/globalize/version.rb
@@ -201,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
258
  version: '0'
202
259
  requirements: []
203
260
  rubyforge_project: "[none]"
204
- rubygems_version: 2.6.13
261
+ rubygems_version: 2.7.6
205
262
  signing_key:
206
263
  specification_version: 4
207
264
  summary: Rails I18n de-facto standard library for ActiveRecord model/data translation