globalize-danibachar 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/Appraisals +33 -0
  3. data/CHANGELOG.md +111 -0
  4. data/CONTRIBUTING.md +52 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +22 -0
  7. data/README.md +437 -0
  8. data/Rakefile +55 -0
  9. data/lib/globalize.rb +98 -0
  10. data/lib/globalize/active_record.rb +14 -0
  11. data/lib/globalize/active_record/act_macro.rb +96 -0
  12. data/lib/globalize/active_record/adapter.rb +108 -0
  13. data/lib/globalize/active_record/adapter_dirty.rb +56 -0
  14. data/lib/globalize/active_record/attributes.rb +26 -0
  15. data/lib/globalize/active_record/class_methods.rb +129 -0
  16. data/lib/globalize/active_record/exceptions.rb +13 -0
  17. data/lib/globalize/active_record/instance_methods.rb +246 -0
  18. data/lib/globalize/active_record/migration.rb +215 -0
  19. data/lib/globalize/active_record/translated_attributes_query.rb +181 -0
  20. data/lib/globalize/active_record/translation.rb +45 -0
  21. data/lib/globalize/interpolation.rb +28 -0
  22. data/lib/globalize/version.rb +3 -0
  23. data/lib/i18n/missing_translations_log_handler.rb +41 -0
  24. data/lib/i18n/missing_translations_raise_handler.rb +25 -0
  25. data/lib/patches/active_record/persistence.rb +17 -0
  26. data/lib/patches/active_record/query_method.rb +3 -0
  27. data/lib/patches/active_record/rails4/query_method.rb +35 -0
  28. data/lib/patches/active_record/rails4/serialization.rb +22 -0
  29. data/lib/patches/active_record/rails4/uniqueness_validator.rb +42 -0
  30. data/lib/patches/active_record/rails5/uniqueness_validator.rb +47 -0
  31. data/lib/patches/active_record/rails5_1/serialization.rb +22 -0
  32. data/lib/patches/active_record/rails5_1/uniqueness_validator.rb +45 -0
  33. data/lib/patches/active_record/relation.rb +12 -0
  34. data/lib/patches/active_record/serialization.rb +5 -0
  35. data/lib/patches/active_record/uniqueness_validator.rb +7 -0
  36. data/lib/patches/active_record/xml_attribute_serializer.rb +23 -0
  37. metadata +264 -0
@@ -0,0 +1,47 @@
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
+ finder_table = finder_class.arel_table
9
+ relation = build_relation(finder_class, finder_table, attribute, value).where(locale: Globalize.locale)
10
+ relation = relation.where.not(klass.reflect_on_association(:translations).foreign_key => record.send(:id)) if record.persisted?
11
+
12
+
13
+ translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
14
+ untranslated_scopes = Array(options[:scope]) - translated_scopes
15
+
16
+ relation = relation.joins(:globalized_model) if untranslated_scopes.present?
17
+ untranslated_scopes.each do |scope_item|
18
+ scope_value = record.send(scope_item)
19
+ reflection = klass.reflect_on_association(scope_item)
20
+ if reflection
21
+ scope_value = record.send(reflection.foreign_key)
22
+ scope_item = reflection.foreign_key
23
+ end
24
+ relation = relation.where(find_finder_class_for(record).table_name => { scope_item => scope_value })
25
+ end
26
+
27
+ translated_scopes.each do |scope_item|
28
+ scope_value = record.send(scope_item)
29
+ relation = relation.where(scope_item => scope_value)
30
+ end
31
+ relation = relation.merge(options[:conditions]) if options[:conditions]
32
+
33
+ # if klass.unscoped.with_translations.where(relation).exists?
34
+ if relation.exists?
35
+ error_options = options.except(:case_sensitive, :scope, :conditions)
36
+ error_options[:value] = value
37
+ record.errors.add(attribute, :taken, error_options)
38
+ end
39
+ else
40
+ super(record, attribute, value)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ ActiveRecord::Validations::UniquenessValidator.prepend Globalize::Validations::UniquenessValidator
@@ -0,0 +1,22 @@
1
+ module Globalize
2
+ module AttributeMethods
3
+ module Serialization
4
+ def serialize(attr_name, class_name_or_coder = Object)
5
+ super(attr_name, class_name_or_coder)
6
+
7
+ coder = if class_name_or_coder == ::JSON
8
+ ::ActiveRecord::Coders::JSON
9
+ elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
10
+ class_name_or_coder
11
+ else
12
+ ::ActiveRecord::Coders::YAMLColumn.new(attr_name, class_name_or_coder)
13
+ end
14
+
15
+ self.globalize_serialized_attributes = globalize_serialized_attributes.dup
16
+ self.globalize_serialized_attributes[attr_name] = coder
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, Globalize::AttributeMethods::Serialization)
@@ -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
@@ -0,0 +1,12 @@
1
+ if ::ActiveRecord::VERSION::STRING >= "5.0.0"
2
+ module Globalize
3
+ module Relation
4
+ def where_values_hash(relation_table_name = table_name)
5
+ return super unless respond_to?(:translations_table_name)
6
+ super.merge(super(translations_table_name))
7
+ end
8
+ end
9
+ end
10
+
11
+ ActiveRecord::Relation.prepend Globalize::Relation
12
+ end
@@ -0,0 +1,5 @@
1
+ if ::ActiveRecord::VERSION::STRING < "5.1.0"
2
+ require_relative 'rails4/serialization'
3
+ else
4
+ require_relative 'rails5_1/serialization'
5
+ end
@@ -0,0 +1,7 @@
1
+ if ::ActiveRecord::VERSION::STRING < "5.0.0"
2
+ require_relative 'rails4/uniqueness_validator'
3
+ elsif ::ActiveRecord::VERSION::STRING < "5.1.0"
4
+ require_relative 'rails5/uniqueness_validator'
5
+ else
6
+ require_relative 'rails5_1/uniqueness_validator'
7
+ end
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'active_record/serializers/xml_serializer'
3
+ rescue LoadError
4
+ end
5
+
6
+ module Globalize
7
+ module XmlSerializer
8
+ module Attribute
9
+ def compute_type
10
+ klass = @serializable.class
11
+ if klass.translates? && klass.translated_attribute_names.include?(name.to_sym)
12
+ :string
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ if defined?(ActiveRecord::XmlSerializer)
22
+ ActiveRecord::XmlSerializer::Attribute.send(:prepend, Globalize::XmlSerializer::Attribute)
23
+ end
metadata ADDED
@@ -0,0 +1,264 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: globalize-danibachar
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Sven Fuchs
8
+ - Joshua Harvey
9
+ - Clemens Kofler
10
+ - John-Paul Bader
11
+ - Tomasz Stachewicz
12
+ - Philip Arndt
13
+ - Chris Salzberg
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2019-12-02 00:00:00.000000000 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: activerecord
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '4.2'
26
+ - - "<"
27
+ - !ruby/object:Gem::Version
28
+ version: '5.3'
29
+ type: :runtime
30
+ prerelease: false
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '4.2'
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: '5.3'
39
+ - !ruby/object:Gem::Dependency
40
+ name: activemodel
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '4.2'
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.3'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '4.2'
56
+ - - "<"
57
+ - !ruby/object:Gem::Version
58
+ version: '5.3'
59
+ - !ruby/object:Gem::Dependency
60
+ name: request_store
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '1.0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
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'
87
+ - !ruby/object:Gem::Dependency
88
+ name: database_cleaner
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
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'
115
+ - !ruby/object:Gem::Dependency
116
+ name: minitest
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: minitest-reporters
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: pry
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ - !ruby/object:Gem::Dependency
158
+ name: rake
159
+ requirement: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ type: :development
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
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'
199
+ description: Rails I18n de-facto standard library for ActiveRecord model/data translation.
200
+ email: nobody@globalize-rails.org
201
+ executables: []
202
+ extensions: []
203
+ extra_rdoc_files: []
204
+ files:
205
+ - Appraisals
206
+ - CHANGELOG.md
207
+ - CONTRIBUTING.md
208
+ - Gemfile
209
+ - LICENSE
210
+ - README.md
211
+ - Rakefile
212
+ - lib/globalize.rb
213
+ - lib/globalize/active_record.rb
214
+ - lib/globalize/active_record/act_macro.rb
215
+ - lib/globalize/active_record/adapter.rb
216
+ - lib/globalize/active_record/adapter_dirty.rb
217
+ - lib/globalize/active_record/attributes.rb
218
+ - lib/globalize/active_record/class_methods.rb
219
+ - lib/globalize/active_record/exceptions.rb
220
+ - lib/globalize/active_record/instance_methods.rb
221
+ - lib/globalize/active_record/migration.rb
222
+ - lib/globalize/active_record/translated_attributes_query.rb
223
+ - lib/globalize/active_record/translation.rb
224
+ - lib/globalize/interpolation.rb
225
+ - lib/globalize/version.rb
226
+ - lib/i18n/missing_translations_log_handler.rb
227
+ - lib/i18n/missing_translations_raise_handler.rb
228
+ - lib/patches/active_record/persistence.rb
229
+ - lib/patches/active_record/query_method.rb
230
+ - lib/patches/active_record/rails4/query_method.rb
231
+ - lib/patches/active_record/rails4/serialization.rb
232
+ - lib/patches/active_record/rails4/uniqueness_validator.rb
233
+ - lib/patches/active_record/rails5/uniqueness_validator.rb
234
+ - lib/patches/active_record/rails5_1/serialization.rb
235
+ - lib/patches/active_record/rails5_1/uniqueness_validator.rb
236
+ - lib/patches/active_record/relation.rb
237
+ - lib/patches/active_record/serialization.rb
238
+ - lib/patches/active_record/uniqueness_validator.rb
239
+ - lib/patches/active_record/xml_attribute_serializer.rb
240
+ homepage: http://github.com/globalize/globalize
241
+ licenses:
242
+ - MIT
243
+ metadata: {}
244
+ post_install_message:
245
+ rdoc_options: []
246
+ require_paths:
247
+ - lib
248
+ required_ruby_version: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: 2.0.0
253
+ required_rubygems_version: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ requirements: []
259
+ rubyforge_project: "[none]"
260
+ rubygems_version: 2.6.14
261
+ signing_key:
262
+ specification_version: 4
263
+ summary: Rails I18n de-facto standard library for ActiveRecord model/data translation
264
+ test_files: []