mobility 1.3.0.rc3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mobility might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd0b53980f62d9538827053f6e08b8ffd287d44a7a4aa87602c5d85e87bf30fc
4
- data.tar.gz: 540af4290175ec08b109a8cc0e783c1a634c66fe87bf97fd014d5c5a0f78b79c
3
+ metadata.gz: e29c8ed1c4b5ff644843c06c90fa46ce9fa9dd951a64dfb40b2ff33961483edd
4
+ data.tar.gz: '0708f6107d1ac5a80fd99c7d7d098e6915c10ad457cf962fdcc8510bced56f58'
5
5
  SHA512:
6
- metadata.gz: 25fc7f6a40125020f7425691a3d183a290bfaa3381594d1ad218a924797a0329f76ca39494742f380a3310fbe9d3c879849e366de20bd695219b247c90161d17
7
- data.tar.gz: 8b02e9620070979a64e71d2774495a1be0054e92180116e4e40790575d05faff38fb78001ab460581de2524598af3823f312734b67804d2debe1de428737801a
6
+ metadata.gz: 87975b6d967a5944c5cc5f1b0bc154eeff73437fd3a0bde826195236e070533cfc2ffbaa1188a3791d8bfb439179005210712a9a91894a9212881113b74a1910
7
+ data.tar.gz: d77ff76539f6f847ded56cada8746cd64a2398ddd2fe1fd33758f129ba737e996e083797e7dabe0769f9e41ab06f73b50b2f56635f8e9d5ab2e23f9c787408fa
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1,4 @@
1
- 25g�=�s�`�7x4C1
2
- �+�uT�'����}{؏�K�C�g \�iV .s���Ɍ�koB�k�]�̯X�Ds��(
3
- ���aKXi�1�8��#~���b{U�q�3�qF��Ԁʈ�?�$�]�F���Gx���n@��{�ߍopZT��Op}�ݻ ����x�:߅U ��n��l�ʙ�0\Y�$]�g\PɋR�*���<��g����.�l{�a�UDϔ�g��>书 ��8I�^p�a��5�U��#�7@�4gs
1
+ z��1���'��J���5Mmά�/n(����BD�V�ҘxI�_"�`� X�[�X(�Y2ׄ�@#��Ŭ\��w53>\qsi���!�Y�ű��D8Ě}v�E"��&{��HA��[���e��tI �㈕!��N]�m��~�!��
2
+ c���E3b@��|���eغ�&S�l�����}ɔ �ly9."N��X��YG
3
+ i�_F+�"ڶ�"��@3.�������ɓ����'|0��S*Y�f;������gľ�Q��@ ���s��_��~EF�* 7n�%�a�~��
4
+ .b�Zh24Oj����~VÌ���F>\��fd�z 9ª��Dq�_�y9F�2M��S��q��D�0�d=Q����iS#�S&ev,A��S�.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  ## 1.3
4
4
 
5
+ ### 1.3.1
6
+
7
+ - Use classify to generate table name
8
+ ([#634](https://github.com/shioyama/mobility/pull/634)), thanks
9
+ [divanburger](https://github.com/divanburger)!
10
+ - Fix select + count in ActiveRecord
11
+ 8 ([#659](https://github.com/shioyama/mobility/pull/659))
12
+
13
+ ### 1.3.0
14
+
15
+ - Only support ActiveRecord >= 7.0
16
+ - Allow `I18n.available_locales` to contain Strings
17
+ ([#612](https://github.com/shioyama/mobility/pull/612))
18
+ - Update CI config, add support for Rails 8
19
+ ([#653](https://github.com/shioyama/mobility/pull/653)), thanks
20
+ [d-rodriguez](https://github.com/n-rodriguez)!
21
+ - Fix broken count statements in Active Record 8.0
22
+ ([#655](https://github.com/shioyama/mobility/pull/655)), thanks
23
+ [jukra](https://github.com/jukra)!
24
+
5
25
  ### 1.3.0.rc3
6
26
 
7
27
  - Don't try to load generators if Rails is loaded but AR is not
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ group :development, :test do
10
10
  when 'active_record'
11
11
  orm_version ||= '7.0'
12
12
  case orm_version
13
- when '6.1', '7.0', '7.1'
13
+ when '6.1', '7.0', '7.1', '7.2', '8.0'
14
14
  gem 'activerecord', "~> #{orm_version}.0"
15
15
  when 'edge'
16
16
  git 'https://github.com/rails/rails.git', branch: 'main' do
@@ -45,19 +45,15 @@ group :development, :test do
45
45
  gem 'pry-byebug'
46
46
  case ENV['DB']
47
47
  when 'sqlite3'
48
- if orm == 'active_record' && orm_version < '5.2'
49
- gem 'sqlite3', '~> 1.3.13'
48
+ if orm == 'active_record' && orm_version >= '8.0'
49
+ gem 'sqlite3', '>= 2.1.0'
50
50
  else
51
- gem 'sqlite3', '~> 1.4.1'
51
+ gem 'sqlite3', '~> 1.5.0'
52
52
  end
53
53
  when 'mysql'
54
54
  gem 'mysql2'
55
55
  when 'postgres'
56
- if orm == 'active_record' && orm_version < '5.0'
57
- gem 'pg', '< 1.0'
58
- else
59
- gem 'pg'
60
- end
56
+ gem 'pg'
61
57
  end
62
58
  end
63
59
  end
data/Gemfile.lock CHANGED
@@ -1,22 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (1.3.0.rc1)
4
+ mobility (1.3.0)
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
- benchmark-ips (2.13.0)
11
+ activemodel (8.0.0)
12
+ activesupport (= 8.0.0)
13
+ activerecord (8.0.0)
14
+ activemodel (= 8.0.0)
15
+ activesupport (= 8.0.0)
16
+ timeout (>= 0.4.0)
17
+ activesupport (8.0.0)
18
+ base64
19
+ benchmark (>= 0.3)
20
+ bigdecimal
21
+ concurrent-ruby (~> 1.0, >= 1.3.1)
22
+ connection_pool (>= 2.2.5)
23
+ drb
24
+ i18n (>= 1.6, < 2)
25
+ logger (>= 1.4.2)
26
+ minitest (>= 5.1)
27
+ securerandom (>= 0.3)
28
+ tzinfo (~> 2.0, >= 2.0.5)
29
+ uri (>= 0.13.1)
30
+ base64 (0.2.0)
31
+ benchmark (0.4.0)
32
+ benchmark-ips (2.14.0)
33
+ bigdecimal (3.1.8)
12
34
  byebug (11.1.3)
13
35
  coderay (1.1.3)
14
- concurrent-ruby (1.2.3)
36
+ concurrent-ruby (1.3.4)
37
+ connection_pool (2.4.1)
15
38
  database_cleaner (1.99.0)
16
39
  diff-lcs (1.5.1)
17
- ffi (1.16.3)
40
+ drb (2.2.1)
41
+ ffi (1.17.0-x86_64-linux-gnu)
18
42
  formatador (1.1.0)
19
- guard (2.18.1)
43
+ guard (2.19.0)
20
44
  formatador (>= 0.2.4)
21
45
  listen (>= 2.7, < 4.0)
22
46
  lumberjack (>= 1.0.12, < 2.0)
@@ -30,13 +54,15 @@ GEM
30
54
  guard (~> 2.1)
31
55
  guard-compat (~> 1.1)
32
56
  rspec (>= 2.99.0, < 4.0)
33
- i18n (1.14.4)
57
+ i18n (1.14.6)
34
58
  concurrent-ruby (~> 1.0)
35
59
  listen (3.9.0)
36
60
  rb-fsevent (~> 0.10, >= 0.10.3)
37
61
  rb-inotify (~> 0.9, >= 0.9.10)
62
+ logger (1.6.1)
38
63
  lumberjack (1.2.10)
39
- method_source (1.0.0)
64
+ method_source (1.1.0)
65
+ minitest (5.25.2)
40
66
  nenv (0.3.0)
41
67
  notiffany (0.1.3)
42
68
  nenv (~> 0.1)
@@ -47,35 +73,41 @@ GEM
47
73
  pry-byebug (3.10.1)
48
74
  byebug (~> 11.0)
49
75
  pry (>= 0.13, < 0.15)
50
- rack (3.0.9.1)
76
+ rack (2.2.7)
51
77
  rake (12.3.3)
52
78
  rb-fsevent (0.11.2)
53
- rb-inotify (0.10.1)
79
+ rb-inotify (0.11.1)
54
80
  ffi (~> 1.0)
55
- request_store (1.6.0)
81
+ request_store (1.7.0)
56
82
  rack (>= 1.4)
57
83
  rspec (3.13.0)
58
84
  rspec-core (~> 3.13.0)
59
85
  rspec-expectations (~> 3.13.0)
60
86
  rspec-mocks (~> 3.13.0)
61
- rspec-core (3.13.0)
87
+ rspec-core (3.13.2)
62
88
  rspec-support (~> 3.13.0)
63
- rspec-expectations (3.13.0)
89
+ rspec-expectations (3.13.3)
64
90
  diff-lcs (>= 1.2.0, < 2.0)
65
91
  rspec-support (~> 3.13.0)
66
- rspec-mocks (3.13.0)
92
+ rspec-mocks (3.13.2)
67
93
  diff-lcs (>= 1.2.0, < 2.0)
68
94
  rspec-support (~> 3.13.0)
69
95
  rspec-support (3.13.1)
96
+ securerandom (0.3.2)
70
97
  shellany (0.0.1)
71
- sqlite3 (1.4.4)
72
- thor (1.3.1)
73
- yard (0.9.36)
98
+ sqlite3 (2.3.1-x86_64-linux-gnu)
99
+ thor (1.3.2)
100
+ timeout (0.4.2)
101
+ tzinfo (2.0.6)
102
+ concurrent-ruby (~> 1.0)
103
+ uri (1.0.2)
104
+ yard (0.9.37)
74
105
 
75
106
  PLATFORMS
76
107
  x86_64-linux
77
108
 
78
109
  DEPENDENCIES
110
+ activerecord (~> 8.0.0)
79
111
  benchmark-ips
80
112
  database_cleaner (~> 1.5, >= 1.5.3)
81
113
  guard-rspec
@@ -83,7 +115,7 @@ DEPENDENCIES
83
115
  pry-byebug
84
116
  rake (~> 12, >= 12.2.1)
85
117
  rspec (~> 3.0)
86
- sqlite3 (~> 1.4.1)
118
+ sqlite3 (>= 2.1.0)
87
119
  yard (~> 0.9.0)
88
120
 
89
121
  BUNDLED WITH
data/README.md CHANGED
@@ -54,13 +54,13 @@ Installation
54
54
  Add this line to your application's Gemfile:
55
55
 
56
56
  ```ruby
57
- gem 'mobility', '~> 1.3.0.rc3'
57
+ gem 'mobility', '~> 1.3.1'
58
58
  ```
59
59
 
60
60
  ### ActiveRecord (Rails)
61
61
 
62
62
  Requirements:
63
- - ActiveRecord >= 6.1
63
+ - ActiveRecord >= 7.0
64
64
 
65
65
  To translate attributes on a model, extend `Mobility`, then call `translates`
66
66
  passing in one or more attributes as well as a hash of options (see below).
@@ -86,25 +86,6 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
86
86
  end
87
87
  end
88
88
 
89
- setup do |_attributes, options|
90
- # Fix for duping depth-2 jsonb column in AR < 5.0
91
- if ::ActiveRecord::VERSION::STRING < '5.0'
92
- column_name = options[:column_name]
93
- module_name = "MobilityArContainer#{column_name.to_s.camelcase}"
94
- unless const_defined?(module_name)
95
- dupable = Module.new do
96
- class_eval <<-EOM, __FILE__, __LINE__ + 1
97
- def initialize_dup(source)
98
- super
99
- self.#{column_name} = source.#{column_name}.deep_dup
100
- end
101
- EOM
102
- end
103
- include const_set(module_name, dupable)
104
- end
105
- end
106
- end
107
-
108
89
  private
109
90
 
110
91
  def model_translations(locale)
@@ -102,7 +102,7 @@ columns to that table.
102
102
  def configure(options)
103
103
  table_name = model_class.table_name
104
104
  options[:table_name] ||= "#{table_name.singularize}_translations"
105
- options[:foreign_key] ||= table_name.downcase.singularize.camelize.foreign_key
105
+ options[:foreign_key] ||= table_name.classify.foreign_key
106
106
  if (association_name = options[:association_name]).present?
107
107
  options[:subclass_name] ||= association_name.to_s.singularize.camelize.freeze
108
108
  else
@@ -79,28 +79,24 @@ locale suffix, so +title_en+, +title_pt_br+, etc.)
79
79
  )
80
80
 
81
81
  module InstanceMethods
82
- if ::ActiveRecord::VERSION::STRING >= '5.1' # define patterns added in 5.1
83
- def saved_changes
84
- super.merge(mutations_from_mobility.previous_changes)
85
- end
82
+ def saved_changes
83
+ super.merge(mutations_from_mobility.previous_changes)
84
+ end
86
85
 
87
- def changes_to_save
88
- super.merge(mutations_from_mobility.changes)
89
- end
86
+ def changes_to_save
87
+ super.merge(mutations_from_mobility.changes)
88
+ end
90
89
 
91
- def changed_attribute_names_to_save
92
- super + mutations_from_mobility.changed
93
- end
90
+ def changed_attribute_names_to_save
91
+ super + mutations_from_mobility.changed
92
+ end
94
93
 
95
- def attributes_in_database
96
- super.merge(mutations_from_mobility.changed_attributes)
97
- end
94
+ def attributes_in_database
95
+ super.merge(mutations_from_mobility.changed_attributes)
96
+ end
98
97
 
99
- if ::ActiveRecord::VERSION::STRING >= '6.0'
100
- def has_changes_to_save?
101
- super || mutations_from_mobility.changed?
102
- end
103
- end
98
+ def has_changes_to_save?
99
+ super || mutations_from_mobility.changed?
104
100
  end
105
101
 
106
102
  def reload(*)
@@ -21,6 +21,9 @@ enabled for any one attribute on the model.
21
21
 
22
22
  requires :query, include: false
23
23
 
24
+ ATTRIBUTE_ALIAS_PREFIX = "__mobility_"
25
+ ATTRIBUTE_ALIAS = "#{ATTRIBUTE_ALIAS_PREFIX}%s_%s__"
26
+
24
27
  included_hook do |klass, backend_class|
25
28
  plugin = self
26
29
  if options[:query]
@@ -39,7 +42,7 @@ enabled for any one attribute on the model.
39
42
 
40
43
  class << self
41
44
  def attribute_alias(attribute, locale = Mobility.locale)
42
- "__mobility_%s_%s__" % [attribute, ::Mobility.normalize_locale(locale)]
45
+ ATTRIBUTE_ALIAS % [attribute, ::Mobility.normalize_locale(locale)]
43
46
  end
44
47
 
45
48
  def build_query(klass, locale = Mobility.locale, &block)
@@ -137,19 +140,19 @@ enabled for any one attribute on the model.
137
140
  end
138
141
 
139
142
  def order(opts, *rest)
140
- return super unless @klass.respond_to?(:mobility_attribute?)
143
+ return super unless klass.respond_to?(:mobility_attribute?)
141
144
 
142
145
  case opts
143
146
  when Symbol, String
144
- @klass.mobility_attribute?(opts) ? order({ opts => :asc }, *rest) : super
147
+ klass.mobility_attribute?(opts) ? order({ opts => :asc }, *rest) : super
145
148
  when ::Hash
146
- i18n_keys, keys = opts.keys.partition(&@klass.method(:mobility_attribute?))
149
+ i18n_keys, keys = opts.keys.partition(&klass.method(:mobility_attribute?))
147
150
  return super if i18n_keys.empty?
148
151
 
149
152
  base = keys.empty? ? self : super(opts.slice(keys))
150
153
 
151
154
  i18n_keys.inject(base) do |query, key|
152
- backend_class = @klass.mobility_backend_class(key)
155
+ backend_class = klass.mobility_backend_class(key)
153
156
  dir, node = opts[key], backend_node(key)
154
157
  backend_class.apply_scope(query, node).order(node.send(dir.downcase))
155
158
  end
@@ -158,28 +161,47 @@ enabled for any one attribute on the model.
158
161
  end
159
162
  end
160
163
 
161
- if ::ActiveRecord::VERSION::STRING >= '5.0'
162
- %w[pluck group select].each do |method_name|
163
- define_method method_name do |*attrs, &block|
164
- return super(*attrs, &block) if (method_name == 'select' && block.present?)
164
+ %w[pluck group select].each do |method_name|
165
+ define_method method_name do |*attrs, &block|
166
+ return super(*attrs, &block) if (method_name == 'select' && block.present?)
165
167
 
166
- return super(*attrs, &block) unless @klass.respond_to?(:mobility_attribute?)
168
+ return super(*attrs, &block) unless klass.respond_to?(:mobility_attribute?)
167
169
 
168
- return super(*attrs, &block) unless attrs.any?(&@klass.method(:mobility_attribute?))
170
+ return super(*attrs, &block) unless attrs.any?(&klass.method(:mobility_attribute?))
169
171
 
170
- keys = attrs.dup
172
+ keys = attrs.dup
171
173
 
172
- base = keys.each_with_index.inject(self) do |query, (key, index)|
173
- next query unless @klass.mobility_attribute?(key)
174
- keys[index] = backend_node(key)
175
- if method_name == "select"
176
- keys[index] = keys[index]
177
- .as(::Mobility::Plugins::ActiveRecord::Query.attribute_alias(key.to_s))
178
- end
179
- @klass.mobility_backend_class(key).apply_scope(query, backend_node(key))
174
+ base = keys.each_with_index.inject(self) do |query, (key, index)|
175
+ next query unless klass.mobility_attribute?(key)
176
+ keys[index] = backend_node(key)
177
+ if method_name == "select"
178
+ keys[index] = keys[index]
179
+ .as(::Mobility::Plugins::ActiveRecord::Query.attribute_alias(key.to_s))
180
180
  end
181
+ klass.mobility_backend_class(key).apply_scope(query, backend_node(key))
182
+ end
183
+
184
+ base.public_send(method_name, *keys, &block)
185
+ end
186
+ end
181
187
 
182
- base.public_send(method_name, *keys, &block)
188
+ if ::ActiveRecord::VERSION::MAJOR >= 8
189
+ # Fix for https://github.com/shioyama/mobility/pull/654#issuecomment-2503479112
190
+ # TODO: Make this better
191
+ def select_for_count
192
+ return super unless klass.respond_to?(:mobility_attribute?)
193
+
194
+ if select_values.any? { |value| value.right.start_with?(ATTRIBUTE_ALIAS_PREFIX) }
195
+ filtered_select_values = select_values.map do |value|
196
+ value.right.start_with?(ATTRIBUTE_ALIAS_PREFIX) ? value.left : value
197
+ end
198
+
199
+ # Copied from lib/active_record/relation/calculations.rb
200
+ with_connection do |conn|
201
+ arel_columns(filtered_select_values).map { |column| conn.visitor.compile(column) }.join(", ")
202
+ end
203
+ else
204
+ super
183
205
  end
184
206
  end
185
207
  end
@@ -189,7 +211,7 @@ enabled for any one attribute on the model.
189
211
  # @param [Symbol] locale Locale
190
212
  # @return [Arel::Node] Arel node for this attribute in given locale
191
213
  def backend_node(name, locale = Mobility.locale)
192
- @klass.mobility_backend_class(name)[name, locale]
214
+ klass.mobility_backend_class(name)[name, locale]
193
215
  end
194
216
 
195
217
  class WhereChain < ::ActiveRecord::QueryMethods::WhereChain
@@ -26,17 +26,6 @@ module Mobility
26
26
  end)
27
27
  end
28
28
 
29
- # Needed for AR 4.2, can be removed when support is deprecated
30
- if ::ActiveRecord::VERSION::STRING < '5.0'
31
- [JsonbDashDoubleArrow, HstoreDashArrow].each do |klass|
32
- klass.class_eval do
33
- def quoted_node other
34
- other && super
35
- end
36
- end
37
- end
38
- end
39
-
40
29
  class Jsonb < JsonbDashDoubleArrow
41
30
  def to_dash_arrow
42
31
  JsonbDashArrow.new left, right
@@ -8,8 +8,8 @@ module Mobility
8
8
  module VERSION
9
9
  MAJOR = 1
10
10
  MINOR = 3
11
- TINY = 0
12
- PRE = "rc3"
11
+ TINY = 1
12
+ PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
15
15
  end
data/lib/mobility.rb CHANGED
@@ -228,9 +228,9 @@ module Mobility
228
228
  # methods (in LocaleAccessors) than is really necessary.
229
229
  def available_locales
230
230
  if defined?(Rails) && Rails.respond_to?(:application) && Rails.application
231
- Rails.application.config.i18n.available_locales&.map(&:to_sym) || I18n.available_locales
231
+ Rails.application.config.i18n.available_locales&.map(&:to_sym) || I18n.available_locales.map(&:to_sym)
232
232
  else
233
- I18n.available_locales
233
+ I18n.available_locales.map(&:to_sym)
234
234
  end
235
235
  end
236
236
 
@@ -78,7 +78,7 @@ Mobility.configure do
78
78
  # fallbacks
79
79
  #
80
80
  # Or uncomment this line to enable fallbacks with a global default.
81
- # fallbacks { :pt => :en }
81
+ # fallbacks(pt: :en)
82
82
 
83
83
  # Presence
84
84
  #
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.3.0.rc3
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3I5AfnFAG4/1IwhadqwF5cl3jOUa7n3mS2OJl3tRCGuPvwAA9MV10hmwbQTXMrNK
36
36
  tD9kfT9eseUE4mfPnIaHOs4FiIoHniA7zdtjB7GIQ4cEpB6o
37
37
  -----END CERTIFICATE-----
38
- date: 2024-03-31 00:00:00.000000000 Z
38
+ date: 2024-12-01 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: request_store
@@ -270,9 +270,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
270
270
  version: '2.5'
271
271
  required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  requirements:
273
- - - ">"
273
+ - - ">="
274
274
  - !ruby/object:Gem::Version
275
- version: 1.3.1
275
+ version: '0'
276
276
  requirements: []
277
277
  rubygems_version: 3.4.6
278
278
  signing_key:
metadata.gz.sig CHANGED
Binary file