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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5cedc8fabef42f478f93a4bb4fa1e8764759855dcded4d25f397c018f1811d2
4
- data.tar.gz: 1fb647fdbcbafa3b8a5a6d47d71500e2481556aa72674c5269ea0dc560d63ca0
3
+ metadata.gz: 826490fa3ce8fc86d22c06737a226e7b35aa509d1ccc47e777f1f2fb18eacc77
4
+ data.tar.gz: 4625eff941c67cde509b7e5d9e5f36deb7f204058d5ba4287d62a367244c007e
5
5
  SHA512:
6
- metadata.gz: ee138cb5544fc8942dc8a6dbf7fcfd54bf3829329075950755b8fea3ba676c430b880b14366dcfc09b66651b06577957e02130c5b4f2a62d7db96d02f1a150c8
7
- data.tar.gz: 980502d8c285bedf8e2958a24cb77c129ee39f1cfb946c44bbd83f7cc89b30009a829bfb17b515aac9e02d3f3a810b1433cab416aabec67c1daab9c6f100683d
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
- ([#512](https://github.com/shioyama/mobility/pull/512))
17
+ ([#512](https://github.com/shioyama/mobility/pull/512))
14
18
  - Fix Sequel querying on untranslated attributes in `i18n` block
15
- ([#529](https://github.com/shioyama/mobility/pull/529))
19
+ ([#529](https://github.com/shioyama/mobility/pull/529))
16
20
  - Allow passing configured backend class as third argument to setup
17
- ([#528](https://github.com/shioyama/mobility/pull/528))
21
+ ([#528](https://github.com/shioyama/mobility/pull/528))
18
22
  - Clearly distinguish backend classes from their configured subclasses
19
- ([#527](Clearly distinguish backend classes from their configured subclasses))
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.alpha)
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
@@ -55,7 +55,7 @@ Installation
55
55
  Add this line to your application's Gemfile:
56
56
 
57
57
  ```ruby
58
- gem 'mobility', '~> 1.2.0'
58
+ gem 'mobility', '~> 1.2.1'
59
59
  ```
60
60
 
61
61
  ### ActiveRecord (Rails)
@@ -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
- case (column_fallback = options[:column_fallback])
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
- backend_class.include I18nDefaultLocaleBackend
20
- when Array, Proc
21
- backend_class.include BackendModule.new(column_fallback)
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
- raise ArgumentError, "column_fallback value must be a boolean, an array of locales or a proc"
30
+ false
24
31
  end
25
32
  end
26
33
 
27
- module I18nDefaultLocaleBackend
34
+ module BackendInstanceMethods
28
35
  def read(locale, **)
29
- locale == I18n.default_locale ? model.read_attribute(attribute) : super
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
- locale == I18n.default_locale ? model.send(:write_attribute, attribute, value) : super
34
- end
35
-
36
- def self.included(base)
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
- class BackendModule < Module
52
- def initialize(column_fallback)
53
- case (@column_fallback = column_fallback)
54
- when Array
55
- define_array_accessors
56
- when Proc
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
- case (column_fallback = options[:column_fallback])
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
- backend_class.include I18nDefaultLocaleBackend
20
- when Array, Proc
21
- backend_class.include BackendModule.new(column_fallback)
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 I18nDefaultLocaleBackend
34
+ module BackendInstanceMethods
26
35
  def read(locale, **)
27
- locale == I18n.default_locale ? model[attribute.to_sym] : super
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 == I18n.default_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
- class BackendModule < Module
54
- def initialize(column_fallback)
55
- case (@column_fallback = column_fallback)
56
- when Array
57
- define_array_accessors
58
- when Proc
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
@@ -8,7 +8,7 @@ module Mobility
8
8
  module VERSION
9
9
  MAJOR = 1
10
10
  MINOR = 2
11
- TINY = 0
11
+ TINY = 1
12
12
  PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
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.0
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-26 00:00:00.000000000 Z
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