mobility 1.2.1 → 1.2.5

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: 826490fa3ce8fc86d22c06737a226e7b35aa509d1ccc47e777f1f2fb18eacc77
4
- data.tar.gz: 4625eff941c67cde509b7e5d9e5f36deb7f204058d5ba4287d62a367244c007e
3
+ metadata.gz: ad89c4b8f858e06961d867d4d6fef4ae2b7fa05228c29beb1262d6bdfbd60eff
4
+ data.tar.gz: 8e626e914ffc5533cd1d7932f66bf7c14acaeae2b0b1bd9cba17539a23389fb6
5
5
  SHA512:
6
- metadata.gz: e496eb5a3a3635d749ded9019795ed4753dc9c4e2f25a89aa022a4ee5aa1116a5ff21b4f3f503f0cc3ecc7b7b087849d2f3fd5e805e0101d1fc23faa62f36823
7
- data.tar.gz: 395035bbfa2e3309cc627706c466f58ab8c4f6dc5af63185365be8d3d79a623cf317626acd6b3d9ab95c4c936ca3136452b1513c268ca8979aeeaea76ae4539f
6
+ metadata.gz: 4d1d31e256f1f2cd9c04ed2f83d73dcef576248bbc0dfc28550da9d2d7e9c66aef0df73ab955324b0669dfdd13ad2bf790049125e16bd9a263d8c3df10713c84
7
+ data.tar.gz: 00a3d9bd1b1fd47fd0e9c732d9ee40709761490029269b629500c876b5d4acdb847e8c512a8de9329a213578202430120b956adb322c7921300895f9dabd8931
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,12 +1,26 @@
1
1
  # Mobility Changelog
2
2
 
3
- ## Unreleased
4
- - Assign blank values in pg hash backends
5
- ([#516](https://github.com/shioyama/mobility/pull/516))
3
+ ## 1.2
6
4
 
7
- ## 1.1
5
+ ### 1.2.5
6
+ - Avoid referencing ActiveRecord::Base
7
+ ([#550](https://github.com/shioyama/mobility/pull/550))
8
8
 
9
- ## 1.2
9
+ ### 1.2.4
10
+ - Fix fallbacks performance regression
11
+ ([#548](https://github.com/shioyama/mobility/pull/548))
12
+
13
+ ### 1.2.3
14
+ - Fix passing wrong options to super in fallbacks plugin
15
+ ([#539](https://github.com/shioyama/mobility/pull/539))
16
+
17
+ ### 1.2.2
18
+ - Make models work with `Marshal.dump`
19
+ ([#532](https://github.com/shioyama/mobility/pull/532))
20
+ - Fix Sequel container op in Sequel
21
+ ([#533](https://github.com/shioyama/mobility/pull/533))
22
+ - Simplify Fallbacks plugin
23
+ ([#531](https://github.com/shioyama/mobility/pull/531))
10
24
 
11
25
  ### 1.2.1
12
26
  - Refactor ColumnFallback plugin
@@ -22,6 +36,8 @@
22
36
  - Clearly distinguish backend classes from their configured subclasses
23
37
  ([#527](https://github.com/shioyama/mobility/pull/527))
24
38
 
39
+ ## 1.1
40
+
25
41
  ### 1.1.3
26
42
  - Do not swallow keyword args on ruby 3 in fallthrough accessors
27
43
  ([#520](https://github.com/shioyama/mobility/pull/520)) thanks
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: https://github.com/rails/rails.git
3
- revision: 53000f3a2df5c59252d019bbb8d46728b291ec74
3
+ revision: 5647a9c1ced68d20338552d47a3b755e10a271c4
4
4
  branch: main
5
5
  specs:
6
6
  activemodel (7.0.0.alpha2)
@@ -17,28 +17,28 @@ GIT
17
17
  PATH
18
18
  remote: .
19
19
  specs:
20
- mobility (1.2.0)
20
+ mobility (1.3.0.alpha)
21
21
  i18n (>= 0.6.10, < 2)
22
22
  request_store (~> 1.0)
23
23
 
24
24
  GEM
25
25
  remote: https://rubygems.org/
26
26
  specs:
27
- benchmark-ips (2.8.4)
27
+ benchmark-ips (2.9.1)
28
28
  byebug (11.1.3)
29
29
  coderay (1.1.3)
30
30
  concurrent-ruby (1.1.9)
31
31
  database_cleaner (1.99.0)
32
32
  diff-lcs (1.4.4)
33
- ffi (1.15.0)
34
- formatador (0.2.5)
35
- guard (2.16.2)
33
+ ffi (1.15.4)
34
+ formatador (0.3.0)
35
+ guard (2.18.0)
36
36
  formatador (>= 0.2.4)
37
37
  listen (>= 2.7, < 4.0)
38
38
  lumberjack (>= 1.0.12, < 2.0)
39
39
  nenv (~> 0.1)
40
40
  notiffany (~> 0.0)
41
- pry (>= 0.9.12)
41
+ pry (>= 0.13.0)
42
42
  shellany (~> 0.0)
43
43
  thor (>= 0.18.1)
44
44
  guard-compat (1.2.1)
@@ -48,7 +48,7 @@ GEM
48
48
  rspec (>= 2.99.0, < 4.0)
49
49
  i18n (1.8.10)
50
50
  concurrent-ruby (~> 1.0)
51
- listen (3.5.1)
51
+ listen (3.7.0)
52
52
  rb-fsevent (~> 0.10, >= 0.10.3)
53
53
  rb-inotify (~> 0.9, >= 0.9.10)
54
54
  lumberjack (1.2.8)
@@ -67,7 +67,7 @@ GEM
67
67
  pry (~> 0.13.0)
68
68
  rack (2.2.3)
69
69
  rake (12.3.3)
70
- rb-fsevent (0.10.4)
70
+ rb-fsevent (0.11.0)
71
71
  rb-inotify (0.10.1)
72
72
  ffi (~> 1.0)
73
73
  request_store (1.5.0)
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.1'
58
+ gem 'mobility', '~> 1.2.5'
59
59
  ```
60
60
 
61
61
  ### ActiveRecord (Rails)
@@ -77,6 +77,12 @@ On top of this, a backend will normally:
77
77
  @attribute = args[1]
78
78
  end
79
79
 
80
+ def ==(backend)
81
+ backend.class == self.class &&
82
+ backend.attribute == attribute &&
83
+ backend.model == model
84
+ end
85
+
80
86
  # @!macro [new] backend_reader
81
87
  # Gets the translated value for provided locale from configured backend.
82
88
  # @param [Symbol] locale Locale to read
@@ -100,7 +100,7 @@ Implements the {Mobility::Backends::Container} backend for Sequel models.
100
100
  # @return [Mobility::Backends::Sequel::Container::JSONOp,Mobility::Backends::Sequel::Container::JSONBOp]
101
101
  def self.build_op(attr, locale)
102
102
  klass = const_get("#{options[:column_type].upcase}Op")
103
- klass.new(klass.new(column_name.to_sym)[locale.to_s]).get_text(attr)
103
+ klass.new(klass.new(column_name.to_sym).get(locale.to_s)).get_text(attr)
104
104
  end
105
105
 
106
106
  class JSONOp < ::Sequel::Postgres::JSONOp; end
@@ -114,15 +114,33 @@ Defines:
114
114
  defaults[key] = [backend, backend_options] if backend
115
115
  end
116
116
 
117
+ class MobilityBackends < Hash
118
+ def initialize(model)
119
+ @model = model
120
+ super()
121
+ end
122
+
123
+ def [](name)
124
+ return fetch(name) if has_key?(name)
125
+ return self[name.to_sym] if String === name
126
+ self[name] = @model.class.mobility_backend_class(name).new(@model, name.to_s)
127
+ end
128
+
129
+ def marshal_dump
130
+ @model
131
+ end
132
+
133
+ def marshal_load(model)
134
+ @model = model
135
+ end
136
+ end
137
+
117
138
  module InstanceMethods
118
139
  # Return a new backend for an attribute name.
119
140
  # @return [Hash] Hash of attribute names and backend instances
120
141
  # @api private
121
142
  def mobility_backends
122
- @mobility_backends ||= ::Hash.new do |hash, name|
123
- next hash[name.to_sym] if String === name
124
- hash[name] = self.class.mobility_backend_class(name).new(self, name.to_s)
125
- end
143
+ @mobility_backends ||= MobilityBackends.new(self)
126
144
  end
127
145
 
128
146
  def initialize_dup(other)
@@ -117,8 +117,21 @@ the current locale was +nil+.
117
117
  # Applies fallbacks plugin to attributes. Completely disables fallbacks
118
118
  # on model if option is +false+.
119
119
  included_hook do |_, backend_class|
120
- fallbacks = options[:fallbacks]
121
- backend_class.include(BackendReader.new(fallbacks, method(:generate_fallbacks))) unless fallbacks == false
120
+ unless options[:fallbacks] == false
121
+ backend_class.include(BackendInstanceMethods)
122
+
123
+ fallbacks =
124
+ if options[:fallbacks].is_a?(Hash)
125
+ generate_fallbacks(options[:fallbacks])
126
+ elsif options[:fallbacks] == true
127
+ generate_fallbacks({})
128
+ else
129
+ ::Hash.new { [] }
130
+ end
131
+
132
+ backend_class.singleton_class.attr_reader :fallbacks
133
+ backend_class.instance_variable_set(:@fallbacks, fallbacks)
134
+ end
122
135
  end
123
136
 
124
137
  private
@@ -134,36 +147,17 @@ the current locale was +nil+.
134
147
  end
135
148
  end
136
149
 
137
- class BackendReader < Module
138
- def initialize(fallbacks_option, fallbacks_generator)
139
- @fallbacks_generator = fallbacks_generator
140
- define_read(convert_option_to_fallbacks(fallbacks_option))
141
- end
142
-
143
- private
150
+ module BackendInstanceMethods
151
+ def read(locale, fallback: true, **kwargs)
152
+ return super(locale, **kwargs) if !fallback || kwargs[:locale]
144
153
 
145
- def define_read(fallbacks)
146
- define_method :read do |locale, fallback: true, **options|
147
- return super(locale, **options) if !fallback || options[:locale]
148
-
149
- locales = fallback == true ? fallbacks[locale] : [locale, *fallback]
150
- locales.each do |fallback_locale|
151
- value = super(fallback_locale, **options)
152
- return value if Util.present?(value)
153
- end
154
-
155
- super(locale, **options)
154
+ locales = fallback == true ? self.class.fallbacks[locale] : [locale, *fallback]
155
+ locales.each do |fallback_locale|
156
+ value = super(fallback_locale, **kwargs)
157
+ return value if Util.present?(value)
156
158
  end
157
- end
158
159
 
159
- def convert_option_to_fallbacks(option)
160
- if option.is_a?(::Hash)
161
- @fallbacks_generator[option]
162
- elsif option == true
163
- @fallbacks_generator[{}]
164
- else
165
- ::Hash.new { [] }
166
- end
160
+ super(locale, **kwargs)
167
161
  end
168
162
  end
169
163
  end
@@ -8,7 +8,7 @@ module Mobility
8
8
  module VERSION
9
9
  MAJOR = 1
10
10
  MINOR = 2
11
- TINY = 1
11
+ TINY = 5
12
12
  PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -46,7 +46,9 @@ module Mobility
46
46
  connection.data_source_exists?(table_name)
47
47
  end
48
48
 
49
- delegate :connection, to: ::ActiveRecord::Base
49
+ def connection
50
+ ::ActiveRecord::Base.connection
51
+ end
50
52
 
51
53
  def truncate_index_name(index_name)
52
54
  if index_name.size < connection.index_name_length
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- ��PaY���W7�L�ey?��BsR
2
- �p��ʶ�)�� {�U���A��KE��Yd&���&9A
1
+ $�����ј���I!4-��fX���y;P��X���w8} ^�RbV�eW޴Ɂ���>�E�?�ҖЖU~G^�q0�N�ˆ�$M��깖+����.Sh�i�\06ʩ2NG�����1�۲���*70����<
2
+ �w����*�4��)c `a[s߸HVj�
3
+ E����O�A�xܿ���@9rW�I�o��:.;ɛ����K]yu\ ��8�����[�:�y�^$���m:�H���b ��"k8�)і¤�@f
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.1
4
+ version: 1.2.5
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-27 00:00:00.000000000 Z
37
+ date: 2021-12-04 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