mobility 1.2.0 → 1.2.1
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 +8 -4
- data/Gemfile.lock +22 -3
- data/README.md +1 -1
- data/lib/mobility/plugins/active_record/column_fallback.rb +28 -101
- data/lib/mobility/plugins/sequel/column_fallback.rb +26 -93
- data/lib/mobility/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: 826490fa3ce8fc86d22c06737a226e7b35aa509d1ccc47e777f1f2fb18eacc77
|
4
|
+
data.tar.gz: 4625eff941c67cde509b7e5d9e5f36deb7f204058d5ba4287d62a367244c007e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e496eb5a3a3635d749ded9019795ed4753dc9c4e2f25a89aa022a4ee5aa1116a5ff21b4f3f503f0cc3ecc7b7b087849d2f3fd5e805e0101d1fc23faa62f36823
|
7
|
+
data.tar.gz: 395035bbfa2e3309cc627706c466f58ab8c4f6dc5af63185365be8d3d79a623cf317626acd6b3d9ab95c4c936ca3136452b1513c268ca8979aeeaea76ae4539f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -8,15 +8,19 @@
|
|
8
8
|
|
9
9
|
## 1.2
|
10
10
|
|
11
|
+
### 1.2.1
|
12
|
+
- Refactor ColumnFallback plugin
|
13
|
+
([#530](https://github.com/shioyama/mobility/pull/530))
|
14
|
+
|
11
15
|
### 1.2.0
|
12
16
|
- Add ColumnFallback plugin
|
13
|
-
|
17
|
+
([#512](https://github.com/shioyama/mobility/pull/512))
|
14
18
|
- Fix Sequel querying on untranslated attributes in `i18n` block
|
15
|
-
|
19
|
+
([#529](https://github.com/shioyama/mobility/pull/529))
|
16
20
|
- Allow passing configured backend class as third argument to setup
|
17
|
-
|
21
|
+
([#528](https://github.com/shioyama/mobility/pull/528))
|
18
22
|
- Clearly distinguish backend classes from their configured subclasses
|
19
|
-
|
23
|
+
([#527](https://github.com/shioyama/mobility/pull/527))
|
20
24
|
|
21
25
|
### 1.1.3
|
22
26
|
- Do not swallow keyword args on ruby 3 in fallthrough accessors
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,23 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/rails/rails.git
|
3
|
+
revision: 53000f3a2df5c59252d019bbb8d46728b291ec74
|
4
|
+
branch: main
|
5
|
+
specs:
|
6
|
+
activemodel (7.0.0.alpha2)
|
7
|
+
activesupport (= 7.0.0.alpha2)
|
8
|
+
activerecord (7.0.0.alpha2)
|
9
|
+
activemodel (= 7.0.0.alpha2)
|
10
|
+
activesupport (= 7.0.0.alpha2)
|
11
|
+
activesupport (7.0.0.alpha2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
|
1
17
|
PATH
|
2
18
|
remote: .
|
3
19
|
specs:
|
4
|
-
mobility (1.2.0
|
20
|
+
mobility (1.2.0)
|
5
21
|
i18n (>= 0.6.10, < 2)
|
6
22
|
request_store (~> 1.0)
|
7
23
|
|
@@ -37,6 +53,7 @@ GEM
|
|
37
53
|
rb-inotify (~> 0.9, >= 0.9.10)
|
38
54
|
lumberjack (1.2.8)
|
39
55
|
method_source (1.0.0)
|
56
|
+
minitest (5.14.4)
|
40
57
|
nenv (0.3.0)
|
41
58
|
notiffany (0.1.3)
|
42
59
|
nenv (~> 0.1)
|
@@ -68,15 +85,18 @@ GEM
|
|
68
85
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
86
|
rspec-support (~> 3.10.0)
|
70
87
|
rspec-support (3.10.2)
|
71
|
-
sequel (5.48.0)
|
72
88
|
shellany (0.0.1)
|
73
89
|
thor (1.1.0)
|
90
|
+
tzinfo (2.0.4)
|
91
|
+
concurrent-ruby (~> 1.0)
|
74
92
|
yard (0.9.26)
|
75
93
|
|
76
94
|
PLATFORMS
|
77
95
|
ruby
|
78
96
|
|
79
97
|
DEPENDENCIES
|
98
|
+
activerecord!
|
99
|
+
activesupport!
|
80
100
|
benchmark-ips
|
81
101
|
database_cleaner (~> 1.5, >= 1.5.3)
|
82
102
|
guard-rspec
|
@@ -85,7 +105,6 @@ DEPENDENCIES
|
|
85
105
|
pry-byebug
|
86
106
|
rake (~> 12, >= 12.2.1)
|
87
107
|
rspec (~> 3.0)
|
88
|
-
sequel (~> 5.0)
|
89
108
|
yard (~> 0.9.0)
|
90
109
|
|
91
110
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -14,120 +14,47 @@ Plugin to use an original column for a given locale, and otherwise use the backe
|
|
14
14
|
requires :column_fallback, include: false
|
15
15
|
|
16
16
|
included_hook do |_, backend_class|
|
17
|
-
|
17
|
+
backend_class.include BackendInstanceMethods
|
18
|
+
backend_class.extend BackendClassMethods
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.use_column_fallback?(options, locale)
|
22
|
+
case column_fallback = options[:column_fallback]
|
18
23
|
when TrueClass
|
19
|
-
|
20
|
-
when Array
|
21
|
-
|
24
|
+
locale == I18n.default_locale
|
25
|
+
when Array
|
26
|
+
column_fallback.include?(locale)
|
27
|
+
when Proc
|
28
|
+
column_fallback.call(locale)
|
22
29
|
else
|
23
|
-
|
30
|
+
false
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
|
-
module
|
34
|
+
module BackendInstanceMethods
|
28
35
|
def read(locale, **)
|
29
|
-
|
36
|
+
if ColumnFallback.use_column_fallback?(options, locale)
|
37
|
+
model.read_attribute(attribute)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
30
41
|
end
|
31
42
|
|
32
43
|
def write(locale, value, **)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
base.extend(ClassMethods)
|
38
|
-
end
|
39
|
-
|
40
|
-
module ClassMethods
|
41
|
-
def build_node(attr, locale)
|
42
|
-
if locale == I18n.default_locale
|
43
|
-
model_class.arel_table[attr]
|
44
|
-
else
|
45
|
-
super
|
46
|
-
end
|
44
|
+
if ColumnFallback.use_column_fallback?(options, locale)
|
45
|
+
model.send(:write_attribute, attribute, value)
|
46
|
+
else
|
47
|
+
super
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
define_proc_accessors
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def included(base)
|
62
|
-
base.extend(ClassMethods.new(@column_fallback))
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def define_array_accessors
|
68
|
-
column_fallback = @column_fallback
|
69
|
-
|
70
|
-
module_eval <<-EOM, __FILE__, __LINE__ + 1
|
71
|
-
def read(locale, **)
|
72
|
-
if #{column_fallback}.include?(locale)
|
73
|
-
model.read_attribute(attribute)
|
74
|
-
else
|
75
|
-
super
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def write(locale, value, **)
|
80
|
-
if #{column_fallback}.include?(locale)
|
81
|
-
model.send(:write_attribute, attribute, value)
|
82
|
-
else
|
83
|
-
super
|
84
|
-
end
|
85
|
-
end
|
86
|
-
EOM
|
87
|
-
end
|
88
|
-
|
89
|
-
def define_proc_accessors
|
90
|
-
column_fallback = @column_fallback
|
91
|
-
|
92
|
-
define_method :read do |locale, **options|
|
93
|
-
if column_fallback.call(locale)
|
94
|
-
model.read_attribute(attribute)
|
95
|
-
else
|
96
|
-
super(locale, **options)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
define_method :write do |locale, value, **options|
|
101
|
-
if column_fallback.call(locale)
|
102
|
-
model.send(:write_attribute, attribute, value)
|
103
|
-
else
|
104
|
-
super(locale, value, **options)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
class ClassMethods < Module
|
110
|
-
def initialize(column_fallback)
|
111
|
-
case column_fallback
|
112
|
-
when Array
|
113
|
-
module_eval <<-EOM, __FILE__, __LINE__ + 1
|
114
|
-
def build_node(attr, locale)
|
115
|
-
if #{column_fallback}.include?(locale)
|
116
|
-
model_class.arel_table[attr]
|
117
|
-
else
|
118
|
-
super
|
119
|
-
end
|
120
|
-
end
|
121
|
-
EOM
|
122
|
-
when Proc
|
123
|
-
define_method(:build_node) do |attr, locale|
|
124
|
-
if column_fallback.call(locale)
|
125
|
-
model_class.arel_table[attr]
|
126
|
-
else
|
127
|
-
super(attr, locale)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
52
|
+
module BackendClassMethods
|
53
|
+
def build_node(attr, locale)
|
54
|
+
if ColumnFallback.use_column_fallback?(options, locale)
|
55
|
+
model_class.arel_table[attr]
|
56
|
+
else
|
57
|
+
super
|
131
58
|
end
|
132
59
|
end
|
133
60
|
end
|
@@ -14,114 +14,47 @@ Plugin to use an original column for a given locale, and otherwise use the backe
|
|
14
14
|
requires :column_fallback, include: false
|
15
15
|
|
16
16
|
included_hook do |_, backend_class|
|
17
|
-
|
17
|
+
backend_class.include BackendInstanceMethods
|
18
|
+
backend_class.extend BackendClassMethods
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.use_column_fallback?(options, locale)
|
22
|
+
case column_fallback = options[:column_fallback]
|
18
23
|
when TrueClass
|
19
|
-
|
20
|
-
when Array
|
21
|
-
|
24
|
+
locale == I18n.default_locale
|
25
|
+
when Array
|
26
|
+
column_fallback.include?(locale)
|
27
|
+
when Proc
|
28
|
+
column_fallback.call(locale)
|
29
|
+
else
|
30
|
+
false
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
module
|
34
|
+
module BackendInstanceMethods
|
26
35
|
def read(locale, **)
|
27
|
-
|
36
|
+
if ColumnFallback.use_column_fallback?(options, locale)
|
37
|
+
model[attribute.to_sym]
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
28
41
|
end
|
29
42
|
|
30
43
|
def write(locale, value, **)
|
31
|
-
if locale
|
44
|
+
if ColumnFallback.use_column_fallback?(options, locale)
|
32
45
|
model[attribute.to_sym] = value
|
33
46
|
else
|
34
47
|
super
|
35
48
|
end
|
36
49
|
end
|
37
|
-
|
38
|
-
def self.included(base)
|
39
|
-
base.extend(ClassMethods)
|
40
|
-
end
|
41
|
-
|
42
|
-
module ClassMethods
|
43
|
-
def build_op(attr, locale)
|
44
|
-
if locale == I18n.default_locale
|
45
|
-
::Sequel::SQL::QualifiedIdentifier.new(model_class.table_name, attr.to_sym)
|
46
|
-
else
|
47
|
-
super
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
50
|
end
|
52
51
|
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
define_proc_accessors
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def included(base)
|
64
|
-
base.extend(ClassMethods.new(@column_fallback))
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def define_array_accessors
|
70
|
-
column_fallback = @column_fallback
|
71
|
-
|
72
|
-
module_eval <<-EOM, __FILE__, __LINE__ + 1
|
73
|
-
def read(locale, **)
|
74
|
-
#{column_fallback}.include?(locale) ? model[attribute.to_sym] : super
|
75
|
-
end
|
76
|
-
|
77
|
-
def write(locale, value, **)
|
78
|
-
if #{column_fallback}.include?(locale)
|
79
|
-
model[attribute.to_sym] = value
|
80
|
-
else
|
81
|
-
super
|
82
|
-
end
|
83
|
-
end
|
84
|
-
EOM
|
85
|
-
end
|
86
|
-
|
87
|
-
def define_proc_accessors
|
88
|
-
column_fallback = @column_fallback
|
89
|
-
|
90
|
-
define_method :read do |locale, **options|
|
91
|
-
column_fallback.call(locale) ? model[attribute.to_sym] : super(locale, **options)
|
92
|
-
end
|
93
|
-
|
94
|
-
define_method :write do |locale, value, **options|
|
95
|
-
if column_fallback.call(locale)
|
96
|
-
model[attribute.to_sym] = value
|
97
|
-
else
|
98
|
-
super(locale, value, **options)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class ClassMethods < Module
|
104
|
-
def initialize(column_fallback)
|
105
|
-
case column_fallback
|
106
|
-
when Array
|
107
|
-
module_eval <<-EOM, __FILE__, __LINE__ + 1
|
108
|
-
def build_op(attr, locale)
|
109
|
-
if #{column_fallback}.include?(locale)
|
110
|
-
::Sequel::SQL::QualifiedIdentifier.new(model_class.table_name, attr.to_sym)
|
111
|
-
else
|
112
|
-
super
|
113
|
-
end
|
114
|
-
end
|
115
|
-
EOM
|
116
|
-
when Proc
|
117
|
-
define_method(:build_op) do |attr, locale|
|
118
|
-
if column_fallback.call(locale)
|
119
|
-
::Sequel::SQL::QualifiedIdentifier.new(model_class.table_name, attr.to_sym)
|
120
|
-
else
|
121
|
-
super(attr, locale)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
52
|
+
module BackendClassMethods
|
53
|
+
def build_op(attr, locale)
|
54
|
+
if ColumnFallback.use_column_fallback?(options, locale)
|
55
|
+
::Sequel::SQL::QualifiedIdentifier.new(model_class.table_name, attr.to_sym)
|
56
|
+
else
|
57
|
+
super
|
125
58
|
end
|
126
59
|
end
|
127
60
|
end
|
data/lib/mobility/version.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
eBMcZq0d1tbtv1M1UXND9mOfhLZ31YvoSTPkrJiRpljUNgD0+ugelnr1/5X/9k8y
|
35
35
|
J9QOd3C5jpSShf/HMvpJnFuSYFm19cH9GrHjvw==
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2021-09-
|
37
|
+
date: 2021-09-27 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: request_store
|
metadata.gz.sig
CHANGED
Binary file
|