globalize 6.3.0 → 7.0.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +2 -13
  3. data/CHANGELOG.md +8 -1
  4. data/CONTRIBUTING.md +2 -4
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +45 -43
  7. data/README.md +37 -47
  8. data/Rakefile +22 -17
  9. data/lib/globalize/active_record/act_macro.rb +20 -22
  10. data/lib/globalize/active_record/adapter_dirty.rb +2 -11
  11. data/lib/globalize/active_record/class_methods.rb +7 -8
  12. data/lib/globalize/active_record/instance_methods.rb +21 -56
  13. data/lib/globalize/active_record/migration.rb +7 -21
  14. data/lib/globalize/active_record/translated_attributes_query.rb +0 -17
  15. data/lib/globalize/version.rb +1 -1
  16. data/lib/globalize.rb +14 -34
  17. data/lib/patches/active_record/rails7_1/serialization.rb +28 -0
  18. data/lib/patches/active_record/rails7_2/serialization.rb +15 -0
  19. data/lib/patches/active_record/relation.rb +11 -15
  20. data/lib/patches/active_record/serialization.rb +5 -5
  21. data/lib/patches/active_record/uniqueness_validator.rb +1 -9
  22. data/lib/patches/active_support/inflections.rb +8 -10
  23. metadata +38 -54
  24. checksums.yaml.gz.sig +0 -0
  25. data/docker-compose.yml +0 -22
  26. data/globalize.gemspec +0 -37
  27. data/issue_template.rb +0 -38
  28. data/lib/patches/active_record/query_method.rb +0 -3
  29. data/lib/patches/active_record/rails4/query_method.rb +0 -35
  30. data/lib/patches/active_record/rails4/serialization.rb +0 -22
  31. data/lib/patches/active_record/rails4/uniqueness_validator.rb +0 -42
  32. data/lib/patches/active_record/rails5/uniqueness_validator.rb +0 -47
  33. data/lib/patches/active_record/rails5_1/serialization.rb +0 -22
  34. data/lib/patches/active_record/rails5_1/uniqueness_validator.rb +0 -45
  35. data.tar.gz.sig +0 -0
  36. metadata.gz.sig +0 -3
@@ -1,35 +0,0 @@
1
- require 'active_record/attribute_methods/query'
2
-
3
- module ActiveRecord
4
- module AttributeMethods
5
- module Query
6
- def query_attribute(attr_name)
7
- unless value = read_attribute(attr_name)
8
- false
9
- else
10
- column = self.class.columns_hash[attr_name]
11
- if column.nil?
12
-
13
- # TODO submit a rails patch
14
-
15
- # not sure what active_record tests say but i guess this should mean:
16
- # call to_i and check zero? if the value is a Numeric or starts with
17
- # a digit, so it can meaningfully be typecasted by to_i
18
-
19
- # if Numeric === value || value !~ /[^0-9]/
20
- if Numeric === value || value.to_s =~ /^[0-9]/
21
- !value.to_i.zero?
22
- else
23
- return false if ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(value)
24
- !value.blank?
25
- end
26
- elsif column.number?
27
- !value.zero?
28
- else
29
- !value.blank?
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,22 +0,0 @@
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(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)
@@ -1,42 +0,0 @@
1
- require 'active_record/validations/uniqueness.rb'
2
-
3
- module Globalize
4
- module UniquenessValidatorOverride
5
- def validate_each(record, attribute, value)
6
- klass = record.class
7
- if klass.translates? && klass.translated?(attribute)
8
- finder_class = klass.translation_class
9
- table = finder_class.arel_table
10
-
11
- relation = build_relation(finder_class, table, attribute, value).and(table[:locale].eq(Globalize.locale))
12
- relation = relation.and(table[klass.reflect_on_association(:translations).foreign_key].not_eq(record.send(:id))) if record.persisted?
13
-
14
- translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
15
- untranslated_scopes = Array(options[:scope]) - translated_scopes
16
-
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.and(find_finder_class_for(record).arel_table[scope_item].eq(scope_value))
25
- end
26
-
27
- translated_scopes.each do |scope_item|
28
- scope_value = record.send(scope_item)
29
- relation = relation.and(table[scope_item].eq(scope_value))
30
- end
31
-
32
- if klass.unscoped.with_translations.where(relation).exists?
33
- record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
34
- end
35
- else
36
- super
37
- end
38
- end
39
- end
40
- end
41
-
42
- ActiveRecord::Validations::UniquenessValidator.send :prepend, Globalize::UniquenessValidatorOverride
@@ -1,47 +0,0 @@
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
@@ -1,22 +0,0 @@
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)
@@ -1,45 +0,0 @@
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
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
@@ -1,3 +0,0 @@
1
- (��8鿐3� H87�D��&�� H&��3�B�d�8�o
2
- ��kޓ��9��r�V�⦄�C3/ˣ)\3�*���Z��3\a�6����u\�A7���q�&��$ �:��j�_q�^X}r;3Q��<�a�Eޡ�i��l�:��{��\��+�M������:�U�Y
3
- NW�P���&���7 \�_���u�n����ʶ�ְ��GS]\���"���.~hϕV�>�8[�n��N���-�w8M��.YI2X-��T��c wQQ��ΰ���yQ�d�v^�