globalize 3.1.0 → 4.0.0.alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a7277cc277d951acb6abb3155ab2ca669708384
4
+ data.tar.gz: 3e1d2c05304f27a6e8cafc15720c2b63a919bdd0
5
+ SHA512:
6
+ metadata.gz: 8cf307368905fe9763cdcb5ef22380574ee9cbeb496439195e92d52ca3ca7dae856d215f7837c9f9446644b291ba0a0d3f846ef3ff99f5d3f3761c6f09ca1ea6
7
+ data.tar.gz: a52cfb6625bf02643cf985d2468965f17f07dffc8cc6bd197167795b6ddac11f64af8b3de010258a1cff6b0f8c41713f8f52ff314a41ee34d84878e989e03f68
data/Gemfile CHANGED
@@ -2,8 +2,12 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- platforms :rbx do
6
- gem 'rubysl', '~> 2.0'
7
- gem 'minitest'
8
- gem 'test-unit'
5
+ # forking off airblade/paper_trail to use the rails4 branch.
6
+ gem 'paper_trail', github: 'airblade/paper_trail', branch: 'master'
7
+ # Per https://github.com/bmabey/database_cleaner/issues/224
8
+ gem 'database_cleaner', github: 'bmabey/database_cleaner', branch: 'master'
9
+
10
+ group :test do
11
+ gem 'pry'
12
+ gem 'pry-nav'
9
13
  end
data/Gemfile.lock CHANGED
@@ -1,261 +1,94 @@
1
+ GIT
2
+ remote: git://github.com/airblade/paper_trail.git
3
+ revision: 41d1b5cd65d7789a9e69e42ae058e71c4747a81d
4
+ branch: master
5
+ specs:
6
+ paper_trail (3.0.0.beta1)
7
+ activerecord (>= 3.0, < 5.0)
8
+
9
+ GIT
10
+ remote: git://github.com/bmabey/database_cleaner.git
11
+ revision: 1ce7c9989acd4815621fe9a007fc4b759a37b239
12
+ branch: master
13
+ specs:
14
+ database_cleaner (1.1.1)
15
+
1
16
  PATH
2
17
  remote: .
3
18
  specs:
4
- globalize (3.0.4)
5
- activemodel (>= 3.0.0, < 4.0.0)
6
- activerecord (>= 3.0.0, < 4.0.0)
19
+ globalize (4.0.0.alpha.1)
20
+ activemodel (>= 4.0.0)
21
+ activerecord (>= 4.0.0)
22
+ paper_trail (~> 3.0.0.beta)
7
23
 
8
24
  GEM
9
25
  remote: https://rubygems.org/
10
26
  specs:
11
- activemodel (3.2.16)
12
- activesupport (= 3.2.16)
13
- builder (~> 3.0.0)
14
- activerecord (3.2.16)
15
- activemodel (= 3.2.16)
16
- activesupport (= 3.2.16)
17
- arel (~> 3.0.2)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.2.16)
27
+ activemodel (4.0.0)
28
+ activesupport (= 4.0.0)
29
+ builder (~> 3.1.0)
30
+ activerecord (4.0.0)
31
+ activemodel (= 4.0.0)
32
+ activerecord-deprecated_finders (~> 1.0.2)
33
+ activesupport (= 4.0.0)
34
+ arel (~> 4.0.0)
35
+ activerecord-deprecated_finders (1.0.3)
36
+ activesupport (4.0.0)
20
37
  i18n (~> 0.6, >= 0.6.4)
21
- multi_json (~> 1.0)
22
- arel (3.0.3)
23
- builder (3.0.4)
24
- database_cleaner (0.6.7)
25
- ffi2-generators (0.1.1)
26
- friendly_id (4.0.10.1)
27
- activerecord (>= 3.0, < 4.0)
28
- i18n (0.6.9)
29
- json (1.8.1)
30
- metaclass (0.0.1)
38
+ minitest (~> 4.2)
39
+ multi_json (~> 1.3)
40
+ thread_safe (~> 0.1)
41
+ tzinfo (~> 0.3.37)
42
+ arel (4.0.0)
43
+ atomic (1.1.14)
44
+ atomic (1.1.14-java)
45
+ builder (3.1.4)
46
+ coderay (1.0.9)
47
+ ffi (1.9.0-java)
48
+ i18n (0.6.5)
49
+ json (1.8.0)
50
+ json (1.8.0-java)
51
+ method_source (0.8.2)
31
52
  minitest (4.7.5)
32
- mocha (0.14.0)
33
- metaclass (~> 0.0.1)
34
- multi_json (1.8.2)
35
- pathname_local (0.0.2)
36
- rake (10.1.1)
37
- rdoc (4.1.0)
53
+ minitest-colorize (0.0.5)
54
+ minitest (>= 2.0)
55
+ multi_json (1.8.1)
56
+ pry (0.9.12.2)
57
+ coderay (~> 1.0.5)
58
+ method_source (~> 0.8)
59
+ slop (~> 3.4)
60
+ pry (0.9.12.2-java)
61
+ coderay (~> 1.0.5)
62
+ method_source (~> 0.8)
63
+ slop (~> 3.4)
64
+ spoon (~> 0.0)
65
+ pry-nav (0.2.3)
66
+ pry (~> 0.9.10)
67
+ rake (10.1.0)
68
+ rdoc (3.12.2)
38
69
  json (~> 1.4)
39
- rubysl (2.0.15)
40
- rubysl-abbrev (~> 2.0)
41
- rubysl-base64 (~> 2.0)
42
- rubysl-benchmark (~> 2.0)
43
- rubysl-bigdecimal (~> 2.0)
44
- rubysl-cgi (~> 2.0)
45
- rubysl-cgi-session (~> 2.0)
46
- rubysl-cmath (~> 2.0)
47
- rubysl-complex (~> 2.0)
48
- rubysl-continuation (~> 2.0)
49
- rubysl-coverage (~> 2.0)
50
- rubysl-csv (~> 2.0)
51
- rubysl-curses (~> 2.0)
52
- rubysl-date (~> 2.0)
53
- rubysl-delegate (~> 2.0)
54
- rubysl-digest (~> 2.0)
55
- rubysl-drb (~> 2.0)
56
- rubysl-e2mmap (~> 2.0)
57
- rubysl-english (~> 2.0)
58
- rubysl-enumerator (~> 2.0)
59
- rubysl-erb (~> 2.0)
60
- rubysl-etc (~> 2.0)
61
- rubysl-expect (~> 2.0)
62
- rubysl-fcntl (~> 2.0)
63
- rubysl-fiber (~> 2.0)
64
- rubysl-fileutils (~> 2.0)
65
- rubysl-find (~> 2.0)
66
- rubysl-forwardable (~> 2.0)
67
- rubysl-getoptlong (~> 2.0)
68
- rubysl-gserver (~> 2.0)
69
- rubysl-io-console (~> 2.0)
70
- rubysl-io-nonblock (~> 2.0)
71
- rubysl-io-wait (~> 2.0)
72
- rubysl-ipaddr (~> 2.0)
73
- rubysl-irb (~> 2.0)
74
- rubysl-logger (~> 2.0)
75
- rubysl-mathn (~> 2.0)
76
- rubysl-matrix (~> 2.0)
77
- rubysl-mkmf (~> 2.0)
78
- rubysl-monitor (~> 2.0)
79
- rubysl-mutex_m (~> 2.0)
80
- rubysl-net-ftp (~> 2.0)
81
- rubysl-net-http (~> 2.0)
82
- rubysl-net-imap (~> 2.0)
83
- rubysl-net-pop (~> 2.0)
84
- rubysl-net-protocol (~> 2.0)
85
- rubysl-net-smtp (~> 2.0)
86
- rubysl-net-telnet (~> 2.0)
87
- rubysl-nkf (~> 2.0)
88
- rubysl-observer (~> 2.0)
89
- rubysl-open-uri (~> 2.0)
90
- rubysl-open3 (~> 2.0)
91
- rubysl-openssl (~> 2.0)
92
- rubysl-optparse (~> 2.0)
93
- rubysl-ostruct (~> 2.0)
94
- rubysl-pathname (~> 2.0)
95
- rubysl-prettyprint (~> 2.0)
96
- rubysl-prime (~> 2.0)
97
- rubysl-profile (~> 2.0)
98
- rubysl-profiler (~> 2.0)
99
- rubysl-pstore (~> 2.0)
100
- rubysl-pty (~> 2.0)
101
- rubysl-rational (~> 2.0)
102
- rubysl-readline (~> 2.0)
103
- rubysl-resolv (~> 2.0)
104
- rubysl-rexml (~> 2.0)
105
- rubysl-rinda (~> 2.0)
106
- rubysl-rss (~> 2.0)
107
- rubysl-scanf (~> 2.0)
108
- rubysl-securerandom (~> 2.0)
109
- rubysl-set (~> 2.0)
110
- rubysl-shellwords (~> 2.0)
111
- rubysl-singleton (~> 2.0)
112
- rubysl-socket (~> 2.0)
113
- rubysl-stringio (~> 2.0)
114
- rubysl-strscan (~> 2.0)
115
- rubysl-sync (~> 2.0)
116
- rubysl-syslog (~> 2.0)
117
- rubysl-tempfile (~> 2.0)
118
- rubysl-thread (~> 2.0)
119
- rubysl-thwait (~> 2.0)
120
- rubysl-time (~> 2.0)
121
- rubysl-timeout (~> 2.0)
122
- rubysl-tmpdir (~> 2.0)
123
- rubysl-tsort (~> 2.0)
124
- rubysl-un (~> 2.0)
125
- rubysl-uri (~> 2.0)
126
- rubysl-weakref (~> 2.0)
127
- rubysl-webrick (~> 2.0)
128
- rubysl-xmlrpc (~> 2.0)
129
- rubysl-yaml (~> 2.0)
130
- rubysl-zlib (~> 2.0)
131
- rubysl-abbrev (2.0.4)
132
- rubysl-base64 (2.0.0)
133
- rubysl-benchmark (2.0.1)
134
- rubysl-bigdecimal (2.0.2)
135
- rubysl-cgi (2.0.1)
136
- rubysl-cgi-session (2.0.1)
137
- rubysl-cmath (2.0.0)
138
- rubysl-complex (2.0.0)
139
- rubysl-continuation (2.0.0)
140
- rubysl-coverage (2.0.3)
141
- rubysl-csv (2.0.2)
142
- rubysl-english (~> 2.0)
143
- rubysl-curses (2.0.1)
144
- rubysl-date (2.0.6)
145
- rubysl-delegate (2.0.1)
146
- rubysl-digest (2.0.3)
147
- rubysl-drb (2.0.1)
148
- rubysl-e2mmap (2.0.0)
149
- rubysl-english (2.0.0)
150
- rubysl-enumerator (2.0.0)
151
- rubysl-erb (2.0.1)
152
- rubysl-etc (2.0.3)
153
- ffi2-generators (~> 0.1)
154
- rubysl-expect (2.0.0)
155
- rubysl-fcntl (2.0.4)
156
- ffi2-generators (~> 0.1)
157
- rubysl-fiber (2.0.0)
158
- rubysl-fileutils (2.0.3)
159
- rubysl-find (2.0.1)
160
- rubysl-forwardable (2.0.1)
161
- rubysl-getoptlong (2.0.0)
162
- rubysl-gserver (2.0.0)
163
- rubysl-socket (~> 2.0)
164
- rubysl-thread (~> 2.0)
165
- rubysl-io-console (2.0.0)
166
- rubysl-io-nonblock (2.0.0)
167
- rubysl-io-wait (2.0.0)
168
- rubysl-ipaddr (2.0.0)
169
- rubysl-irb (2.0.4)
170
- rubysl-e2mmap (~> 2.0)
171
- rubysl-mathn (~> 2.0)
172
- rubysl-readline (~> 2.0)
173
- rubysl-thread (~> 2.0)
174
- rubysl-logger (2.0.0)
175
- rubysl-mathn (2.0.0)
176
- rubysl-matrix (2.1.0)
177
- rubysl-e2mmap (~> 2.0)
178
- rubysl-mkmf (2.0.1)
179
- rubysl-fileutils (~> 2.0)
180
- rubysl-shellwords (~> 2.0)
181
- rubysl-monitor (2.0.0)
182
- rubysl-mutex_m (2.0.0)
183
- rubysl-net-ftp (2.0.1)
184
- rubysl-net-http (2.0.4)
185
- rubysl-cgi (~> 2.0)
186
- rubysl-erb (~> 2.0)
187
- rubysl-singleton (~> 2.0)
188
- rubysl-net-imap (2.0.1)
189
- rubysl-net-pop (2.0.1)
190
- rubysl-net-protocol (2.0.1)
191
- rubysl-net-smtp (2.0.1)
192
- rubysl-net-telnet (2.0.0)
193
- rubysl-nkf (2.0.1)
194
- rubysl-observer (2.0.0)
195
- rubysl-open-uri (2.0.0)
196
- rubysl-open3 (2.0.0)
197
- rubysl-openssl (2.0.5)
198
- rubysl-optparse (2.0.1)
199
- rubysl-shellwords (~> 2.0)
200
- rubysl-ostruct (2.0.4)
201
- rubysl-pathname (2.0.0)
202
- rubysl-prettyprint (2.0.2)
203
- rubysl-prime (2.0.1)
204
- rubysl-profile (2.0.0)
205
- rubysl-profiler (2.0.1)
206
- rubysl-pstore (2.0.0)
207
- rubysl-pty (2.0.2)
208
- rubysl-rational (2.0.1)
209
- rubysl-readline (2.0.2)
210
- rubysl-resolv (2.0.0)
211
- rubysl-rexml (2.0.2)
212
- rubysl-rinda (2.0.0)
213
- rubysl-rss (2.0.0)
214
- rubysl-scanf (2.0.0)
215
- rubysl-securerandom (2.0.0)
216
- rubysl-set (2.0.1)
217
- rubysl-shellwords (2.0.0)
218
- rubysl-singleton (2.0.0)
219
- rubysl-socket (2.0.1)
220
- rubysl-stringio (2.0.0)
221
- rubysl-strscan (2.0.0)
222
- rubysl-sync (2.0.0)
223
- rubysl-syslog (2.0.1)
224
- ffi2-generators (~> 0.1)
225
- rubysl-tempfile (2.0.1)
226
- rubysl-thread (2.0.2)
227
- rubysl-thwait (2.0.0)
228
- rubysl-time (2.0.3)
229
- rubysl-timeout (2.0.0)
230
- rubysl-tmpdir (2.0.0)
231
- rubysl-tsort (2.0.1)
232
- rubysl-un (2.0.0)
233
- rubysl-fileutils (~> 2.0)
234
- rubysl-optparse (~> 2.0)
235
- rubysl-uri (2.0.0)
236
- rubysl-weakref (2.0.0)
237
- rubysl-webrick (2.0.0)
238
- rubysl-xmlrpc (2.0.0)
239
- rubysl-yaml (2.0.4)
240
- rubysl-zlib (2.0.1)
241
- sqlite3 (1.3.8)
242
- test-unit (2.0.0.0)
243
- test_declarative (0.0.5)
244
- tzinfo (0.3.38)
70
+ slop (3.4.6)
71
+ spoon (0.0.4)
72
+ ffi
73
+ sqlite3 (1.3.7)
74
+ thread_safe (0.1.3)
75
+ atomic
76
+ thread_safe (0.1.3-java)
77
+ atomic
78
+ tzinfo (0.3.37)
245
79
 
246
80
  PLATFORMS
81
+ java
247
82
  ruby
248
83
 
249
84
  DEPENDENCIES
250
- database_cleaner (~> 0.6.0)
251
- friendly_id
85
+ database_cleaner!
252
86
  globalize!
253
87
  minitest
254
- mocha
255
- pathname_local
88
+ minitest-colorize
89
+ paper_trail!
90
+ pry
91
+ pry-nav
256
92
  rake
257
93
  rdoc
258
- rubysl (~> 2.0)
259
94
  sqlite3
260
- test-unit
261
- test_declarative
data/lib/globalize.rb CHANGED
@@ -2,14 +2,11 @@ require 'active_record'
2
2
  require 'patches/active_record/xml_attribute_serializer'
3
3
  require 'patches/active_record/query_method'
4
4
  require 'patches/active_record/uniqueness_validator'
5
-
6
- # until https://github.com/svenfuchs/i18n/issues/232 is resolved
7
- unless I18n.respond_to?(:interpolate)
8
- require 'patches/i18n/interpolate'
9
- end
5
+ require 'patches/active_record/relation'
10
6
 
11
7
  module Globalize
12
8
  autoload :ActiveRecord, 'globalize/active_record'
9
+ autoload :Versioning, 'globalize/versioning'
13
10
  autoload :Interpolation, 'globalize/interpolation'
14
11
 
15
12
  class << self
@@ -8,6 +8,6 @@ module Globalize
8
8
  autoload :InstanceMethods, 'globalize/active_record/instance_methods'
9
9
  autoload :Migration, 'globalize/active_record/migration'
10
10
  autoload :Translation, 'globalize/active_record/translation'
11
- autoload :QueryMethods, 'globalize/active_record/query_methods'
11
+ autoload :Relation, 'globalize/active_record/relation'
12
12
  end
13
13
  end
@@ -10,10 +10,6 @@ module Globalize
10
10
  attr_names -= translated_attribute_names if defined?(translated_attribute_names)
11
11
 
12
12
  if attr_names.present?
13
- translation_class.instance_eval %{
14
- attr_accessible :#{attr_names.join(', :')}
15
- }
16
-
17
13
  attr_names.each do |attr_name|
18
14
  # Detect and apply serialization.
19
15
  serializer = self.serialized_attributes[attr_name.to_s]
@@ -58,11 +54,6 @@ module Globalize
58
54
  self.translation_options = options
59
55
  self.fallbacks_for_empty_translations = options[:fallbacks_for_empty_translations]
60
56
 
61
- # Alias original relation method so we can safely override it in ClassMethods.
62
- class << self
63
- alias relation_without_globalize relation
64
- end
65
-
66
57
  include InstanceMethods
67
58
  extend ClassMethods, Migration
68
59
 
@@ -77,7 +68,16 @@ module Globalize
77
68
  after_create :save_translations!
78
69
  after_update :save_translations!
79
70
 
80
- translation_class.instance_eval %{ attr_accessible :locale }
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)
76
+
77
+ translation_class.has_paper_trail
78
+ delegate :version, :versions, :to => :translation
79
+ end
80
+ end
81
81
  end
82
82
  end
83
83
 
@@ -9,19 +9,16 @@ module Globalize
9
9
  delegate :translation_class, :to => :'record.class'
10
10
 
11
11
  def initialize(record)
12
- self.record = record
13
- self.stash = Attributes.new
12
+ @record = record
13
+ @stash = Attributes.new
14
14
  end
15
15
 
16
16
  def fetch_stash(locale, name)
17
- value = stash.read(locale, name)
18
- return value if value
19
- return nil
17
+ stash.read(locale, name)
20
18
  end
21
19
 
22
- def stash_contains?(locale, name)
23
- stash.contains?(locale, name)
24
- end
20
+ delegate :contains?, :to => :stash, :prefix => :stash
21
+ delegate :write, :to => :stash
25
22
 
26
23
  def fetch(locale, name)
27
24
  record.globalize_fallbacks(locale).each do |fallback|
@@ -36,19 +33,12 @@ module Globalize
36
33
  return nil
37
34
  end
38
35
 
39
- def write(locale, name, value)
40
- stash.write(locale, name, value)
41
- end
42
-
43
36
  def save_translations!
44
- existing_translations_by_locale = {}
45
- record.translations.each do |t|
46
- existing_translations_by_locale[t.locale.to_s] = t
47
- end
48
-
37
+ existing_translations_by_locale = Hash[record.translations.map { |t| [ t.locale, t ] }]
38
+
49
39
  stash.reject {|locale, attrs| attrs.empty?}.each do |locale, attrs|
50
- translation = existing_translations_by_locale[locale.to_s] ||
51
- record.translations.build(:locale => locale.to_s)
40
+ translation = existing_translations_by_locale[locale] ||
41
+ record.translations.build(locale: locale.to_s)
52
42
  attrs.each { |name, value| translation[name] = value }
53
43
  ensure_foreign_key_for(translation)
54
44
  translation.save!
@@ -65,17 +55,13 @@ module Globalize
65
55
 
66
56
  def ensure_foreign_key_for(translation)
67
57
  # Sometimes the translation is initialised before a foreign key can be set.
68
- translation[record.class.translation_options[:foreign_key]] = record.id
58
+ translation[translation.reflections[:globalized_model].foreign_key] = record.id
69
59
  end
70
60
 
71
61
  def type_cast(name, value)
72
- if value.nil?
73
- nil
74
- elsif column = column_for_attribute(name)
75
- column.type_cast(value)
76
- else
77
- value
78
- end
62
+ return value.presence unless column = column_for_attribute(name)
63
+
64
+ column.type_cast value
79
65
  end
80
66
 
81
67
  def column_for_attribute(name)
@@ -106,9 +92,7 @@ module Globalize
106
92
  object.nil? || (fallbacks_for_empty_translations? && object.blank?)
107
93
  end
108
94
 
109
- def fallbacks_for_empty_translations?
110
- record.fallbacks_for_empty_translations
111
- end
95
+ delegate :fallbacks_for_empty_translations?, :to => :record, :prefix => false
112
96
  end
113
97
  end
114
98
  end