globalize 4.0.0.alpha.3 → 4.0.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd7e2e9e5d23a8dd6696722ddd3dfabc200f07e1
4
- data.tar.gz: 340c3919bd3bdb8a5a3f821c12189d29df20e181
3
+ metadata.gz: 346bd7c5bd2e5a5f967a664e31cd11daee6d19c8
4
+ data.tar.gz: 51953b552d2ba5f9e87f6c710767ac498b19db47
5
5
  SHA512:
6
- metadata.gz: 53351f2d7268b5e183410c58331205e9f704a24f6e5e2df95813117c0915d62c5ba9dbca33531bff572c80672a315e1add169bbdc2e2686b68abc51f45815d6e
7
- data.tar.gz: c411ea171a017727cf07d2bd6dcc4e83c71f88700f4cde510684a88422e6eda44bf2af10e43d9c87a4b2de54d089d546e334cb81930128bd8259bb1808e337df
6
+ metadata.gz: 4204e5c710147a377f5ae008a5df25d7611c3366555581daa8d4ccf51d82b38ba4e387fc7a81db7530dccba1874ef951ac4490915501c1cc8227fcbe73802675
7
+ data.tar.gz: 4705b6326dba707413cbff15ff3d0799a3a53b17154c7874725cd98c878023e05657f42cd94567925b8f9433884f3c7b85f80bb89f39571402c5894ede1d0f74
@@ -0,0 +1,59 @@
1
+ # Globalize Changelog
2
+
3
+ ## 4.0.0.alpha.4 (2013-12-30)
4
+ * Add this changelog.
5
+ * Add contributing guidelines.
6
+ * Group options into more structured methods in act_macro.rb.
7
+ * Remove dynamic finder code from globalize3, no longer used in AR4.
8
+ * Get hash of translated attributes by calling attribute on model, not translation.
9
+ * Define translation readers/writers in separate methods.
10
+ * Test against AR 4.1 and AR 4.0.
11
+ * Switch to minitest-reporters for colouring output from minitest.
12
+ * Remove find_or_instantiator_by_attributes which is no longer used in AR4.
13
+ * Set I18n.available_locales in tests to avoid deprecation message.
14
+ * Reorganize specs into describe blocks to clarify object of specs.
15
+
16
+ ## 4.0.0.alpha.3 (2013-12-18)
17
+
18
+ * Move ActiveRecord::Relation#where_values_hash patch into globalize relation class to avoid monkeypatching.
19
+ * Add Code Climate Score (thanks [BrandonMathis](https://github.com/BrandonMathis)).
20
+ * Query using Globalize.fallbacks rather than locale only when fetching a record (thanks [@huoxito](https://github.com/huoxito)).
21
+ * Use a module (QueryMethods) rather than a class for overriding functionality of ActiveRecord::Relation.
22
+ * Use ActiveRecord::Relation#extending! to extend ActiveRecord::Base#relation with QueryMethods, works with associations as well.
23
+
24
+ ## 4.0.0.alpha.2 (2013-10-24)
25
+
26
+ * Add license to gemspec.
27
+ * Update references to ActiveRecord 3 -> ActiveRecord.
28
+ * Replace references to globalize3 with globalize and remove references to ActiveRecord 3.x.
29
+ * Document `3-0-stable` branch in readme.
30
+ * Convert test syntax to MiniTest::Spec.
31
+ * Extract easy accessors functionality, moved to new [globalize-accessors](https://github.com/globalize/globalize-accessors) gem.
32
+ * Check that `first` is not nil before reloading translations, fixes [#282](https://github.com/globalize/globalize/issues/282).
33
+ * Duplicate arguments in query finders before modifying them, fixes [#284](https://github.com/globalize/globalize/issues/284).
34
+ * Add test for `find_or_create_by` with translated attribute.
35
+
36
+ ## 4.0.0.alpha.1 (2013-10-9)
37
+
38
+ * Initial release of Rails 4-compatible gem.
39
+
40
+ ## 3.0.3 (2013-12-26)
41
+
42
+ * Ensure that foreign key is always set when saving translations (thanks [Andrew Feng](https://github.com/mingliangfeng)).
43
+ * Patch I18n to add back I18n.interpolate after it was removed (accidentally?) in v0.5.2 (see [svenfuchs/i18n#232](https://github.com/svenfuchs/i18n/issues/232). Hopefully this patch will be temporary.
44
+ * Explicitly test compatibility with FriendlyId to avoid issues like [#306](https://github.com/globalize/globalize/issues/306).
45
+ * Only override ActiveRecord::Base#relation to patch where_values_hash if using AR >= 3.2.1.
46
+
47
+ ## 3.0.2 (2013-12-07)
48
+
49
+ * Alias `ActiveRecord::Base#relation` and include query method overrides as module, fixes [#306](https://github.com/globalize/globalize/issues/306) and [norman/friendly_id#485](https://github.com/norman/friendly_id/issues/485).
50
+
51
+ ## 3.0.1 (2013-11-07)
52
+
53
+ * Move `ActiveRecord::Relation#where_values_hash` patch to Globalize-specific Relation class that inherits from `ActiveRecord::Relation` to fix compatibility issue with Squeel ([#288](https://github.com/globalize/globalize/issues/288)).
54
+ * Use FriendlyId pattern for overriding `ActiveRecord::Base#relation` to avoid conflict.
55
+ * Remove `:null => false` condition on reference to parent model in translation table migration, partial fix for [refinery/refinerycms#2450](https://github.com/refinery/refinerycms/issues/2450).
56
+
57
+ ## 3.0.0 (2013-10-24)
58
+
59
+ * Initial release with new version numbering.
@@ -0,0 +1,37 @@
1
+ # Contributing to Globalize
2
+
3
+ Globalize is a community project, and would not be here today if it were not for the support of the community of [contributors](https://github.com/globalize/globalize/graphs/contributors) that have kept it alive and running. Thank you for your support!
4
+
5
+ ## Bugs
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 (`master` branch) over Rails 3 issues (`3-0-stable` branch).
8
+
9
+ If you also have some idea how to fix the bug, then by all means post a pull request (see below).
10
+
11
+ ## Features
12
+
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
+
15
+ If however your feature would improve the core functionality of Globalize, please do submit a PR, preferably to the `master` branch.
16
+
17
+ ## Refactoring
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 (`master` branch).
20
+
21
+ ## Documentation
22
+
23
+ Globalize needs better documentation. That includes more inline comments explaining clearly what code is doing, as well as reference documentation beyond the [readme](readme.md) -- possibly in the github wiki. Please contact us if you would like to help with documentation.
24
+
25
+ ## Pull Requests
26
+
27
+ Have a bug fix, code improvement or proposed feature? Do the following:
28
+
29
+ 1. Fork the repository.
30
+ 2. Create your feature branch: `git checkout -b my_new_feature`
31
+ 3. Commit your changes: `git commit -am 'Add some new feature'`
32
+ 4. Push to the branch: `git push origin my_new_feature`
33
+ 5. Submit a pull request.
34
+
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
+
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.
@@ -1,75 +1,294 @@
1
+ GIT
2
+ remote: git://github.com/airblade/paper_trail.git
3
+ revision: c4e188c27040888515866660bac94740b92a262b
4
+ branch: master
5
+ specs:
6
+ paper_trail (3.0.0)
7
+ activerecord (>= 3.0, < 5.0)
8
+ activesupport (>= 3.0, < 5.0)
9
+
10
+ GIT
11
+ remote: git://github.com/bmabey/database_cleaner.git
12
+ revision: c0c7885466287dcde3dbac195a5f10df306db098
13
+ branch: master
14
+ specs:
15
+ database_cleaner (1.2.0)
16
+
1
17
  PATH
2
18
  remote: .
3
19
  specs:
4
20
  globalize (4.0.0.alpha.3)
5
21
  activemodel (>= 4.0.0)
6
22
  activerecord (>= 4.0.0)
23
+ paper_trail (~> 3.0.0.beta)
7
24
 
8
25
  GEM
9
26
  remote: https://rubygems.org/
10
27
  specs:
11
- activemodel (4.0.1)
12
- activesupport (= 4.0.1)
28
+ activemodel (4.0.2)
29
+ activesupport (= 4.0.2)
13
30
  builder (~> 3.1.0)
14
- activerecord (4.0.1)
15
- activemodel (= 4.0.1)
31
+ activerecord (4.0.2)
32
+ activemodel (= 4.0.2)
16
33
  activerecord-deprecated_finders (~> 1.0.2)
17
- activesupport (= 4.0.1)
34
+ activesupport (= 4.0.2)
18
35
  arel (~> 4.0.0)
19
36
  activerecord-deprecated_finders (1.0.3)
20
- activesupport (4.0.1)
37
+ activesupport (4.0.2)
21
38
  i18n (~> 0.6, >= 0.6.4)
22
39
  minitest (~> 4.2)
23
40
  multi_json (~> 1.3)
24
41
  thread_safe (~> 0.1)
25
42
  tzinfo (~> 0.3.37)
43
+ ansi (1.4.3)
26
44
  arel (4.0.1)
27
45
  atomic (1.1.14)
28
46
  builder (3.1.4)
29
- coderay (1.0.9)
30
- database_cleaner (1.2.0)
31
- ffi (1.9.3-java)
32
- i18n (0.6.5)
47
+ coderay (1.1.0)
48
+ ffi2-generators (0.1.1)
49
+ hashie (2.0.5)
50
+ i18n (0.6.9)
33
51
  json (1.8.1)
34
- json (1.8.1-java)
35
52
  method_source (0.8.2)
36
53
  minitest (4.7.5)
37
- minitest-colorize (0.0.5)
38
- minitest (>= 2.0)
54
+ minitest-reporters (0.14.23)
55
+ ansi
56
+ builder
57
+ minitest (>= 2.12, < 5.0)
58
+ powerbar
39
59
  multi_json (1.8.2)
40
- pry (0.9.12.2)
41
- coderay (~> 1.0.5)
42
- method_source (~> 0.8)
43
- slop (~> 3.4)
44
- pry (0.9.12.2-java)
45
- coderay (~> 1.0.5)
60
+ powerbar (1.0.11)
61
+ ansi (~> 1.4.0)
62
+ hashie (>= 1.1.0)
63
+ pry (0.9.12.4)
64
+ coderay (~> 1.0)
46
65
  method_source (~> 0.8)
47
66
  slop (~> 3.4)
48
- spoon (~> 0.0)
49
67
  pry-nav (0.2.3)
50
68
  pry (~> 0.9.10)
51
69
  rake (10.1.0)
52
- rdoc (3.12.2)
70
+ rdoc (4.0.1)
53
71
  json (~> 1.4)
54
- slop (3.4.6)
55
- spoon (0.0.4)
56
- ffi
57
- sqlite3 (1.3.7)
72
+ rubysl (2.0.15)
73
+ rubysl-abbrev (~> 2.0)
74
+ rubysl-base64 (~> 2.0)
75
+ rubysl-benchmark (~> 2.0)
76
+ rubysl-bigdecimal (~> 2.0)
77
+ rubysl-cgi (~> 2.0)
78
+ rubysl-cgi-session (~> 2.0)
79
+ rubysl-cmath (~> 2.0)
80
+ rubysl-complex (~> 2.0)
81
+ rubysl-continuation (~> 2.0)
82
+ rubysl-coverage (~> 2.0)
83
+ rubysl-csv (~> 2.0)
84
+ rubysl-curses (~> 2.0)
85
+ rubysl-date (~> 2.0)
86
+ rubysl-delegate (~> 2.0)
87
+ rubysl-digest (~> 2.0)
88
+ rubysl-drb (~> 2.0)
89
+ rubysl-e2mmap (~> 2.0)
90
+ rubysl-english (~> 2.0)
91
+ rubysl-enumerator (~> 2.0)
92
+ rubysl-erb (~> 2.0)
93
+ rubysl-etc (~> 2.0)
94
+ rubysl-expect (~> 2.0)
95
+ rubysl-fcntl (~> 2.0)
96
+ rubysl-fiber (~> 2.0)
97
+ rubysl-fileutils (~> 2.0)
98
+ rubysl-find (~> 2.0)
99
+ rubysl-forwardable (~> 2.0)
100
+ rubysl-getoptlong (~> 2.0)
101
+ rubysl-gserver (~> 2.0)
102
+ rubysl-io-console (~> 2.0)
103
+ rubysl-io-nonblock (~> 2.0)
104
+ rubysl-io-wait (~> 2.0)
105
+ rubysl-ipaddr (~> 2.0)
106
+ rubysl-irb (~> 2.0)
107
+ rubysl-logger (~> 2.0)
108
+ rubysl-mathn (~> 2.0)
109
+ rubysl-matrix (~> 2.0)
110
+ rubysl-mkmf (~> 2.0)
111
+ rubysl-monitor (~> 2.0)
112
+ rubysl-mutex_m (~> 2.0)
113
+ rubysl-net-ftp (~> 2.0)
114
+ rubysl-net-http (~> 2.0)
115
+ rubysl-net-imap (~> 2.0)
116
+ rubysl-net-pop (~> 2.0)
117
+ rubysl-net-protocol (~> 2.0)
118
+ rubysl-net-smtp (~> 2.0)
119
+ rubysl-net-telnet (~> 2.0)
120
+ rubysl-nkf (~> 2.0)
121
+ rubysl-observer (~> 2.0)
122
+ rubysl-open-uri (~> 2.0)
123
+ rubysl-open3 (~> 2.0)
124
+ rubysl-openssl (~> 2.0)
125
+ rubysl-optparse (~> 2.0)
126
+ rubysl-ostruct (~> 2.0)
127
+ rubysl-pathname (~> 2.0)
128
+ rubysl-prettyprint (~> 2.0)
129
+ rubysl-prime (~> 2.0)
130
+ rubysl-profile (~> 2.0)
131
+ rubysl-profiler (~> 2.0)
132
+ rubysl-pstore (~> 2.0)
133
+ rubysl-pty (~> 2.0)
134
+ rubysl-rational (~> 2.0)
135
+ rubysl-readline (~> 2.0)
136
+ rubysl-resolv (~> 2.0)
137
+ rubysl-rexml (~> 2.0)
138
+ rubysl-rinda (~> 2.0)
139
+ rubysl-rss (~> 2.0)
140
+ rubysl-scanf (~> 2.0)
141
+ rubysl-securerandom (~> 2.0)
142
+ rubysl-set (~> 2.0)
143
+ rubysl-shellwords (~> 2.0)
144
+ rubysl-singleton (~> 2.0)
145
+ rubysl-socket (~> 2.0)
146
+ rubysl-stringio (~> 2.0)
147
+ rubysl-strscan (~> 2.0)
148
+ rubysl-sync (~> 2.0)
149
+ rubysl-syslog (~> 2.0)
150
+ rubysl-tempfile (~> 2.0)
151
+ rubysl-thread (~> 2.0)
152
+ rubysl-thwait (~> 2.0)
153
+ rubysl-time (~> 2.0)
154
+ rubysl-timeout (~> 2.0)
155
+ rubysl-tmpdir (~> 2.0)
156
+ rubysl-tsort (~> 2.0)
157
+ rubysl-un (~> 2.0)
158
+ rubysl-uri (~> 2.0)
159
+ rubysl-weakref (~> 2.0)
160
+ rubysl-webrick (~> 2.0)
161
+ rubysl-xmlrpc (~> 2.0)
162
+ rubysl-yaml (~> 2.0)
163
+ rubysl-zlib (~> 2.0)
164
+ rubysl-abbrev (2.0.4)
165
+ rubysl-base64 (2.0.0)
166
+ rubysl-benchmark (2.0.1)
167
+ rubysl-bigdecimal (2.0.2)
168
+ rubysl-cgi (2.0.1)
169
+ rubysl-cgi-session (2.0.1)
170
+ rubysl-cmath (2.0.0)
171
+ rubysl-complex (2.0.0)
172
+ rubysl-continuation (2.0.0)
173
+ rubysl-coverage (2.0.3)
174
+ rubysl-csv (2.0.2)
175
+ rubysl-english (~> 2.0)
176
+ rubysl-curses (2.0.0)
177
+ rubysl-date (2.0.6)
178
+ rubysl-delegate (2.0.1)
179
+ rubysl-digest (2.0.3)
180
+ rubysl-drb (2.0.1)
181
+ rubysl-e2mmap (2.0.0)
182
+ rubysl-english (2.0.0)
183
+ rubysl-enumerator (2.0.0)
184
+ rubysl-erb (2.0.1)
185
+ rubysl-etc (2.0.3)
186
+ ffi2-generators (~> 0.1)
187
+ rubysl-expect (2.0.0)
188
+ rubysl-fcntl (2.0.4)
189
+ ffi2-generators (~> 0.1)
190
+ rubysl-fiber (2.0.0)
191
+ rubysl-fileutils (2.0.3)
192
+ rubysl-find (2.0.1)
193
+ rubysl-forwardable (2.0.1)
194
+ rubysl-getoptlong (2.0.0)
195
+ rubysl-gserver (2.0.0)
196
+ rubysl-socket (~> 2.0)
197
+ rubysl-thread (~> 2.0)
198
+ rubysl-io-console (2.0.0)
199
+ rubysl-io-nonblock (2.0.0)
200
+ rubysl-io-wait (2.0.0)
201
+ rubysl-ipaddr (2.0.0)
202
+ rubysl-irb (2.0.4)
203
+ rubysl-e2mmap (~> 2.0)
204
+ rubysl-mathn (~> 2.0)
205
+ rubysl-readline (~> 2.0)
206
+ rubysl-thread (~> 2.0)
207
+ rubysl-logger (2.0.0)
208
+ rubysl-mathn (2.0.0)
209
+ rubysl-matrix (2.1.0)
210
+ rubysl-e2mmap (~> 2.0)
211
+ rubysl-mkmf (2.0.1)
212
+ rubysl-fileutils (~> 2.0)
213
+ rubysl-shellwords (~> 2.0)
214
+ rubysl-monitor (2.0.0)
215
+ rubysl-mutex_m (2.0.0)
216
+ rubysl-net-ftp (2.0.1)
217
+ rubysl-net-http (2.0.4)
218
+ rubysl-cgi (~> 2.0)
219
+ rubysl-erb (~> 2.0)
220
+ rubysl-singleton (~> 2.0)
221
+ rubysl-net-imap (2.0.1)
222
+ rubysl-net-pop (2.0.1)
223
+ rubysl-net-protocol (2.0.1)
224
+ rubysl-net-smtp (2.0.1)
225
+ rubysl-net-telnet (2.0.0)
226
+ rubysl-nkf (2.0.1)
227
+ rubysl-observer (2.0.0)
228
+ rubysl-open-uri (2.0.0)
229
+ rubysl-open3 (2.0.0)
230
+ rubysl-openssl (2.0.5)
231
+ rubysl-optparse (2.0.1)
232
+ rubysl-shellwords (~> 2.0)
233
+ rubysl-ostruct (2.0.4)
234
+ rubysl-pathname (2.0.0)
235
+ rubysl-prettyprint (2.0.2)
236
+ rubysl-prime (2.0.1)
237
+ rubysl-profile (2.0.0)
238
+ rubysl-profiler (2.0.1)
239
+ rubysl-pstore (2.0.0)
240
+ rubysl-pty (2.0.2)
241
+ rubysl-rational (2.0.1)
242
+ rubysl-readline (2.0.2)
243
+ rubysl-resolv (2.0.0)
244
+ rubysl-rexml (2.0.2)
245
+ rubysl-rinda (2.0.0)
246
+ rubysl-rss (2.0.0)
247
+ rubysl-scanf (2.0.0)
248
+ rubysl-securerandom (2.0.0)
249
+ rubysl-set (2.0.1)
250
+ rubysl-shellwords (2.0.0)
251
+ rubysl-singleton (2.0.0)
252
+ rubysl-socket (2.0.1)
253
+ rubysl-stringio (2.0.0)
254
+ rubysl-strscan (2.0.0)
255
+ rubysl-sync (2.0.0)
256
+ rubysl-syslog (2.0.1)
257
+ ffi2-generators (~> 0.1)
258
+ rubysl-tempfile (2.0.1)
259
+ rubysl-thread (2.0.2)
260
+ rubysl-thwait (2.0.0)
261
+ rubysl-time (2.0.3)
262
+ rubysl-timeout (2.0.0)
263
+ rubysl-tmpdir (2.0.0)
264
+ rubysl-tsort (2.0.1)
265
+ rubysl-un (2.0.0)
266
+ rubysl-fileutils (~> 2.0)
267
+ rubysl-optparse (~> 2.0)
268
+ rubysl-uri (2.0.0)
269
+ rubysl-weakref (2.0.0)
270
+ rubysl-webrick (2.0.0)
271
+ rubysl-xmlrpc (2.0.0)
272
+ rubysl-yaml (2.0.4)
273
+ rubysl-zlib (2.0.1)
274
+ slop (3.4.7)
275
+ sqlite3 (1.3.8)
58
276
  thread_safe (0.1.3)
59
277
  atomic
60
278
  tzinfo (0.3.38)
61
279
 
62
280
  PLATFORMS
63
- java
64
281
  ruby
65
282
 
66
283
  DEPENDENCIES
67
- database_cleaner (>= 1.2.0)
284
+ database_cleaner!
68
285
  globalize!
69
286
  minitest
70
- minitest-colorize
287
+ minitest-reporters
288
+ paper_trail!
71
289
  pry
72
290
  pry-nav
73
291
  rake
74
292
  rdoc
293
+ rubysl (~> 2.0)
75
294
  sqlite3
@@ -2,35 +2,14 @@ module Globalize
2
2
  module ActiveRecord
3
3
  module ActMacro
4
4
  def translates(*attr_names)
5
+ # Bypass setup_translates! if the initial bootstrapping is done already.
6
+ setup_translates!(attr_names.extract_options!) unless translates?
5
7
 
6
- options = attr_names.extract_options!
7
- setup_translates!(options) unless translates?
8
-
8
+ # Add any extra translatable attributes.
9
9
  attr_names = attr_names.map(&:to_sym)
10
10
  attr_names -= translated_attribute_names if defined?(translated_attribute_names)
11
11
 
12
- if attr_names.present?
13
- attr_names.each do |attr_name|
14
- # Detect and apply serialization.
15
- serializer = self.serialized_attributes[attr_name.to_s]
16
- if serializer.present?
17
- if defined?(::ActiveRecord::Coders::YAMLColumn) &&
18
- serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
19
-
20
- serializer = serializer.object_class
21
- end
22
-
23
- translation_class.send :serialize, attr_name, serializer
24
- end
25
-
26
- # Create accessors for the attribute.
27
- translated_attr_accessor(attr_name)
28
- translations_accessor(attr_name)
29
-
30
- # Add attribute to the list.
31
- self.translated_attribute_names << attr_name
32
- end
33
- end
12
+ allow_translation_of_attributes(attr_names) if attr_names.present?
34
13
  end
35
14
 
36
15
  def class_name
@@ -45,7 +24,22 @@ module Globalize
45
24
  end
46
25
 
47
26
  protected
48
- def setup_translates!(options)
27
+
28
+ def allow_translation_of_attributes(attr_names)
29
+ attr_names.each do |attr_name|
30
+ # Detect and apply serialization.
31
+ enable_serializable_attribute(attr_name)
32
+
33
+ # Create accessors for the attribute.
34
+ define_translated_attr_accessor(attr_name)
35
+ define_translations_accessor(attr_name)
36
+
37
+ # Add attribute to the list.
38
+ self.translated_attribute_names << attr_name
39
+ end
40
+ end
41
+
42
+ def apply_globalize_options(options)
49
43
  options[:table_name] ||= "#{table_name.singularize}_translations"
50
44
  options[:foreign_key] ||= class_name.foreign_key
51
45
 
@@ -53,6 +47,23 @@ module Globalize
53
47
  self.translated_attribute_names = []
54
48
  self.translation_options = options
55
49
  self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
50
+ end
51
+
52
+ def enable_serializable_attribute(attr_name)
53
+ serializer = self.serialized_attributes[attr_name.to_s]
54
+ if serializer.present?
55
+ if defined?(::ActiveRecord::Coders::YAMLColumn) &&
56
+ serializer.is_a?(::ActiveRecord::Coders::YAMLColumn)
57
+
58
+ serializer = serializer.object_class
59
+ end
60
+
61
+ translation_class.send :serialize, attr_name, serializer
62
+ end
63
+ end
64
+
65
+ def setup_translates!(options)
66
+ apply_globalize_options(options)
56
67
 
57
68
  include InstanceMethods
58
69
  extend ClassMethods, Migration
@@ -68,15 +79,17 @@ module Globalize
68
79
  after_create :save_translations!
69
80
  after_update :save_translations!
70
81
 
71
- if options[:versioning]
72
- if options[:versioning].is_a?(Hash)
73
- translation_class.versioned options[:versioning]
74
- else
75
- ::ActiveRecord::Base.extend(Globalize::Versioning::PaperTrail)
82
+ setup_globalize_versioning(options[:versioning]) if options[:versioning]
83
+ end
76
84
 
77
- translation_class.has_paper_trail
78
- delegate :version, :versions, :to => :translation
79
- end
85
+ def setup_globalize_versioning(versioning_options)
86
+ if versioning_options.is_a?(Hash)
87
+ translation_class.versioned(versioning_options)
88
+ else
89
+ ::ActiveRecord::Base.extend(Globalize::Versioning::PaperTrail)
90
+
91
+ translation_class.has_paper_trail
92
+ delegate :version, :versions, :to => :translation
80
93
  end
81
94
  end
82
95
  end
@@ -34,11 +34,9 @@ module Globalize
34
34
  end
35
35
 
36
36
  def save_translations!
37
- existing_translations_by_locale = Hash[record.translations.map { |t| [ t.locale, t ] }]
38
-
39
37
  stash.reject {|locale, attrs| attrs.empty?}.each do |locale, attrs|
40
- translation = existing_translations_by_locale[locale] ||
41
- record.translations.build(locale: locale.to_s)
38
+ translation = record.translations_by_locale[locale] ||
39
+ record.translations.build(locale: locale.to_s)
42
40
  attrs.each { |name, value| translation[name] = value }
43
41
  ensure_foreign_key_for(translation)
44
42
  translation.save!
@@ -18,8 +18,7 @@ module Globalize
18
18
  end
19
19
  end
20
20
 
21
- def with_translated_attribute(name, value, locales = nil)
22
- locales ||= Globalize.fallbacks
21
+ def with_translated_attribute(name, value, locales = Globalize.fallbacks)
23
22
  with_translations.where(
24
23
  translated_column_name(name) => value,
25
24
  translated_column_name(:locale) => Array(locales).map(&:to_s)
@@ -58,73 +57,6 @@ module Globalize
58
57
  "#{translation_class.table_name}.#{name}"
59
58
  end
60
59
 
61
- def respond_to_missing?(method_id, include_private = false)
62
- supported_on_missing?(method_id) || super
63
- end
64
-
65
- def supported_on_missing?(method_id)
66
- return super unless respond_to?(:translated_attribute_names)
67
- match = defined?(::ActiveRecord::DynamicFinderMatch) && (::ActiveRecord::DynamicFinderMatch.match(method_id) || ::ActiveRecord::DynamicScopeMatch.match(method_id))
68
- return false if match.nil?
69
-
70
- attribute_names = match.attribute_names.map(&:to_sym)
71
- translated_attributes = attribute_names & translated_attribute_names
72
- return false if translated_attributes.empty?
73
-
74
- untranslated_attributes = attribute_names - translated_attributes
75
- return false if untranslated_attributes.any?{|unt| ! respond_to?(:"scoped_by_#{unt}")}
76
- return [match, attribute_names, translated_attributes, untranslated_attributes]
77
- end
78
-
79
- def method_missing(method_id, *arguments, &block)
80
- match, attribute_names, translated_attributes, untranslated_attributes = supported_on_missing?(method_id)
81
- return super unless match
82
-
83
- scope = all
84
-
85
- translated_attributes.each do |attr|
86
- scope = scope.with_translated_attribute(attr, arguments[attribute_names.index(attr)])
87
- end
88
-
89
- untranslated_attributes.each do |unt|
90
- index = attribute_names.index(unt)
91
- raise StandarError unless index
92
- scope = scope.send(:"scoped_by_#{unt}", arguments[index])
93
- end
94
-
95
- if defined?(::ActiveRecord::DynamicFinderMatch) && match.is_a?(::ActiveRecord::DynamicFinderMatch)
96
- if match.instantiator? && scope.blank?
97
- return scope.find_or_instantiator_by_attributes match, attribute_names, *arguments, &block
98
- end
99
- match_finder_method = match.finder.to_s
100
- match_finder_method << "!" if match.bang?
101
- return scope.send(match_finder_method).tap do |found|
102
- Array(found).map { |f| f.translations.reload } unless found.nil?
103
- end
104
- end
105
- return scope
106
- end
107
-
108
- def find_or_instantiator_by_attributes(match, attributes, *args)
109
- options = args.many? && args.last(2).all?{ |a| a.is_a?(Hash) } ? args.extract_options! : {}
110
- protected_attributes_for_create, unprotected_attributes_for_create = {}, {}
111
- args.each_with_index do |arg, i|
112
- if arg.is_a?(Hash)
113
- protected_attributes_for_create = args[i].with_indifferent_access
114
- else
115
- unprotected_attributes_for_create[attributes[i]] = args[i]
116
- end
117
- end
118
-
119
- record = new(protected_attributes_for_create, options) do |r|
120
- r.assign_attributes(unprotected_attributes_for_create)
121
- end
122
- yield(record) if block_given?
123
- record.send(match.bang? ? :save! : :save) if match.instantiator.eql?(:create)
124
-
125
- record
126
- end
127
-
128
60
  private
129
61
 
130
62
  # Override the default relation method in order to return a subclass
@@ -136,25 +68,34 @@ module Globalize
136
68
 
137
69
  protected
138
70
 
139
- def translated_attr_accessor(name)
140
- define_method(:"#{name}=") do |value|
141
- write_attribute(name, value)
142
- end
71
+ def define_translated_attr_reader(name)
143
72
  define_method(name) do |*args|
144
73
  Globalize::Interpolation.interpolate(name, self, args)
145
74
  end
146
75
  alias_method :"#{name}_before_type_cast", name
147
76
  end
148
77
 
149
- def translations_accessor(name)
78
+ def define_translated_attr_writer(name)
79
+ define_method(:"#{name}=") do |value|
80
+ write_attribute(name, value)
81
+ end
82
+ end
83
+
84
+ def define_translated_attr_accessor(name)
85
+ define_translated_attr_reader(name)
86
+ define_translated_attr_writer(name)
87
+ end
88
+
89
+ def define_translations_reader(name)
150
90
  define_method(:"#{name}_translations") do
151
- result = translations.each_with_object(HashWithIndifferentAccess.new) do |translation, result|
152
- result[translation.locale] = translation.send(name)
153
- end
154
- globalize.stash.keys.each_with_object(result) do |locale, result|
91
+ hash = translated_attribute_by_locale(name)
92
+ globalize.stash.keys.each_with_object(hash) do |locale, result|
155
93
  result[locale] = globalize.fetch_stash(locale, name) if globalize.stash_contains?(locale, name)
156
94
  end
157
95
  end
96
+ end
97
+
98
+ def define_translations_writer(name)
158
99
  define_method(:"#{name}_translations=") do |value|
159
100
  value.each do |(locale, value)|
160
101
  write_attribute name, value, :locale => locale
@@ -162,8 +103,10 @@ module Globalize
162
103
  end
163
104
  end
164
105
 
106
+ def define_translations_accessor(name)
107
+ define_translations_reader(name)
108
+ define_translations_writer(name)
109
+ end
165
110
  end
166
-
167
111
  end
168
-
169
112
  end
@@ -66,11 +66,7 @@ module Globalize
66
66
 
67
67
  def translated_attributes
68
68
  translated_attribute_names.inject({}) do |attributes, name|
69
- if self.respond_to?(name) && Globalize.locale == I18n.default_locale
70
- attributes.merge(name.to_s => self.send(name))
71
- else
72
- attributes.merge(name.to_s => translation.send(name))
73
- end
69
+ attributes.merge(name.to_s => self.send(name))
74
70
  end
75
71
  end
76
72
 
@@ -134,6 +130,16 @@ module Globalize
134
130
  @translation_caches ||= {}
135
131
  end
136
132
 
133
+ def translations_by_locale(&block)
134
+ translations.each_with_object(HashWithIndifferentAccess.new) do |t, hash|
135
+ hash[t.locale] = block_given? ? block.call(t) : t
136
+ end
137
+ end
138
+
139
+ def translated_attribute_by_locale(name)
140
+ translations_by_locale(&:"#{name}")
141
+ end
142
+
137
143
  def globalize_fallbacks(locale)
138
144
  Globalize.fallbacks(locale)
139
145
  end
@@ -62,7 +62,7 @@ module Globalize
62
62
  # It's a problem because in early migrations would add all the translated attributes
63
63
  def complete_translated_fields
64
64
  translated_attribute_names.each do |name|
65
- fields[name] = column_type(name) unless fields[name]
65
+ fields[name] ||= column_type(name)
66
66
  end
67
67
  end
68
68
 
@@ -137,11 +137,8 @@ module Globalize
137
137
  def validate_translated_fields
138
138
  fields.each do |name, options|
139
139
  raise BadFieldName.new(name) unless valid_field_name?(name)
140
- if options.is_a? Hash
141
- raise BadFieldType.new(name, options[:type]) unless valid_field_type?(name, options[:type])
142
- else
143
- raise BadFieldType.new(name, options) unless valid_field_type?(name, options)
144
- end
140
+ type = (options.is_a? Hash) ? options[:type] : options
141
+ raise BadFieldType.new(name, type) unless valid_field_type?(name, type)
145
142
  end
146
143
  end
147
144
 
@@ -60,7 +60,8 @@ module Globalize
60
60
  end
61
61
 
62
62
  def where_values_hash
63
- equalities = with_default_scope.where_values.grep(Arel::Nodes::Equality).find_all { |node|
63
+ equalities = respond_to?(:with_default_scope) ? with_default_scope.where_values : where_values
64
+ equalities = equalities.grep(Arel::Nodes::Equality).find_all { |node|
64
65
  node.left.relation.name == translations_table_name
65
66
  }
66
67
 
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: 4.0.0.alpha.3
4
+ version: 4.0.0.alpha.4
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: 2013-12-18 00:00:00.000000000 Z
17
+ date: 2013-12-30 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -87,7 +87,7 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: minitest-colorize
90
+ name: minitest-reporters
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - '>='
@@ -148,29 +148,31 @@ executables: []
148
148
  extensions: []
149
149
  extra_rdoc_files: []
150
150
  files:
151
- - lib/globalize/active_record/act_macro.rb
152
- - lib/globalize/active_record/adapter.rb
151
+ - lib/globalize/versioning.rb
152
+ - lib/globalize/versioning/paper_trail.rb
153
+ - lib/globalize/interpolation.rb
154
+ - lib/globalize/active_record.rb
153
155
  - lib/globalize/active_record/attributes.rb
154
- - lib/globalize/active_record/class_methods.rb
155
- - lib/globalize/active_record/exceptions.rb
156
156
  - lib/globalize/active_record/instance_methods.rb
157
- - lib/globalize/active_record/migration.rb
158
- - lib/globalize/active_record/query_methods.rb
157
+ - lib/globalize/active_record/adapter.rb
159
158
  - lib/globalize/active_record/translation.rb
160
- - lib/globalize/active_record.rb
161
- - lib/globalize/interpolation.rb
162
- - lib/globalize/versioning/paper_trail.rb
163
- - lib/globalize/versioning.rb
159
+ - lib/globalize/active_record/act_macro.rb
160
+ - lib/globalize/active_record/exceptions.rb
161
+ - lib/globalize/active_record/query_methods.rb
162
+ - lib/globalize/active_record/class_methods.rb
163
+ - lib/globalize/active_record/migration.rb
164
164
  - lib/globalize.rb
165
- - lib/i18n/missing_translations_log_handler.rb
166
165
  - lib/i18n/missing_translations_raise_handler.rb
167
- - lib/patches/active_record/query_method.rb
166
+ - lib/i18n/missing_translations_log_handler.rb
168
167
  - lib/patches/active_record/uniqueness_validator.rb
168
+ - lib/patches/active_record/query_method.rb
169
169
  - lib/patches/active_record/xml_attribute_serializer.rb
170
- - Gemfile
170
+ - CONTRIBUTING.md
171
171
  - Gemfile.lock
172
+ - CHANGELOG.md
172
173
  - LICENSE
173
174
  - Rakefile
175
+ - Gemfile
174
176
  homepage: http://github.com/globalize/globalize
175
177
  licenses:
176
178
  - MIT
@@ -191,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
193
  version: 1.3.1
192
194
  requirements: []
193
195
  rubyforge_project: '[none]'
194
- rubygems_version: 2.0.14
196
+ rubygems_version: 2.0.3
195
197
  signing_key:
196
198
  specification_version: 4
197
199
  summary: Rails I18n de-facto standard library for ActiveRecord model/data translation