globalize 5.0.1 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +19 -5
- data/Gemfile.lock +97 -47
- data/{readme.md → README.md} +116 -35
- data/Rakefile +33 -0
- data/lib/globalize.rb +11 -5
- data/lib/globalize/active_record.rb +1 -0
- data/lib/globalize/active_record/act_macro.rb +24 -3
- data/lib/globalize/active_record/adapter.rb +10 -11
- data/lib/globalize/active_record/adapter_dirty.rb +54 -0
- data/lib/globalize/active_record/class_methods.rb +15 -6
- data/lib/globalize/active_record/exceptions.rb +1 -7
- data/lib/globalize/active_record/instance_methods.rb +55 -35
- data/lib/globalize/active_record/migration.rb +51 -29
- data/lib/globalize/active_record/query_methods.rb +42 -17
- data/lib/globalize/version.rb +1 -1
- data/lib/patches/active_record/persistence.rb +6 -15
- data/lib/patches/active_record/query_method.rb +2 -34
- data/lib/patches/active_record/rails4/query_method.rb +35 -0
- data/lib/patches/active_record/rails4/uniqueness_validator.rb +42 -0
- data/lib/patches/active_record/rails5/uniqueness_validator.rb +47 -0
- data/lib/patches/active_record/relation.rb +12 -0
- data/lib/patches/active_record/serialization.rb +13 -16
- data/lib/patches/active_record/uniqueness_validator.rb +5 -39
- data/lib/patches/active_record/xml_attribute_serializer.rb +19 -9
- metadata +27 -24
- data/globalize.gemspec +0 -29
@@ -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,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
|
@@ -1,24 +1,21 @@
|
|
1
|
-
module
|
1
|
+
module Globalize
|
2
2
|
module AttributeMethods
|
3
3
|
module Serialization
|
4
|
-
|
4
|
+
def serialize(attr_name, class_name_or_coder = Object)
|
5
|
+
super(attr_name, class_name_or_coder)
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
9
14
|
|
10
|
-
|
11
|
-
Coders::JSON
|
12
|
-
elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
|
13
|
-
class_name_or_coder
|
14
|
-
else
|
15
|
-
Coders::YAMLColumn.new(class_name_or_coder)
|
16
|
-
end
|
17
|
-
|
18
|
-
self.globalize_serialized_attributes[attr_name] = coder
|
19
|
-
end
|
20
|
-
alias_method_chain :serialize, :globalize
|
15
|
+
self.globalize_serialized_attributes[attr_name] = coder
|
21
16
|
end
|
22
17
|
end
|
23
18
|
end
|
24
19
|
end
|
20
|
+
|
21
|
+
ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, Globalize::AttributeMethods::Serialization)
|
@@ -1,39 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
if klass.translates? && klass.translated?(attribute)
|
7
|
-
finder_class = klass.translation_class
|
8
|
-
table = finder_class.arel_table
|
9
|
-
|
10
|
-
relation = build_relation(finder_class, table, attribute, value).and(table[:locale].eq(Globalize.locale))
|
11
|
-
relation = relation.and(table[klass.reflect_on_association(:translations).foreign_key].not_eq(record.send(:id))) if record.persisted?
|
12
|
-
|
13
|
-
translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
|
14
|
-
untranslated_scopes = Array(options[:scope]) - translated_scopes
|
15
|
-
|
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.and(find_finder_class_for(record).arel_table[scope_item].eq(scope_value))
|
24
|
-
end
|
25
|
-
|
26
|
-
translated_scopes.each do |scope_item|
|
27
|
-
scope_value = record.send(scope_item)
|
28
|
-
relation = relation.and(table[scope_item].eq(scope_value))
|
29
|
-
end
|
30
|
-
|
31
|
-
if klass.unscoped.with_translations.where(relation).exists?
|
32
|
-
record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
|
33
|
-
end
|
34
|
-
else
|
35
|
-
validate_each_without_translations(record, attribute, value)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
alias_method_chain :validate_each, :translations
|
39
|
-
end
|
1
|
+
if ::ActiveRecord::VERSION::STRING < "5.0.0"
|
2
|
+
require_relative 'rails4/uniqueness_validator'
|
3
|
+
else
|
4
|
+
require_relative 'rails5/uniqueness_validator'
|
5
|
+
end
|
@@ -1,13 +1,23 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'active_record/serializers/xml_serializer'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
10
17
|
end
|
11
18
|
end
|
12
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
if defined?(ActiveRecord::XmlSerializer)
|
22
|
+
ActiveRecord::XmlSerializer::Attribute.send(:prepend, Globalize::XmlSerializer::Attribute)
|
13
23
|
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.0.
|
4
|
+
version: 5.1.0.beta1
|
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:
|
17
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activerecord
|
@@ -22,56 +22,56 @@ dependencies:
|
|
22
22
|
requirements:
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: 4.2
|
25
|
+
version: '4.2'
|
26
26
|
- - "<"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
28
|
+
version: '5.1'
|
29
29
|
type: :runtime
|
30
30
|
prerelease: false
|
31
31
|
version_requirements: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 4.2
|
35
|
+
version: '4.2'
|
36
36
|
- - "<"
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: '
|
38
|
+
version: '5.1'
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: activemodel
|
41
41
|
requirement: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 4.2
|
45
|
+
version: '4.2'
|
46
46
|
- - "<"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '5.1'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 4.2
|
55
|
+
version: '4.2'
|
56
56
|
- - "<"
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: '
|
58
|
+
version: '5.1'
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: request_store
|
61
61
|
requirement: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
63
|
- - "~>"
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 1.
|
66
|
-
type: :
|
65
|
+
version: '1.0'
|
66
|
+
type: :runtime
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
70
|
- - "~>"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: 1.
|
72
|
+
version: '1.0'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
74
|
+
name: database_cleaner
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
|
-
name: minitest
|
88
|
+
name: minitest
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
91
|
- - ">="
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
|
-
name:
|
102
|
+
name: minitest-reporters
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
@@ -151,12 +151,13 @@ files:
|
|
151
151
|
- Gemfile
|
152
152
|
- Gemfile.lock
|
153
153
|
- LICENSE
|
154
|
+
- README.md
|
154
155
|
- Rakefile
|
155
|
-
- globalize.gemspec
|
156
156
|
- lib/globalize.rb
|
157
157
|
- lib/globalize/active_record.rb
|
158
158
|
- lib/globalize/active_record/act_macro.rb
|
159
159
|
- lib/globalize/active_record/adapter.rb
|
160
|
+
- lib/globalize/active_record/adapter_dirty.rb
|
160
161
|
- lib/globalize/active_record/attributes.rb
|
161
162
|
- lib/globalize/active_record/class_methods.rb
|
162
163
|
- lib/globalize/active_record/exceptions.rb
|
@@ -170,10 +171,13 @@ files:
|
|
170
171
|
- lib/i18n/missing_translations_raise_handler.rb
|
171
172
|
- lib/patches/active_record/persistence.rb
|
172
173
|
- lib/patches/active_record/query_method.rb
|
174
|
+
- lib/patches/active_record/rails4/query_method.rb
|
175
|
+
- lib/patches/active_record/rails4/uniqueness_validator.rb
|
176
|
+
- lib/patches/active_record/rails5/uniqueness_validator.rb
|
177
|
+
- lib/patches/active_record/relation.rb
|
173
178
|
- lib/patches/active_record/serialization.rb
|
174
179
|
- lib/patches/active_record/uniqueness_validator.rb
|
175
180
|
- lib/patches/active_record/xml_attribute_serializer.rb
|
176
|
-
- readme.md
|
177
181
|
homepage: http://github.com/globalize/globalize
|
178
182
|
licenses:
|
179
183
|
- MIT
|
@@ -186,17 +190,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
190
|
requirements:
|
187
191
|
- - ">="
|
188
192
|
- !ruby/object:Gem::Version
|
189
|
-
version:
|
193
|
+
version: 2.0.0
|
190
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
195
|
requirements:
|
192
|
-
- - "
|
196
|
+
- - ">"
|
193
197
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
198
|
+
version: 1.3.1
|
195
199
|
requirements: []
|
196
200
|
rubyforge_project: "[none]"
|
197
|
-
rubygems_version: 2.
|
201
|
+
rubygems_version: 2.6.8
|
198
202
|
signing_key:
|
199
203
|
specification_version: 4
|
200
204
|
summary: Rails I18n de-facto standard library for ActiveRecord model/data translation
|
201
205
|
test_files: []
|
202
|
-
has_rdoc:
|
data/globalize.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path('../lib/globalize/version', __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = 'globalize'
|
5
|
-
s.version = Globalize::Version
|
6
|
-
s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Clemens Kofler', 'John-Paul Bader', 'Tomasz Stachewicz', 'Philip Arndt', 'Chris Salzberg']
|
7
|
-
s.email = 'nobody@globalize-rails.org'
|
8
|
-
s.homepage = 'http://github.com/globalize/globalize'
|
9
|
-
s.summary = 'Rails I18n de-facto standard library for ActiveRecord model/data translation'
|
10
|
-
s.description = "#{s.summary}."
|
11
|
-
s.license = "MIT"
|
12
|
-
|
13
|
-
s.files = Dir['{lib/**/*,[A-Z]*}']
|
14
|
-
s.platform = Gem::Platform::RUBY
|
15
|
-
s.require_path = 'lib'
|
16
|
-
s.rubyforge_project = '[none]'
|
17
|
-
|
18
|
-
s.add_dependency 'activerecord', '>= 4.2.0', '< 4.3'
|
19
|
-
s.add_dependency 'activemodel', '>= 4.2.0', '< 4.3'
|
20
|
-
|
21
|
-
s.add_development_dependency 'database_cleaner', '~> 1.4.0'
|
22
|
-
s.add_development_dependency 'minitest'
|
23
|
-
s.add_development_dependency 'minitest-reporters'
|
24
|
-
|
25
|
-
s.add_development_dependency 'sqlite3'
|
26
|
-
s.add_development_dependency 'rdoc'
|
27
|
-
|
28
|
-
s.add_development_dependency 'rake'
|
29
|
-
end
|