mobility 1.2.9 → 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +20 -1
- data/Gemfile.lock +5 -21
- data/README.md +1 -1
- data/lib/mobility/backends/active_record/container.rb +20 -28
- data/lib/mobility/backends/active_record/key_value.rb +1 -1
- data/lib/mobility/backends/active_record/pg_hash.rb +13 -22
- data/lib/mobility/backends/active_record/table.rb +1 -1
- data/lib/mobility/plugins/backend.rb +1 -1
- data/lib/mobility/plugins/fallthrough_accessors.rb +1 -1
- data/lib/mobility/version.rb +3 -3
- data/lib/rails/generators/mobility/templates/initializer.rb +13 -0
- data.tar.gz.sig +0 -0
- metadata +33 -32
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a89e6682c14088be7f337e5a03c5b510a67dd7a93ee88024f3686f9bfc4694e
|
4
|
+
data.tar.gz: c5a99fc2000e05d2d3ccc3ff9d6dd00357dc3b5ace57d7c92782b2601bd32e51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f60e92ede85fc444d4151a14c833a13ced95c1e2f073fafa024aa967de01810e5b2b6ccfc4365c5d338679d1899573ec2921453ce44dcdc9736fde749ad650ed
|
7
|
+
data.tar.gz: 21319dd41e1025a82545a08da30fcafd38d5bc61c86bdcfe2b017b195d670a9a503fbff8101a7897b99fe32e3c0bf19666bd0c86f06887fb697a8bce132b6253
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Mobility Changelog
|
2
2
|
|
3
|
+
## 1.3
|
4
|
+
|
5
|
+
### 1.3.0.rc1
|
6
|
+
|
7
|
+
This version includes potentially breaking chnages for jsonb and hstore
|
8
|
+
backends. See PRs below for details.
|
9
|
+
|
10
|
+
- Fix ActiveRecord JSONB blank values
|
11
|
+
([#536](https://github.com/shioyama/mobility/pull/536))
|
12
|
+
- Support primary keys other then :id on model classes
|
13
|
+
([#542](https://github.com/shioyama/mobility/pull/542))
|
14
|
+
- Clean up and refactor container backend
|
15
|
+
([#543](https://github.com/shioyama/mobility/pull/543)),
|
16
|
+
thanks [doits](https://github.com/doits)!
|
17
|
+
- Update fallthrough_accessor regex to allow for ISO 639-2 codes
|
18
|
+
([#580](https://github.com/shioyama/mobility/pull/580))
|
19
|
+
thanks [phil-allcock](https://github.com/phil-allcock)!
|
20
|
+
|
3
21
|
## 1.2
|
4
22
|
|
5
23
|
### 1.2.9
|
@@ -11,7 +29,8 @@
|
|
11
29
|
- Fix issues with subclassing, such as when using AR STI,
|
12
30
|
fixes [#566](https://github.com/shioyama/mobility/issues/566)
|
13
31
|
([#568](https://github.com/shioyama/mobility/pull/568))
|
14
|
-
- Handle attribute_method_matchers rename (part of
|
32
|
+
- Handle `attribute_method_matchers` rename (part of
|
33
|
+
[#560](https://github.com/shioyama/mobility/pull/560))
|
15
34
|
|
16
35
|
### 1.2.7
|
17
36
|
- Do not query same attribute more than once, fixes
|
data/Gemfile.lock
CHANGED
@@ -1,27 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mobility (1.
|
4
|
+
mobility (1.3.0.rc1)
|
5
5
|
i18n (>= 0.6.10, < 2)
|
6
6
|
request_store (~> 1.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (7.0.3)
|
12
|
-
activesupport (= 7.0.3)
|
13
|
-
activerecord (7.0.3)
|
14
|
-
activemodel (= 7.0.3)
|
15
|
-
activesupport (= 7.0.3)
|
16
|
-
activesupport (7.0.3)
|
17
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (>= 1.6, < 2)
|
19
|
-
minitest (>= 5.1)
|
20
|
-
tzinfo (~> 2.0)
|
21
11
|
benchmark-ips (2.10.0)
|
22
12
|
byebug (11.1.3)
|
23
13
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.
|
14
|
+
concurrent-ruby (1.2.2)
|
25
15
|
database_cleaner (1.99.0)
|
26
16
|
diff-lcs (1.5.0)
|
27
17
|
ffi (1.15.5)
|
@@ -40,26 +30,24 @@ GEM
|
|
40
30
|
guard (~> 2.1)
|
41
31
|
guard-compat (~> 1.1)
|
42
32
|
rspec (>= 2.99.0, < 4.0)
|
43
|
-
i18n (1.
|
33
|
+
i18n (1.12.0)
|
44
34
|
concurrent-ruby (~> 1.0)
|
45
35
|
listen (3.7.1)
|
46
36
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
47
37
|
rb-inotify (~> 0.9, >= 0.9.10)
|
48
38
|
lumberjack (1.2.8)
|
49
39
|
method_source (1.0.0)
|
50
|
-
minitest (5.16.1)
|
51
40
|
nenv (0.3.0)
|
52
41
|
notiffany (0.1.3)
|
53
42
|
nenv (~> 0.1)
|
54
43
|
shellany (~> 0.0)
|
55
|
-
pg (1.3.5)
|
56
44
|
pry (0.13.1)
|
57
45
|
coderay (~> 1.1)
|
58
46
|
method_source (~> 1.0)
|
59
47
|
pry-byebug (3.9.0)
|
60
48
|
byebug (~> 11.0)
|
61
49
|
pry (~> 0.13.0)
|
62
|
-
rack (
|
50
|
+
rack (3.0.7)
|
63
51
|
rake (12.3.3)
|
64
52
|
rb-fsevent (0.11.1)
|
65
53
|
rb-inotify (0.10.1)
|
@@ -81,8 +69,6 @@ GEM
|
|
81
69
|
rspec-support (3.11.0)
|
82
70
|
shellany (0.0.1)
|
83
71
|
thor (1.2.1)
|
84
|
-
tzinfo (2.0.4)
|
85
|
-
concurrent-ruby (~> 1.0)
|
86
72
|
webrick (1.7.0)
|
87
73
|
yard (0.9.28)
|
88
74
|
webrick (~> 1.7.0)
|
@@ -91,16 +77,14 @@ PLATFORMS
|
|
91
77
|
ruby
|
92
78
|
|
93
79
|
DEPENDENCIES
|
94
|
-
activerecord (~> 7.0.0)
|
95
80
|
benchmark-ips
|
96
81
|
database_cleaner (~> 1.5, >= 1.5.3)
|
97
82
|
guard-rspec
|
98
83
|
mobility!
|
99
|
-
pg
|
100
84
|
pry-byebug
|
101
85
|
rake (~> 12, >= 12.2.1)
|
102
86
|
rspec (~> 3.0)
|
103
87
|
yard (~> 0.9.0)
|
104
88
|
|
105
89
|
BUNDLED WITH
|
106
|
-
2.
|
90
|
+
2.4.10
|
data/README.md
CHANGED
@@ -22,7 +22,11 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
|
|
22
22
|
# @param [Hash] options
|
23
23
|
# @return [String,Integer,Boolean] Value of translation
|
24
24
|
def read(locale, _ = nil)
|
25
|
-
model_translations(locale)
|
25
|
+
locale_translations = model_translations(locale)
|
26
|
+
|
27
|
+
return unless locale_translations
|
28
|
+
|
29
|
+
locale_translations[attribute.to_s]
|
26
30
|
end
|
27
31
|
|
28
32
|
# @note Translation may be a string, integer, boolean, hash or array
|
@@ -33,7 +37,7 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
|
|
33
37
|
# @return [String,Integer,Boolean] Updated value
|
34
38
|
def write(locale, value, _ = nil)
|
35
39
|
set_attribute_translation(locale, value)
|
36
|
-
|
40
|
+
read(locale)
|
37
41
|
end
|
38
42
|
# @!endgroup
|
39
43
|
|
@@ -42,8 +46,7 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
|
|
42
46
|
# @option options [Symbol] column_name (:translations) Name of column on which to store translations
|
43
47
|
# @raise [InvalidColumnType] if the type of the container column is not json or jsonb
|
44
48
|
def configure(options)
|
45
|
-
options[:column_name]
|
46
|
-
options[:column_name] = options[:column_name].to_sym
|
49
|
+
options[:column_name] = options[:column_name]&.to_sym || :translations
|
47
50
|
end
|
48
51
|
# @!endgroup
|
49
52
|
|
@@ -78,14 +81,12 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
|
|
78
81
|
|
79
82
|
# @!macro backend_iterator
|
80
83
|
def each_locale
|
81
|
-
model[column_name].
|
82
|
-
yield l.to_sym
|
84
|
+
model[column_name].each_key do |l|
|
85
|
+
yield l.to_sym
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
86
89
|
setup do |_attributes, options|
|
87
|
-
store options[:column_name], coder: Coder
|
88
|
-
|
89
90
|
# Fix for duping depth-2 jsonb column in AR < 5.0
|
90
91
|
if ::ActiveRecord::VERSION::STRING < '5.0'
|
91
92
|
column_name = options[:column_name]
|
@@ -107,32 +108,23 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
|
|
107
108
|
private
|
108
109
|
|
109
110
|
def model_translations(locale)
|
110
|
-
model[column_name][locale]
|
111
|
+
model[column_name][locale.to_s]
|
111
112
|
end
|
112
113
|
|
113
114
|
def set_attribute_translation(locale, value)
|
114
|
-
|
115
|
-
translations[locale.to_s] ||= {}
|
116
|
-
translations[locale.to_s][attribute] = value
|
117
|
-
model[column_name] = translations
|
118
|
-
end
|
115
|
+
locale_translations = model_translations(locale)
|
119
116
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
translations
|
128
|
-
end
|
117
|
+
if locale_translations
|
118
|
+
if value.nil?
|
119
|
+
locale_translations.delete(attribute.to_s)
|
120
|
+
|
121
|
+
# delete empty locale hash if last attribute was just deleted
|
122
|
+
model[column_name].delete(locale.to_s) if locale_translations.empty?
|
129
123
|
else
|
130
|
-
|
124
|
+
locale_translations[attribute.to_s] = value
|
131
125
|
end
|
132
|
-
|
133
|
-
|
134
|
-
def self.load(obj)
|
135
|
-
obj
|
126
|
+
elsif !value.nil?
|
127
|
+
model[column_name][locale.to_s] = { attribute.to_s => value }
|
136
128
|
end
|
137
129
|
end
|
138
130
|
|
@@ -138,7 +138,7 @@ Implements the {Mobility::Backends::KeyValue} backend for ActiveRecord models.
|
|
138
138
|
on(t[key_column].eq(key).
|
139
139
|
and(t[:locale].eq(locale).
|
140
140
|
and(t[:"#{belongs_to}_type"].eq(model_class.base_class.name).
|
141
|
-
and(t[:"#{belongs_to}_id"].eq(m[:id]))))).join_sources)
|
141
|
+
and(t[:"#{belongs_to}_id"].eq(m[model_class.primary_key] || m[:id]))))).join_sources)
|
142
142
|
end
|
143
143
|
|
144
144
|
def already_joined?(relation, name, locale, join_type)
|
@@ -15,34 +15,25 @@ Internal class used by ActiveRecord backends backed by a Postgres data type
|
|
15
15
|
include ActiveRecord
|
16
16
|
include HashValued
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
super { |l| yield l.to_sym }
|
18
|
+
def read(locale, _options = nil)
|
19
|
+
translations[locale.to_s]
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
22
|
+
def write(locale, value, _options = nil)
|
23
|
+
if value.nil?
|
24
|
+
translations.delete(locale.to_s)
|
25
|
+
else
|
26
|
+
translations[locale.to_s] = value
|
27
|
+
end
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
|
30
|
+
# @!macro backend_iterator
|
31
|
+
def each_locale
|
32
|
+
super { |l| yield l.to_sym }
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
if obj.is_a? ::Hash
|
34
|
-
obj.inject({}) do |translations, (locale, value)|
|
35
|
-
translations[locale] = value unless value.nil?
|
36
|
-
translations
|
37
|
-
end
|
38
|
-
else
|
39
|
-
raise ArgumentError, "Attribute is supposed to be a Hash, but was a #{obj.class}. -- #{obj.inspect}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.load(obj)
|
44
|
-
obj
|
45
|
-
end
|
35
|
+
def translations
|
36
|
+
model[column_name]
|
46
37
|
end
|
47
38
|
end
|
48
39
|
private_constant :PgHash
|
@@ -145,7 +145,7 @@ columns to that table.
|
|
145
145
|
m = model_class.arel_table
|
146
146
|
t = model_class.const_get(subclass_name).arel_table.alias(table_alias(locale))
|
147
147
|
relation.joins(m.join(t, join_type).
|
148
|
-
on(t[foreign_key].eq(m[:id]).
|
148
|
+
on(t[foreign_key].eq(m[model_class.primary_key] || m[:id]).
|
149
149
|
and(t[:locale].eq(locale))).join_sources)
|
150
150
|
end
|
151
151
|
|
@@ -36,7 +36,7 @@ model class is generated.
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def define_fallthrough_accessors(*names)
|
39
|
-
method_name_regex = /\A(#{names.join('|')})_([a-z]{2}(_[a-z]{2})?)(=?|\??)\z/.freeze
|
39
|
+
method_name_regex = /\A(#{names.join('|')})_([a-z]{2,3}(_[a-z]{2})?)(=?|\??)\z/.freeze
|
40
40
|
|
41
41
|
define_method :method_missing do |method_name, *args, &block|
|
42
42
|
if method_name =~ method_name_regex
|
data/lib/mobility/version.rb
CHANGED
@@ -58,6 +58,19 @@ Mobility.configure do
|
|
58
58
|
# Or uncomment this line to include but disable by default, and only enable
|
59
59
|
# per model by passing +dirty: true+ to +translates+.
|
60
60
|
# dirty false
|
61
|
+
|
62
|
+
# Column Fallback
|
63
|
+
#
|
64
|
+
# Uncomment line below to fallback to original column. You can pass
|
65
|
+
# +column_fallback: true+ to +translates+ to return original column on
|
66
|
+
# default locale, or pass +column_fallback: [:en, :de]+ to +translates+
|
67
|
+
# to return original column for those locales or pass
|
68
|
+
# +column_fallback: ->(locale) { ... }+ to +translates to evaluate which
|
69
|
+
# locales to return original column for.
|
70
|
+
# column_fallback
|
71
|
+
#
|
72
|
+
# Or uncomment this line to enable column fallback with a global default.
|
73
|
+
# column_fallback true
|
61
74
|
|
62
75
|
# Fallbacks
|
63
76
|
#
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
@@ -10,31 +10,32 @@ bindir: exe
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
+
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
13
|
+
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MQ4wDAYDVQQDDAVjaHJp
|
14
|
+
czEYMBYGCgmSJomT8ixkARkWCGRlamltYXRhMRMwEQYKCZImiZPyLGQBGRYDY29t
|
15
|
+
MB4XDTIzMDMyODA3MTQzNVoXDTI0MDMyNzA3MTQzNVowPzEOMAwGA1UEAwwFY2hy
|
16
|
+
aXMxGDAWBgoJkiaJk/IsZAEZFghkZWppbWF0YTETMBEGCgmSJomT8ixkARkWA2Nv
|
17
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAJI6uJ3SQZs7gaYR4nFb
|
18
|
+
yKG+ZHDMoAvrYHPp5hb3ssueoniFtfV1SOh2QOm3AfdA4XIiUco1NAepYkp+zEIT
|
19
|
+
sCUKWkYe8uOwvpdTBrO6JbEfFw0/2ewkCWreN/hfFjOXqZIieJXEHeScrzbU0w/6
|
20
|
+
/oa3rsiN91ED1qaQqRU7K9pPuhuOnKrZSzdTDpbwbBn4jK2j2BQ2/yRlX6FObOWa
|
21
|
+
4gpyFpr0jU0rpk38UOiHS9uDN7Zi+uagAulgHHkzfYaNPjCswIdobpzLiT9C0stQ
|
22
|
+
EYI4cc51dAhoVR4FYP+J0xXn9t39fZ5+843krkOHOcPJxfT1wXGI/guKoqHETzoV
|
23
|
+
Tjc1sIgjWqOyBKAafAOvz1+5lltt2WO3HtBS8/56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::Dependency
|
40
41
|
name: request_store
|
@@ -254,11 +255,11 @@ metadata:
|
|
254
255
|
rubygems_mfa_required: 'true'
|
255
256
|
post_install_message: |2
|
256
257
|
|
257
|
-
Warning: Mobility v1.
|
258
|
+
Warning: Mobility v1.3.x includes potentially backwards-incompatible changes
|
259
|
+
for jsonb/hstore backends.
|
258
260
|
|
259
|
-
|
260
|
-
- https://github.com/shioyama/mobility/
|
261
|
-
- https://github.com/shioyama/mobility/wiki/Introduction-to-Mobility-v1.0
|
261
|
+
Please see:
|
262
|
+
- https://github.com/shioyama/mobility/issues/535
|
262
263
|
rdoc_options: []
|
263
264
|
require_paths:
|
264
265
|
- lib
|
@@ -269,11 +270,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
269
270
|
version: '2.5'
|
270
271
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
271
272
|
requirements:
|
272
|
-
- - "
|
273
|
+
- - ">"
|
273
274
|
- !ruby/object:Gem::Version
|
274
|
-
version:
|
275
|
+
version: 1.3.1
|
275
276
|
requirements: []
|
276
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.4.6
|
277
278
|
signing_key:
|
278
279
|
specification_version: 4
|
279
280
|
summary: Pluggable Ruby translation framework
|
metadata.gz.sig
CHANGED
Binary file
|