mobility 1.0.0.beta1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +53 -3
  5. data/Gemfile +5 -16
  6. data/Gemfile.lock +20 -3
  7. data/README.md +23 -28
  8. data/lib/mobility.rb +61 -7
  9. data/lib/mobility/backends/active_record.rb +1 -1
  10. data/lib/mobility/backends/active_record/column.rb +1 -1
  11. data/lib/mobility/backends/active_record/container.rb +4 -4
  12. data/lib/mobility/backends/active_record/hstore.rb +3 -3
  13. data/lib/mobility/backends/active_record/json.rb +3 -3
  14. data/lib/mobility/backends/active_record/jsonb.rb +3 -3
  15. data/lib/mobility/backends/active_record/key_value.rb +27 -11
  16. data/lib/mobility/backends/active_record/table.rb +11 -6
  17. data/lib/mobility/backends/sequel.rb +32 -0
  18. data/lib/mobility/backends/sequel/container.rb +5 -3
  19. data/lib/mobility/backends/sequel/key_value.rb +79 -12
  20. data/lib/mobility/backends/sequel/pg_hash.rb +6 -6
  21. data/lib/mobility/backends/sequel/table.rb +18 -8
  22. data/lib/mobility/backends/table.rb +11 -6
  23. data/lib/mobility/plugin.rb +2 -2
  24. data/lib/mobility/plugins/active_record.rb +3 -0
  25. data/lib/mobility/plugins/active_record/backend.rb +2 -0
  26. data/lib/mobility/plugins/active_record/query.rb +7 -7
  27. data/lib/mobility/plugins/active_record/uniqueness_validation.rb +4 -0
  28. data/lib/mobility/plugins/arel.rb +125 -0
  29. data/lib/mobility/plugins/arel/nodes.rb +15 -0
  30. data/lib/mobility/plugins/arel/nodes/pg_ops.rb +134 -0
  31. data/lib/mobility/plugins/attribute_methods.rb +1 -0
  32. data/lib/mobility/plugins/attributes.rb +17 -15
  33. data/lib/mobility/plugins/backend.rb +7 -7
  34. data/lib/mobility/plugins/sequel/dirty.rb +1 -1
  35. data/lib/mobility/version.rb +2 -2
  36. data/lib/rails/generators/mobility/templates/create_string_translations.rb +0 -1
  37. data/lib/rails/generators/mobility/templates/create_text_translations.rb +0 -1
  38. data/lib/rails/generators/mobility/templates/initializer.rb +9 -1
  39. metadata +14 -20
  40. metadata.gz.sig +0 -0
  41. data/lib/mobility/active_record/model_translation.rb +0 -14
  42. data/lib/mobility/active_record/string_translation.rb +0 -10
  43. data/lib/mobility/active_record/text_translation.rb +0 -10
  44. data/lib/mobility/active_record/translation.rb +0 -14
  45. data/lib/mobility/arel.rb +0 -49
  46. data/lib/mobility/arel/nodes.rb +0 -13
  47. data/lib/mobility/arel/nodes/pg_ops.rb +0 -132
  48. data/lib/mobility/arel/visitor.rb +0 -61
  49. data/lib/mobility/sequel/column_changes.rb +0 -28
  50. data/lib/mobility/sequel/hash_initializer.rb +0 -21
  51. data/lib/mobility/sequel/model_translation.rb +0 -20
  52. data/lib/mobility/sequel/sql.rb +0 -16
  53. data/lib/mobility/sequel/string_translation.rb +0 -10
  54. data/lib/mobility/sequel/text_translation.rb +0 -10
  55. data/lib/mobility/sequel/translation.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a27c475aac12e8c93750cd6b11b7b339912c95bb24ada1e579c8f87598359388
4
- data.tar.gz: faf2187673842e059b204715e774b2ef22d0a98e6162d7014ef875236a0db192
3
+ metadata.gz: 8c59ad405d9183d4a2a27905ecace4c3f25e1fdb7492646bed76866b5eefab8a
4
+ data.tar.gz: 557c434ad2858d524b68a9580a0ae77b03a4361cc6e8b3b46f8883610c4c2598
5
5
  SHA512:
6
- metadata.gz: 51dfb02fb8624897834dbc9260eb7edc67f6120f2971de120f7084e59df0865a027eca3ccae435ba77604fa8086760a1c682b9879a4c625be71368fa21d3b2c7
7
- data.tar.gz: 5133980f0433ba31d157ebda7e1a8028dc84aa8d8dc7ab6b0df94861c347e60f34b09665eb890341998080be5256bea566f7e0dea62f96f6c85fcfd931319969
6
+ metadata.gz: 8479d64a5db0190980afede4f638ecfb67a895312afa8c1d9d742a52c07298bf5898a0796606c9287907ebec5989dcb177ab41ced41d651f8843e057beb0e8f1
7
+ data.tar.gz: fb61359a451ff909d81137365538bbdfa7726672da5bfe4ce75ee59b5ab07de9b6a9b9784708b65de998b75921551ed87ba81b3d04a27dae401c0918419b9283
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,10 +1,60 @@
1
1
  # Mobility Changelog
2
2
 
3
+ ### Unreleased
4
+ - Remove `Mobility::Plugins::Attributes#each`
5
+ ([#475](https://github.com/shioyama/mobility/pull/475))
6
+ - Add public method `Mobility::Plugins::ActiveRecord::Query.build_query`
7
+ ([#471](https://github.com/shioyama/mobility/pull/471))
8
+ - Allow setting locale per node in query block
9
+ ([#479](https://github.com/shioyama/mobility/pull/479))
10
+ - Add `Mobility.validate_locale!`
11
+ ([#479](https://github.com/shioyama/mobility/pull/479))
12
+ - Call after_destroy in setup block to delete associated translations
13
+ ([#487](https://github.com/shioyama/mobility/pull/487))
14
+ - Add key, value and belongs_to options to key-value backend
15
+ ([#488](https://github.com/shioyama/mobility/pull/488)) thanks
16
+ [sedubois](https://github.com/sedubois)!
17
+
3
18
  ## 1.0
4
19
 
5
- 1.0 is a rewrite of many internals of the gem. Please see the [wiki page on v1.0](https://github.com/shioyama/mobility/wiki/Introduction-to-Mobility-v1.0) for more details on how to upgrade.
20
+ 1.0 is a rewrite of many internals of the gem. Please see the [wiki page on
21
+ v1.0](https://github.com/shioyama/mobility/wiki/Introduction-to-Mobility-v1.0)
22
+ for more details on how to upgrade.
23
+
24
+ ### 1.0.2
25
+ - Fix `Mobility.default_backend`
26
+ ([#497](https://github.com/shioyama/mobility/pull/497))
27
+
28
+ ### 1.0.1
29
+
30
+ - Make `Mobility::Plugins::ActiveRecord::Query::VirtualRow` and
31
+ `Mobility::Plugins::ActiveRecord::Query::QueryExtension`
32
+ ([#471](https://github.com/shioyama/mobility/pull/471)) public
33
+ - Fix typo in initializer template
34
+ ([#474](https://github.com/shioyama/mobility/pull/474))
35
+
36
+ ### 1.0.0
37
+
38
+ - Fix setting a locale from Rails config
39
+ ([#468](https://github.com/shioyama/mobility/pull/468)) thanks
40
+ [sergey-alekseev](https://github.com/sergey-alekseev)!
41
+ - Fixes validations with validates_uniqueness_of
42
+ ([#470](https://github.com/shioyama/mobility/pull/470)) thanks
43
+ [artplan1](https://github.com/artplan1)!
44
+
45
+ ### 1.0.0.rc1 (pre-release)
46
+
47
+ - Remove `Mobility::ActiveRecord`, `Mobility::Sequel` and `Mobility::Arel`, and
48
+ general cleanup ([#464](https://github.com/shioyama/mobility/pull/464))
49
+
50
+ ### 1.0.0.beta2 (pre-release)
51
+
52
+ - Refactor attributes & backend plugins and make `mobility_attributes` public
53
+ ([#462](https://github.com/shioyama/mobility/pull/462))
54
+ - Make attribute_methods plugin depend on attributes
55
+ ([#461](https://github.com/shioyama/mobility/pull/461))
6
56
 
7
- ## 1.0.0.beta1 (pre-release)
57
+ ### 1.0.0.beta1 (pre-release)
8
58
 
9
59
  - Remove `Mobility::Backend#apply_plugin`
10
60
  ([#454](https://github.com/shioyama/mobility/pull/454))
@@ -15,7 +65,7 @@
15
65
  - Fix Ruby 2.7 deprecation warnings
16
66
  ([#460](https://github.com/shioyama/mobility/pull/460))
17
67
 
18
- ## 1.0.0.alpha (pre-release)
68
+ ### 1.0.0.alpha (pre-release)
19
69
 
20
70
  - Default fallbacks plugin to `true` when enabled
21
71
  ([#447](https://github.com/shioyama/mobility/pull/447))
data/Gemfile CHANGED
@@ -8,20 +8,11 @@ orm, orm_version = ENV['ORM'], ENV['ORM_VERSION']
8
8
  group :development, :test do
9
9
  case orm
10
10
  when 'active_record'
11
- orm_version ||= '6.0'
11
+ orm_version ||= '6.1'
12
12
  case orm_version
13
- when '4.2'
14
- gem 'activerecord', '>= 4.2.6', '< 5.0'
15
- when '5.0'
16
- gem 'activerecord', '>= 5.0', '< 5.1'
17
- when '5.1'
18
- gem 'activerecord', '>= 5.1', '< 5.2'
19
- when '5.2'
20
- gem 'activerecord', '>= 5.2.0', '< 5.3'
21
- gem 'railties', '>= 5.2.0.rc2', '< 5.3'
22
- when '6.0'
23
- gem 'activerecord', '>= 6.0.0', '< 6.1'
24
- when '6.1'
13
+ when '4.2', '5.0', '5.1', '5.2', '6.0', '6.1'
14
+ gem 'activerecord', "~> #{orm_version}.0"
15
+ when '6.2'
25
16
  git 'https://github.com/rails/rails.git' do
26
17
  gem 'activerecord'
27
18
  gem 'activesupport'
@@ -32,10 +23,8 @@ group :development, :test do
32
23
  when 'sequel'
33
24
  orm_version ||= '5'
34
25
  case orm_version
35
- when '4'
36
- gem 'sequel', '>= 4.46.0', '< 5.0'
37
26
  when '5'
38
- gem 'sequel', '>= 5.0.0', '< 6.0.0'
27
+ gem 'sequel', "~> #{orm_version}.0"
39
28
  else
40
29
  raise ArgumentError, 'Invalid Sequel version'
41
30
  end
@@ -1,14 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (1.0.0.alpha)
4
+ mobility (1.0.1)
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
- allocation_stats (0.1.5)
11
+ activemodel (6.0.3.4)
12
+ activesupport (= 6.0.3.4)
13
+ activerecord (6.0.3.4)
14
+ activemodel (= 6.0.3.4)
15
+ activesupport (= 6.0.3.4)
16
+ activesupport (6.0.3.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ zeitwerk (~> 2.2, >= 2.2.2)
12
22
  benchmark-ips (2.8.3)
13
23
  byebug (11.1.3)
14
24
  coderay (1.1.3)
@@ -38,10 +48,12 @@ GEM
38
48
  rb-inotify (~> 0.9, >= 0.9.10)
39
49
  lumberjack (1.2.8)
40
50
  method_source (1.0.0)
51
+ minitest (5.14.3)
41
52
  nenv (0.3.0)
42
53
  notiffany (0.1.3)
43
54
  nenv (~> 0.1)
44
55
  shellany (~> 0.0)
56
+ pg (1.2.3)
45
57
  pry (0.13.1)
46
58
  coderay (~> 1.1)
47
59
  method_source (~> 1.0)
@@ -70,17 +82,22 @@ GEM
70
82
  rspec-support (3.10.0)
71
83
  shellany (0.0.1)
72
84
  thor (1.0.1)
85
+ thread_safe (0.3.6)
86
+ tzinfo (1.2.9)
87
+ thread_safe (~> 0.1)
73
88
  yard (0.9.25)
89
+ zeitwerk (2.4.2)
74
90
 
75
91
  PLATFORMS
76
92
  ruby
77
93
 
78
94
  DEPENDENCIES
79
- allocation_stats
95
+ activerecord (~> 6.0.0)
80
96
  benchmark-ips
81
97
  database_cleaner (~> 1.5, >= 1.5.3)
82
98
  guard-rspec
83
99
  mobility!
100
+ pg
84
101
  pry-byebug
85
102
  rake (~> 12, >= 12.2.1)
86
103
  rspec (~> 3.0)
data/README.md CHANGED
@@ -12,11 +12,9 @@ Mobility
12
12
  [docs]: http://www.rubydoc.info/gems/mobility
13
13
  [wiki]: https://github.com/shioyama/mobility/wiki
14
14
 
15
- **This is the readme for the [`master`](https://github.com/shioyama/mobility)
16
- branch, which corresponds to v1.0.0.beta, a pre-release version of Mobility.
17
- If you are using an earlier version (0.8.x or earlier), you probably want the
18
- readme on the [0-8-stable
19
- branch](https://github.com/shioyama/mobility/tree/0-8-stable).**
15
+ **This is the readme for version 1.0 of Mobility. If you are using an earlier
16
+ version (0.8.x or earlier), you probably want the readme on the [0-8
17
+ branch](https://github.com/shioyama/mobility/tree/0-8).**
20
18
 
21
19
  Mobility is a gem for storing and retrieving translations as attributes on a
22
20
  class. These translations could be the content of blog posts, captions on
@@ -58,12 +56,9 @@ To use the latest pre-version of Mobility 1.0, add this line to your
58
56
  application's Gemfile:
59
57
 
60
58
  ```ruby
61
- gem 'mobility', '~> 1.0.0.beta1'
59
+ gem 'mobility', '~> 1.0.2'
62
60
  ```
63
61
 
64
- For the latest stable version of Mobility, see the readme on the
65
- [0-8-stable](https://github.com/shioyama/mobility/tree/0-8-stable) branch.
66
-
67
62
  ### ActiveRecord (Rails)
68
63
 
69
64
  Requirements:
@@ -91,10 +86,10 @@ The generator will create an initializer file `config/initializers/mobility.rb`
91
86
  which looks something like this:
92
87
 
93
88
  ```ruby
94
- Mobility.configure do |config|
95
- # PLUGINS
89
+ Mobility.configure do
96
90
 
97
- config.plugins do
91
+ # PLUGINS
92
+ plugins do
98
93
  backend :key_value
99
94
 
100
95
  active_record
@@ -107,15 +102,15 @@ Mobility.configure do |config|
107
102
  end
108
103
  ```
109
104
 
110
- Each method call inside the block passed to `config.plugins` declares a plugin,
111
- along with an optional default. To use a different default backend, you can
105
+ Each method call inside the block passed to `plugins` declares a plugin, along
106
+ with an optional default. To use a different default backend, you can
112
107
  change the default passed to the `backend` plugin, like this:
113
108
 
114
109
  ```diff
115
- Mobility.configure do |config|
116
- # PLUGINS
110
+ Mobility.configure do
117
111
 
118
- config.plugins do
112
+ # PLUGINS
113
+ plugins do
119
114
  - backend :key_value
120
115
  + backend :table
121
116
  ```
@@ -126,10 +121,10 @@ You can also set defaults for backend-specific options. Below, we set the
126
121
  default `type` option for the KeyValue backend to `:string`.
127
122
 
128
123
  ```diff
129
- Mobility.configure do |config|
130
- # PLUGINS
124
+ Mobility.configure do
131
125
 
132
- config.plugins do
126
+ # PLUGINS
127
+ plugins do
133
128
  - backend :key_value
134
129
  + backend :key_value, type: :string
135
130
  end
@@ -150,7 +145,7 @@ Requirements:
150
145
  When configuring Mobility, ensure that you include the `sequel` plugin:
151
146
 
152
147
  ```diff
153
- config.plugins do
148
+ plugins do
154
149
  backend :key_value
155
150
 
156
151
  - active_record
@@ -297,7 +292,7 @@ accessors" in Mobility, and can be enabled by including the `locale_accessors`
297
292
  plugin, with a default set of accessors:
298
293
 
299
294
  ```diff
300
- config.plugins do
295
+ plugins do
301
296
  # ...
302
297
  + locale_accessors [:en, :ja]
303
298
  ```
@@ -345,7 +340,7 @@ defined for a given locale.)
345
340
  Ensure the plugin is enabled:
346
341
 
347
342
  ```diff
348
- config.plugins do
343
+ plugins do
349
344
  # ...
350
345
  + fallthrough_accessors
351
346
  ```
@@ -470,7 +465,7 @@ Mobility offers basic support for translation fallbacks. First, enable the
470
465
  `fallbacks` plugin:
471
466
 
472
467
  ```diff
473
- config.plugins do
468
+ plugins do
474
469
  # ...
475
470
  + fallbacks
476
471
  + locale_accessors
@@ -579,7 +574,7 @@ fallbacks](https://github.com/svenfuchs/i18n/wiki/Fallbacks).
579
574
  Another option is to assign a default value, using the `default` plugin:
580
575
 
581
576
  ```diff
582
- config.plugins do
577
+ plugins do
583
578
  # ...
584
579
  + default 'foo'
585
580
  ```
@@ -632,7 +627,7 @@ have enabled an ORM plugin (either `active_record` or `sequel`), since the
632
627
  dirty plugin will depend on one of these being enabled.
633
628
 
634
629
  ```diff
635
- config.plugins do
630
+ plugins do
636
631
  # ...
637
632
  active_record
638
633
  + dirty
@@ -722,7 +717,7 @@ can be quickly retrieved again. The cache plugin is included in the default
722
717
  configuration created by the install generator:
723
718
 
724
719
  ```diff
725
- config.plugins do
720
+ plugins do
726
721
  # ...
727
722
  + cache
728
723
  ```
@@ -752,7 +747,7 @@ this feature, include the `query` plugin, and ensure you also have an ORM
752
747
  plugin enabled (`active_record` or `sequel`):
753
748
 
754
749
  ```diff
755
- config.plugins do
750
+ plugins do
756
751
  # ...
757
752
  active_record
758
753
  + query
@@ -6,17 +6,71 @@ require 'mobility/version'
6
6
  =begin
7
7
 
8
8
  Mobility is a gem for storing and retrieving localized data through attributes
9
- on a class. The {Mobility} module includes all necessary methods and modules to
10
- support defining backend accessors on a class.
9
+ on a class.
11
10
 
12
- To enable Mobility on a class, simply include or extend the {Mobility} module,
13
- and define any attribute accessors using {Translates#translates}.
11
+ There are two ways to translate attributes on a class, both of which are
12
+ variations on the same basic mechanism. The first and most common way is to
13
+ extend the `Mobility` module, which adds a class method +translates+.
14
+ Translated attributes can then be defined like this:
14
15
 
15
- class MyClass
16
+ class Post
16
17
  extend Mobility
17
18
  translates :title, backend: :key_value
18
19
  end
19
20
 
21
+ Behind the scenes, +translates+ simply creates an instance of
22
+ +Mobility.translations_class+, passes it whatever arguments are passed to
23
+ +translates+, and includes the instance (which is a module) into the class.
24
+
25
+ So the above example is equivalent to:
26
+
27
+ class Post
28
+ Mobility.translations_class.new(:title, backend: :key_value)
29
+ end
30
+
31
+ `Mobility.translations_class` is a subclass of `Mobility::Translations` created
32
+ when `Mobility.configure` is called to configure Mobility. In fact, when you
33
+ call `Mobility.configure`, it is the subclass of `Mobility::Translations` which
34
+ is passed to the block as `config`. Plugins and plugin configuration is all
35
+ applied to the same `Mobility.translations_class`.
36
+
37
+ There is another way to use Mobility, which is to create your own subclass or
38
+ subclasses of +Mobility::Translations+ and include them explicitly, without
39
+ using +translates+.
40
+
41
+ For example:
42
+
43
+ class Translations < Mobility::Translations
44
+ plugins do
45
+ backend :key_value
46
+ # ...
47
+ end
48
+ end
49
+
50
+ class Post
51
+ include Translations.new(:title)
52
+ end
53
+
54
+ This usage might be handy if, for example, you want to have more complex
55
+ configuration, where some models use some plugins while others do not. Since
56
+ `Mobility::Translations` is a class like any other, you can subclass it and
57
+ define plugins specifically on the subclass which are not present on its
58
+ parent:
59
+
60
+ class TranslationsWithFallbacks < Translations
61
+ plugins do
62
+ fallbacks
63
+ end
64
+ end
65
+
66
+ class Comment
67
+ include TranslationsWithFallbacks.new(:author)
68
+ end
69
+
70
+ In this case, +Comment+ uses +TranslationsWithFallbacks+ and thus has the
71
+ fallbacks plugin, whereas +Post+ uses +Translations+ which does not have that
72
+ plugin enabled.
73
+
20
74
  =end
21
75
  module Mobility
22
76
  # A generic exception used by Mobility.
@@ -50,6 +104,7 @@ module Mobility
50
104
  model_class.extend self
51
105
  end
52
106
 
107
+ # Alias to default backend defined on *translations_class+.
53
108
  # @return [Symbol,Class]
54
109
  def default_backend
55
110
  translations_class.defaults[:backend]
@@ -65,7 +120,6 @@ module Mobility
65
120
  yield translations_class
66
121
  end
67
122
  end
68
- # @!endgroup
69
123
 
70
124
  def translates_with(pluggable)
71
125
  raise ArgumentError, "translations class must be a subclass of Module." unless Module === pluggable
@@ -164,7 +218,7 @@ module Mobility
164
218
  # methods (in LocaleAccessors) than is really necessary.
165
219
  def available_locales
166
220
  if defined?(Rails) && Rails.application
167
- Rails.application.config.i18n.available_locales || I18n.available_locales
221
+ Rails.application.config.i18n.available_locales&.map(&:to_sym) || I18n.available_locales
168
222
  else
169
223
  I18n.available_locales
170
224
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "mobility/backend"
3
- require "mobility/arel"
3
+ require "mobility/plugins/arel"
4
4
 
5
5
  module Mobility
6
6
  module Backends
@@ -57,7 +57,7 @@ can be run again to add new attributes or locales.)
57
57
  # on model table
58
58
  def self.build_node(attr, locale)
59
59
  model_class.arel_table[Column.column_name_for(attr, locale)]
60
- .extend(::Mobility::Arel::MobilityExpressions)
60
+ .extend(Plugins::Arel::MobilityExpressions)
61
61
  end
62
62
 
63
63
  private