mobility 0.8.13 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -2
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +63 -0
  5. data/Gemfile +5 -2
  6. data/Gemfile.lock +39 -20
  7. data/README.md +183 -93
  8. data/lib/mobility.rb +101 -169
  9. data/lib/mobility/backend.rb +27 -51
  10. data/lib/mobility/backends.rb +20 -0
  11. data/lib/mobility/backends/active_record.rb +4 -0
  12. data/lib/mobility/backends/active_record/column.rb +3 -1
  13. data/lib/mobility/backends/active_record/container.rb +10 -11
  14. data/lib/mobility/backends/active_record/hstore.rb +6 -4
  15. data/lib/mobility/backends/active_record/json.rb +5 -3
  16. data/lib/mobility/backends/active_record/jsonb.rb +5 -3
  17. data/lib/mobility/backends/active_record/key_value.rb +31 -13
  18. data/lib/mobility/backends/active_record/pg_hash.rb +1 -1
  19. data/lib/mobility/backends/active_record/serialized.rb +6 -0
  20. data/lib/mobility/backends/active_record/table.rb +17 -10
  21. data/lib/mobility/backends/column.rb +0 -6
  22. data/lib/mobility/backends/container.rb +10 -1
  23. data/lib/mobility/backends/hash.rb +39 -0
  24. data/lib/mobility/backends/hash_valued.rb +4 -0
  25. data/lib/mobility/backends/hstore.rb +0 -1
  26. data/lib/mobility/backends/json.rb +0 -1
  27. data/lib/mobility/backends/jsonb.rb +1 -2
  28. data/lib/mobility/backends/key_value.rb +31 -26
  29. data/lib/mobility/backends/null.rb +2 -0
  30. data/lib/mobility/backends/sequel.rb +37 -2
  31. data/lib/mobility/backends/sequel/column.rb +2 -0
  32. data/lib/mobility/backends/sequel/container.rb +11 -9
  33. data/lib/mobility/backends/sequel/hstore.rb +3 -1
  34. data/lib/mobility/backends/sequel/json.rb +3 -0
  35. data/lib/mobility/backends/sequel/jsonb.rb +3 -1
  36. data/lib/mobility/backends/sequel/key_value.rb +87 -18
  37. data/lib/mobility/backends/sequel/pg_hash.rb +6 -6
  38. data/lib/mobility/backends/sequel/serialized.rb +6 -0
  39. data/lib/mobility/backends/sequel/table.rb +22 -9
  40. data/lib/mobility/backends/serialized.rb +1 -3
  41. data/lib/mobility/backends/table.rb +39 -31
  42. data/lib/mobility/pluggable.rb +56 -0
  43. data/lib/mobility/plugin.rb +260 -0
  44. data/lib/mobility/plugins.rb +27 -24
  45. data/lib/mobility/plugins/active_model.rb +17 -0
  46. data/lib/mobility/plugins/active_model/cache.rb +26 -0
  47. data/lib/mobility/plugins/active_model/dirty.rb +119 -78
  48. data/lib/mobility/plugins/active_record.rb +37 -0
  49. data/lib/mobility/plugins/active_record/backend.rb +27 -0
  50. data/lib/mobility/plugins/active_record/cache.rb +28 -0
  51. data/lib/mobility/plugins/active_record/dirty.rb +34 -17
  52. data/lib/mobility/plugins/active_record/query.rb +43 -31
  53. data/lib/mobility/plugins/active_record/uniqueness_validation.rb +64 -0
  54. data/lib/mobility/plugins/arel.rb +125 -0
  55. data/lib/mobility/plugins/arel/nodes.rb +15 -0
  56. data/lib/mobility/plugins/arel/nodes/pg_ops.rb +134 -0
  57. data/lib/mobility/plugins/attribute_methods.rb +29 -20
  58. data/lib/mobility/plugins/attributes.rb +72 -0
  59. data/lib/mobility/plugins/backend.rb +161 -0
  60. data/lib/mobility/plugins/backend_reader.rb +34 -0
  61. data/lib/mobility/plugins/cache.rb +68 -26
  62. data/lib/mobility/plugins/default.rb +22 -17
  63. data/lib/mobility/plugins/dirty.rb +12 -33
  64. data/lib/mobility/plugins/fallbacks.rb +52 -44
  65. data/lib/mobility/plugins/fallthrough_accessors.rb +19 -23
  66. data/lib/mobility/plugins/locale_accessors.rb +22 -35
  67. data/lib/mobility/plugins/presence.rb +28 -21
  68. data/lib/mobility/plugins/query.rb +8 -17
  69. data/lib/mobility/plugins/reader.rb +50 -0
  70. data/lib/mobility/plugins/sequel.rb +34 -0
  71. data/lib/mobility/plugins/sequel/backend.rb +25 -0
  72. data/lib/mobility/plugins/sequel/cache.rb +24 -0
  73. data/lib/mobility/plugins/sequel/dirty.rb +34 -23
  74. data/lib/mobility/plugins/sequel/query.rb +21 -6
  75. data/lib/mobility/plugins/writer.rb +44 -0
  76. data/lib/mobility/translations.rb +95 -0
  77. data/lib/mobility/version.rb +12 -1
  78. data/lib/rails/generators/mobility/templates/create_string_translations.rb +0 -1
  79. data/lib/rails/generators/mobility/templates/create_text_translations.rb +0 -1
  80. data/lib/rails/generators/mobility/templates/initializer.rb +104 -78
  81. metadata +35 -40
  82. metadata.gz.sig +0 -0
  83. data/lib/mobility/active_model.rb +0 -4
  84. data/lib/mobility/active_model/backend_resetter.rb +0 -26
  85. data/lib/mobility/active_record.rb +0 -23
  86. data/lib/mobility/active_record/backend_resetter.rb +0 -26
  87. data/lib/mobility/active_record/model_translation.rb +0 -14
  88. data/lib/mobility/active_record/string_translation.rb +0 -10
  89. data/lib/mobility/active_record/text_translation.rb +0 -10
  90. data/lib/mobility/active_record/translation.rb +0 -14
  91. data/lib/mobility/active_record/uniqueness_validator.rb +0 -60
  92. data/lib/mobility/arel.rb +0 -49
  93. data/lib/mobility/arel/nodes.rb +0 -13
  94. data/lib/mobility/arel/nodes/pg_ops.rb +0 -132
  95. data/lib/mobility/arel/visitor.rb +0 -61
  96. data/lib/mobility/attributes.rb +0 -324
  97. data/lib/mobility/backend/orm_delegator.rb +0 -44
  98. data/lib/mobility/backend_resetter.rb +0 -50
  99. data/lib/mobility/configuration.rb +0 -138
  100. data/lib/mobility/fallbacks.rb +0 -28
  101. data/lib/mobility/interface.rb +0 -0
  102. data/lib/mobility/loaded.rb +0 -4
  103. data/lib/mobility/plugins/active_record/attribute_methods.rb +0 -38
  104. data/lib/mobility/plugins/cache/translation_cacher.rb +0 -40
  105. data/lib/mobility/sequel.rb +0 -9
  106. data/lib/mobility/sequel/backend_resetter.rb +0 -23
  107. data/lib/mobility/sequel/column_changes.rb +0 -28
  108. data/lib/mobility/sequel/hash_initializer.rb +0 -21
  109. data/lib/mobility/sequel/model_translation.rb +0 -20
  110. data/lib/mobility/sequel/sql.rb +0 -16
  111. data/lib/mobility/sequel/string_translation.rb +0 -10
  112. data/lib/mobility/sequel/text_translation.rb +0 -10
  113. data/lib/mobility/sequel/translation.rb +0 -53
  114. data/lib/mobility/translates.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd73c4e94757a4138786f7ebfeb2ac7bbdbcb219030af3319043232b696d70c2
4
- data.tar.gz: c05a86a128d80fb859b531c25745474a561f92bf1c610a6d41250c4995f8b0a0
3
+ metadata.gz: d927c413815d0bd56b1f75e5b0a352d2f5832415c4e1f8c50a98fde44d973e92
4
+ data.tar.gz: 72d484c61b6b17b9d99e1061444d209ce66a4de70f904d68d1ce612b24656ae0
5
5
  SHA512:
6
- metadata.gz: cfcddf59bc7a203fd00508bbcb32c8e59658eded31cbf637fb5fe9e9ccfd4cde3b59f762113b1f32c1427d5e2fecfa67e9c91d6c9d8b58c05928cf90356370be
7
- data.tar.gz: 887fbb7bb02fa80fc421b45f8f434972c4d163e11e0d6d5dc2618f94e7f86307feb2fc4801c988fd86d19735edb863519b60addacaebebb49d2cb27490af0210
6
+ metadata.gz: 1167adec126a34ff482d01beaa38e18e4188a79aa1be9e5031f8786d86629724984f7597c29d947ae11ad77d72c7538ecc84ed7474c70c87a3da226e81b1f59c
7
+ data.tar.gz: d64f21cab45ffa292e9980962d38c7f76fcaacdcac48b7d83b25fbcc0856b49b6814cefdc78e39382d7c12b944ef27ebedb23c14bffb6f819c972e8c9176cb43
@@ -1,2 +1,2 @@
1
- >0��R(������p��*�χ-�s����d��������\ذ~m(���@�@U^����*��Z���kr+4A"�R���6'��D�If��7ɣ��ta\�.���cۆ��i3Ê�Yxh��S U�s$y���dޣ��l���hHf>͐�9.������h���F(|��A7��z�1���5~;c��dWwJ K΃�ηp#�?)Eo�ʉ�"Y��`x����:��q7.G �b�c8*ꊢ�c����g�b$��q����sx���p
2
- �MPm#��[a*���&������ë�aC]=X1J�Q!�S1ףev��v7p ���wn\�*�ל��$�k�
1
+ Z���yyWy��=���T�R?��6�Jl����-��a���q��te����������&�r��Ş�I8��KJ���@FS�I�CĔm�z��1y�/�qDI e�~:�!�/��_8
2
+ Σ��U�π�Y��>�)��)"0_k�L���N6~#���o��P��^��5К%��\ M9�$�/)t����uԋ�^�t�ʎ@
data.tar.gz.sig CHANGED
Binary file
@@ -1,5 +1,68 @@
1
1
  # Mobility Changelog
2
2
 
3
+ ## 1.0
4
+
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.
6
+
7
+ ## 1.0.0
8
+
9
+ - Fix setting a locale from Rails config
10
+ ([#468](https://github.com/shioyama/mobility/pull/468)) thanks
11
+ [sergey-alekseev](https://github.com/sergey-alekseev)!
12
+ - Fixes validations with validates_uniqueness_of
13
+ ([#470](https://github.com/shioyama/mobility/pull/470)) thanks
14
+ [artplan1](https://github.com/shioyama/mobility/pull/470)!
15
+
16
+ ## 1.0.0.rc1 (pre-release)
17
+
18
+ - Remove `Mobility::ActiveRecord`, `Mobility::Sequel` and `Mobility::Arel`, and
19
+ general cleanup ([#464](https://github.com/shioyama/mobility/pull/464))
20
+
21
+ ## 1.0.0.beta2 (pre-release)
22
+
23
+ - Refactor attributes & backend plugins and make `mobility_attributes` public
24
+ ([#462](https://github.com/shioyama/mobility/pull/462))
25
+ - Make attribute_methods plugin depend on attributes
26
+ ([#461](https://github.com/shioyama/mobility/pull/461))
27
+
28
+ ## 1.0.0.beta1 (pre-release)
29
+
30
+ - Remove `Mobility::Backend#apply_plugin`
31
+ ([#454](https://github.com/shioyama/mobility/pull/454))
32
+ - Instance exec configure block if it takes no arguments
33
+ ([#456](https://github.com/shioyama/mobility/pull/456))
34
+ - Raise an exception if invalid options are passed to Translations initializer
35
+ ([#457](https://github.com/shioyama/mobility/pull/457/files))
36
+ - Fix Ruby 2.7 deprecation warnings
37
+ ([#460](https://github.com/shioyama/mobility/pull/460))
38
+
39
+ ## 1.0.0.alpha (pre-release)
40
+
41
+ - Default fallbacks plugin to `true` when enabled
42
+ ([#447](https://github.com/shioyama/mobility/pull/447))
43
+ - Remove `Mobility::Backend.method_name`
44
+ ([#400](https://github.com/shioyama/mobility/pull/400))
45
+ - Remove `translated_attribute_names` as alias for `mobility_attributes`
46
+ ([#402](https://github.com/shioyama/mobility/pull/402))
47
+ - Move `_backend` methods into `backend_reader` plugin
48
+ ([#403](https://github.com/shioyama/mobility/pull/403))
49
+ - Replace `Configuration#query_method` configuration with Query plugin option
50
+ ([#414](https://github.com/shioyama/mobility/pull/414))
51
+ - Remove `Mobility::Configuration#default_accessor_locales`. Use plugin option
52
+ to configure global default instead.
53
+ ([#424](https://github.com/shioyama/mobility/pull/424))
54
+ - Pass `model_class` to `Mobility::Backend#configure` via class method rather
55
+ than on options hash ([#429](https://github.com/shioyama/mobility/pull/429))
56
+ - Remove `Mobility.new_fallbacks` and `Configuration#fallbacks_generator`
57
+ ([#433](https://github.com/shioyama/mobility/pull/433))
58
+ - Rename `backend_name` to `backend`
59
+ ([#443](https://github.com/shioyama/mobility/pull/443))
60
+ - Remove `Configuration#accessor_method`
61
+ ([#450](https://github.com/shioyama/mobility/pull/450))
62
+ - Rename `Mobility::Attributes` to `Mobility::Translations`
63
+ - Remove `Mobility::Configuration` altogether
64
+ ([#452](https://github.com/shioyama/mobility/pull/452))
65
+
3
66
  ## 0.8
4
67
 
5
68
  ### 0.8.13 (May 27, 2020)
data/Gemfile CHANGED
@@ -29,8 +29,6 @@ group :development, :test do
29
29
  else
30
30
  raise ArgumentError, 'Invalid ActiveRecord version'
31
31
  end
32
-
33
- gem "generator_spec", '~> 0.9.4'
34
32
  when 'sequel'
35
33
  orm_version ||= '5'
36
34
  case orm_version
@@ -48,6 +46,11 @@ group :development, :test do
48
46
 
49
47
  gem 'allocation_stats' if ENV['FEATURE'] == 'performance'
50
48
 
49
+ if ENV['FEATURE'] == 'rails'
50
+ gem 'rails'
51
+ gem 'generator_spec', '~> 0.9.4'
52
+ end
53
+
51
54
  platforms :ruby do
52
55
  gem 'guard-rspec'
53
56
  gem 'pry-byebug'
@@ -1,20 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (1.0.alpha.1)
4
+ mobility (1.0.0.rc1)
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.8.2)
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)
22
+ benchmark-ips (2.8.3)
12
23
  byebug (11.1.3)
13
- coderay (1.1.2)
14
- concurrent-ruby (1.1.6)
24
+ coderay (1.1.3)
25
+ concurrent-ruby (1.1.7)
15
26
  database_cleaner (1.8.5)
16
- diff-lcs (1.3)
17
- ffi (1.12.2)
27
+ diff-lcs (1.4.4)
28
+ ffi (1.13.1)
18
29
  formatador (0.2.5)
19
30
  guard (2.16.2)
20
31
  formatador (>= 0.2.4)
@@ -30,55 +41,63 @@ GEM
30
41
  guard (~> 2.1)
31
42
  guard-compat (~> 1.1)
32
43
  rspec (>= 2.99.0, < 4.0)
33
- i18n (1.8.2)
44
+ i18n (1.8.5)
34
45
  concurrent-ruby (~> 1.0)
35
46
  listen (3.2.1)
36
47
  rb-fsevent (~> 0.10, >= 0.10.3)
37
48
  rb-inotify (~> 0.9, >= 0.9.10)
38
- lumberjack (1.2.4)
49
+ lumberjack (1.2.8)
39
50
  method_source (1.0.0)
51
+ minitest (5.14.2)
40
52
  nenv (0.3.0)
41
53
  notiffany (0.1.3)
42
54
  nenv (~> 0.1)
43
55
  shellany (~> 0.0)
56
+ pg (1.2.3)
44
57
  pry (0.13.1)
45
58
  coderay (~> 1.1)
46
59
  method_source (~> 1.0)
47
60
  pry-byebug (3.9.0)
48
61
  byebug (~> 11.0)
49
62
  pry (~> 0.13.0)
50
- rack (2.2.2)
63
+ rack (2.2.3)
51
64
  rake (12.3.3)
52
65
  rb-fsevent (0.10.4)
53
66
  rb-inotify (0.10.1)
54
67
  ffi (~> 1.0)
55
68
  request_store (1.5.0)
56
69
  rack (>= 1.4)
57
- rspec (3.9.0)
58
- rspec-core (~> 3.9.0)
59
- rspec-expectations (~> 3.9.0)
60
- rspec-mocks (~> 3.9.0)
61
- rspec-core (3.9.2)
62
- rspec-support (~> 3.9.3)
63
- rspec-expectations (3.9.2)
70
+ rspec (3.10.0)
71
+ rspec-core (~> 3.10.0)
72
+ rspec-expectations (~> 3.10.0)
73
+ rspec-mocks (~> 3.10.0)
74
+ rspec-core (3.10.0)
75
+ rspec-support (~> 3.10.0)
76
+ rspec-expectations (3.10.0)
64
77
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.9.0)
66
- rspec-mocks (3.9.1)
78
+ rspec-support (~> 3.10.0)
79
+ rspec-mocks (3.10.0)
67
80
  diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.9.0)
69
- rspec-support (3.9.3)
81
+ rspec-support (~> 3.10.0)
82
+ rspec-support (3.10.0)
70
83
  shellany (0.0.1)
71
84
  thor (1.0.1)
85
+ thread_safe (0.3.6)
86
+ tzinfo (1.2.8)
87
+ thread_safe (~> 0.1)
72
88
  yard (0.9.25)
89
+ zeitwerk (2.4.1)
73
90
 
74
91
  PLATFORMS
75
92
  ruby
76
93
 
77
94
  DEPENDENCIES
95
+ activerecord (>= 6.0.0, < 6.1)
78
96
  benchmark-ips
79
97
  database_cleaner (~> 1.5, >= 1.5.3)
80
98
  guard-rspec
81
99
  mobility!
100
+ pg
82
101
  pry-byebug
83
102
  rake (~> 12, >= 12.2.1)
84
103
  rspec (~> 3.0)
data/README.md CHANGED
@@ -2,16 +2,20 @@ Mobility
2
2
  ========
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/mobility.svg)][gem]
5
- [![Build Status](https://travis-ci.org/shioyama/mobility.svg?branch=master)][travis]
5
+ [![Build Status](https://github.com/shioyama/mobility/workflows/CI/badge.svg)][actions]
6
6
  [![Code Climate](https://api.codeclimate.com/v1/badges/72200f2b00c339ec4537/maintainability.svg)][codeclimate]
7
7
  [![Gitter Chat](https://badges.gitter.im/mobility-ruby/mobility.svg)](https://gitter.im/mobility-ruby/mobility)
8
8
 
9
9
  [gem]: https://rubygems.org/gems/mobility
10
- [travis]: https://travis-ci.org/shioyama/mobility
10
+ [actions]: https://github.com/shioyama/mobility/actions
11
11
  [codeclimate]: https://codeclimate.com/github/shioyama/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 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-stable
17
+ branch](https://github.com/shioyama/mobility/tree/0-8-stable).**
18
+
15
19
  Mobility is a gem for storing and retrieving translations as attributes on a
16
20
  class. These translations could be the content of blog posts, captions on
17
21
  images, tags on bookmarks, or anything else you might want to store in
@@ -36,10 +40,10 @@ and [Sequel](http://sequel.jeremyevans.net/) ORM, with support for other
36
40
  platforms planned.
37
41
 
38
42
  For a detailed introduction to Mobility, see [Translating with
39
- Mobility](http://dejimata.com/2017/3/3/translating-with-mobility). See also the
40
- [Roadmap](https://github.com/shioyama/mobility/wiki/Roadmap) for what's in the
41
- works for future releases, and other pages of the [wiki][wiki] for more detail
42
- on usage.
43
+ Mobility](http://dejimata.com/2017/3/3/translating-with-mobility). See also my
44
+ talk at RubyConf 2018, [Building Generic
45
+ Software](https://www.youtube.com/watch?v=RZkemV_-__A), where I explain the
46
+ thinking behind Mobility's design.
43
47
 
44
48
  If you're coming from Globalize, be sure to also read the [Migrating from
45
49
  Globalize](https://github.com/shioyama/mobility/wiki/Migrating-from-Globalize)
@@ -48,22 +52,15 @@ section of the wiki.
48
52
  Installation
49
53
  ------------
50
54
 
51
- Add this line to your application's Gemfile:
55
+ To use the latest pre-version of Mobility 1.0, add this line to your
56
+ application's Gemfile:
52
57
 
53
58
  ```ruby
54
- gem 'mobility', '~> 0.8.13'
55
- ```
56
-
57
- Mobility is cryptographically signed. To be sure the gem you install hasn't
58
- been tampered with, add my public key as a trusted certificate and install:
59
-
60
- ```
61
- gem cert --add <(curl -Ls https://raw.github.com/shioyama/mobility/master/certs/shioyama.pem)
62
- gem install mobility -P MediumSecurity
59
+ gem 'mobility', '~> 1.0.0'
63
60
  ```
64
61
 
65
- The MediumSecurity trust profile will verify signed gems, but allow the
66
- installation of unsigned dependencies.
62
+ For the latest stable version of Mobility, see the readme on the
63
+ [0-8-stable](https://github.com/shioyama/mobility/tree/0-8-stable) branch.
67
64
 
68
65
  ### ActiveRecord (Rails)
69
66
 
@@ -72,7 +69,7 @@ Requirements:
72
69
 
73
70
  (Support for most backends and features is also supported with
74
71
  ActiveRecord/Rails 4.2, but there are some tests still failing. To see exactly
75
- what might not work, check pending specs in Rails 4.2 Travis builds.)
72
+ what might not work, check pending specs in Rails 4.2 builds.)
76
73
 
77
74
  To translate attributes on a model, extend `Mobility`, then call `translates`
78
75
  passing in one or more attributes as well as a hash of options (see below).
@@ -89,36 +86,52 @@ rails generate mobility:install
89
86
  the `--without_tables` option here to skip the migration generation.)
90
87
 
91
88
  The generator will create an initializer file `config/initializers/mobility.rb`
92
- with the lines:
89
+ which looks something like this:
93
90
 
94
91
  ```ruby
95
- Mobility.configure do |config|
96
- config.default_backend = :key_value
97
- config.accessor_method = :translates
98
- config.query_method = :i18n
92
+ Mobility.configure do
93
+
94
+ # PLUGINS
95
+ plugins do
96
+ backend :key_value
97
+
98
+ active_record
99
+
100
+ reader
101
+ writer
102
+
103
+ # ...
104
+ end
99
105
  end
100
106
  ```
101
107
 
102
- To use a different default backend, set `default_backend` to another value (see
103
- possibilities [below](#backends)).
108
+ Each method call inside the block passed to `plugins` declares a plugin, along
109
+ with an optional default. To use a different default backend, you can
110
+ change the default passed to the `backend` plugin, like this:
111
+
112
+ ```diff
113
+ Mobility.configure do
114
+
115
+ # PLUGINS
116
+ plugins do
117
+ - backend :key_value
118
+ + backend :table
119
+ ```
104
120
 
105
- You will likely also want to set default values for the various translation
106
- options described below. You can set these defaults by assigning values to keys
107
- on the `config.default_options` hash. Below, we turn on the Dirty plugin by
108
- default, so it will be enabled for all models.
121
+ See other possible backends in the [backends section](#backends).
109
122
 
110
123
  You can also set defaults for backend-specific options. Below, we set the
111
- default `type` option for the KeyValue backend to `:string` (this is
112
- unnecessary and will be ignored if you are using a different backend).
124
+ default `type` option for the KeyValue backend to `:string`.
113
125
 
114
126
  ```diff
115
- Mobility.configure do |config|
116
- config.default_backend = :key_value
117
- config.accessor_method = :translates
118
- config.query_method = :i18n
119
- + config.default_options[:dirty] = true
120
- + config.default_options[:type] = :string
121
- end
127
+ Mobility.configure do
128
+
129
+ # PLUGINS
130
+ plugins do
131
+ - backend :key_value
132
+ + backend :key_value, type: :string
133
+ end
134
+ end
122
135
  ```
123
136
 
124
137
  We will assume the configuration above in the examples that follow. Other
@@ -132,6 +145,16 @@ See [Getting Started](#quickstart) to get started translating your models.
132
145
  Requirements:
133
146
  - Sequel >= 4.0
134
147
 
148
+ When configuring Mobility, ensure that you include the `sequel` plugin:
149
+
150
+ ```diff
151
+ plugins do
152
+ backend :key_value
153
+
154
+ - active_record
155
+ + sequel
156
+ ```
157
+
135
158
  You can extend `Mobility` just like in ActiveRecord, or you can use the
136
159
  `mobility` plugin, which does the same thing:
137
160
 
@@ -143,8 +166,8 @@ end
143
166
  ```
144
167
 
145
168
  Otherwise everything is (almost) identical to AR, with the exception that there
146
- is no equivalent to a Rails generator (so you will need to create the migration
147
- for any translation table(s) yourself, using Rails generators as a reference).
169
+ is no equivalent to a Rails generator, so you will need to create the migration
170
+ for any translation table(s) yourself, using Rails generators as a reference.
148
171
 
149
172
  The models in examples below all inherit from `ApplicationRecord`, but
150
173
  everything works exactly the same if the parent class is `Sequel::Model`.
@@ -259,15 +282,25 @@ changed and/or customized (see the [Backends](#backends) section below).
259
282
  ### <a name="getset"></a> Getting and Setting Translations
260
283
 
261
284
  The easiest way to get or set a translation is to use the getter and setter
262
- methods described above (`word.name` and `word.name=`), but you may want to
263
- access the value of an attribute in a specific locale, independent of the
264
- current value of `I18n.locale` (or `Mobility.locale`). There are a few ways to
265
- do this.
285
+ methods described above (`word.name` and `word.name=`), enabled by including
286
+ the `reader` and `writer` plugins.
287
+
288
+ You may also want to access the value of an attribute in a specific locale,
289
+ independent of the current value of `I18n.locale` (or `Mobility.locale`). There
290
+ are a few ways to do this.
266
291
 
267
292
  The first way is to define locale-specific methods, one for each locale you
268
293
  want to access directly on a given attribute. These are called "locale
269
- accessors" in Mobility, and they can be defined by passing a `locale_accessors`
270
- option when defining translated attributes on the model class:
294
+ accessors" in Mobility, and can be enabled by including the `locale_accessors`
295
+ plugin, with a default set of accessors:
296
+
297
+ ```diff
298
+ plugins do
299
+ # ...
300
+ + locale_accessors [:en, :ja]
301
+ ```
302
+
303
+ You can also override this default from `translates` in any model:
271
304
 
272
305
  ```ruby
273
306
  class Word < ApplicationRecord
@@ -296,24 +329,23 @@ word.name_ru
296
329
  #=> NoMethodError: undefined method `name_ru' for #<Word id: ... >
297
330
  ```
298
331
 
299
- To generate methods for all locales in `I18n.available_locales` (at the time
300
- the model is first loaded), use `locale_accessors: true`.
332
+ With no plugin option (or a default of `true`), Mobility generates methods for
333
+ all locales in `I18n.available_locales` at the time the model is first loaded.
301
334
 
302
- An alternative to using the `locale_accessors` option is to use the
303
- `fallthrough_accessors` option, with `fallthrough_accessors: true`. This uses
304
- Ruby's [`method_missing`](http://apidock.com/ruby/BasicObject/method_missing)
305
- method to implicitly define the same methods as above, but supporting any
306
- locale without any method definitions. (Locale accessors and fallthrough
307
- locales can be used together without conflict, with locale accessors taking
308
- precedence if defined for a given locale.)
335
+ An alternative to using the `locale_accessors` plugin is to use the
336
+ `fallthrough_accessors` plugin. This uses Ruby's
337
+ [`method_missing`](http://apidock.com/ruby/BasicObject/method_missing) method
338
+ to implicitly define the same methods as above, but supporting any locale
339
+ without any method definitions. (Locale accessors and fallthrough locales can
340
+ be used together without conflict, with locale accessors taking precedence if
341
+ defined for a given locale.)
309
342
 
310
- For example, if we define `Word` this way:
343
+ Ensure the plugin is enabled:
311
344
 
312
- ```ruby
313
- class Word < ApplicationRecord
314
- extend Mobility
315
- translates :name, fallthrough_accessors: true
316
- end
345
+ ```diff
346
+ plugins do
347
+ # ...
348
+ + fallthrough_accessors
317
349
  ```
318
350
 
319
351
  ... then we can access any locale we want, without specifying them upfront:
@@ -374,11 +406,24 @@ word.name_backend.read(:en)
374
406
  ```
375
407
 
376
408
  Internally, all methods for accessing translated attributes ultimately end up
377
- reading and writing from the backend instance this way.
409
+ reading and writing from the backend instance this way. (The `write` methods
410
+ do not call underlying backend's methods to persist the change. This is up to
411
+ the user, so e.g. with ActiveRecord you should call `save` write the changes to
412
+ the database).
378
413
 
379
- The `write` methods do not call underlying backend's methods to persist the change.
380
- This is up to the user (e.g. with ActiveRecord you should call `save` write
381
- the changes to the database).
414
+ Note that accessor methods are defined in an included module, so you can wrap
415
+ reads or writes in custom logic:
416
+
417
+ ```ruby
418
+ class Post < ApplicationRecord
419
+ extend Mobility
420
+ translates :title
421
+
422
+ def title(*)
423
+ super.reverse
424
+ end
425
+ end
426
+ ```
382
427
 
383
428
  ### Setting the Locale
384
429
 
@@ -419,15 +464,28 @@ details on how to configure it for your use case.
419
464
 
420
465
  ### <a name="fallbacks"></a>Fallbacks
421
466
 
422
- Mobility offers basic support for translation fallbacks. To enable fallbacks,
423
- pass a hash with fallbacks for each locale as an option when defining
467
+ Mobility offers basic support for translation fallbacks. First, enable the
468
+ `fallbacks` plugin:
469
+
470
+ ```diff
471
+ plugins do
472
+ # ...
473
+ + fallbacks
474
+ + locale_accessors
475
+ ```
476
+
477
+ Fallbacks will require `fallthrough_accessors` to handle methods like
478
+ `title_en`, which are used to track changes. For performance reasons it's
479
+ generally best to also enable the `locale_accessors` plugin as shown above.
480
+
481
+ Now pass a hash with fallbacks for each locale as an option when defining
424
482
  translated attributes on a class:
425
483
 
426
484
  ```ruby
427
485
  class Word < ApplicationRecord
428
486
  extend Mobility
429
- translates :name, fallbacks: { de: :ja, fr: :ja }, locale_accessors: true
430
- translates :meaning, fallbacks: { de: :ja, fr: :ja }, locale_accessors: true
487
+ translates :name, fallbacks: { de: :ja, fr: :ja }
488
+ translates :meaning, fallbacks: { de: :ja, fr: :ja }
431
489
  end
432
490
  ```
433
491
 
@@ -516,7 +574,16 @@ fallbacks](https://github.com/svenfuchs/i18n/wiki/Fallbacks).
516
574
 
517
575
  ### <a name="default"></a>Default values
518
576
 
519
- Another option is to assign a default value, which will be used if the result of a fetch would otherwise be `nil`:
577
+ Another option is to assign a default value, using the `default` plugin:
578
+
579
+ ```diff
580
+ plugins do
581
+ # ...
582
+ + default 'foo'
583
+ ```
584
+
585
+ Here we've set a "default default" of `'foo'`, which will be returned if a fetch would
586
+ otherwise return `nil`. This can be overridden from model classes:
520
587
 
521
588
  ```ruby
522
589
  class Word < ApplicationRecord
@@ -558,24 +625,29 @@ support it. Currently this is models which include
558
625
  [dirty](http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/Dirty.html)
559
626
  plugin).
560
627
 
561
- Enabling dirty tracking is as simple as sending the `dirty: true` option when
562
- defining a translated attribute. The way dirty tracking works is somewhat
563
- dependent on the model class (ActiveModel or Sequel); we will describe the
564
- ActiveModel implementation here.
628
+ First, ensure the `dirty` plugin is enabled in your configuration, and that you
629
+ have enabled an ORM plugin (either `active_record` or `sequel`), since the
630
+ dirty plugin will depend on one of these being enabled.
631
+
632
+ ```diff
633
+ plugins do
634
+ # ...
635
+ active_record
636
+ + dirty
637
+ ```
638
+
639
+ (Once enabled globally, the dirty plugin can be selectively disabled on classes
640
+ by passing `dirty: false` to `translates`.)
565
641
 
566
- First, enable dirty tracking (note that this is a persisted AR model, although
567
- dirty tracking is not specific to AR and works for non-persisted models as well):
642
+ Take this ActiveRecord class:
568
643
 
569
644
  ```ruby
570
645
  class Post < ApplicationRecord
571
646
  extend Mobility
572
- translates :title, dirty: true
647
+ translates :title
573
648
  end
574
649
  ```
575
650
 
576
- (If you want to enable dirty tracking on all models, set the
577
- `config.default_options[:dirty]` option in your Mobility configuration.)
578
-
579
651
  Let's assume we start with a post with a title in English and Japanese:
580
652
 
581
653
  ```ruby
@@ -637,9 +709,6 @@ For performance reasons, it is highly recommended that when using the Dirty
637
709
  plugin, you also enable [locale accessors](#getset) for all locales which will
638
710
  be used, so that methods like `title_en` above are defined; otherwise they will
639
711
  be caught by `method_missing` (using fallthrough accessors), which is much slower.
640
- The easiest way to do this is to set `config.default_options[:locale_accessors]
641
- = true` in your Mobility config, and make sure that `I18n.available_locales`
642
- includes all locales you use in production.
643
712
 
644
713
  For more details on dirty tracking, see the [API
645
714
  documentation](http://www.rubydoc.info/gems/mobility/Mobility/Plugins/Dirty).
@@ -647,9 +716,17 @@ documentation](http://www.rubydoc.info/gems/mobility/Mobility/Plugins/Dirty).
647
716
  ### Cache
648
717
 
649
718
  The Mobility cache caches localized values that have been fetched once so they
650
- can be quickly retrieved again. The cache is enabled by default and should
651
- generally only be disabled when debugging; this can be done by passing `cache:
652
- false` when defining an attribute, like this:
719
+ can be quickly retrieved again. The cache plugin is included in the default
720
+ configuration created by the install generator:
721
+
722
+ ```diff
723
+ plugins do
724
+ # ...
725
+ + cache
726
+ ```
727
+
728
+ It can be disabled selectively per model by passing `cache: false` when
729
+ defining an attribute, like this:
653
730
 
654
731
  ```ruby
655
732
  class Word < ApplicationRecord
@@ -659,7 +736,8 @@ end
659
736
  ```
660
737
 
661
738
  You can also turn off the cache for a single fetch by passing `cache: false` to
662
- the getter method, i.e. `post.title(cache: false)`.
739
+ the getter method, i.e. `post.title(cache: false)`. To remove the cache plugin
740
+ entirely, remove the `cache` line from the global plugins configuration.
663
741
 
664
742
  The cache is normally just a hash with locale keys and string (translation)
665
743
  values, but some backends (e.g. KeyValue and Table backends) have slightly more
@@ -667,11 +745,23 @@ complex implementations.
667
745
 
668
746
  ### <a name="querying"></a>Querying
669
747
 
670
- Mobility backends also support querying on translated attributes, in two
671
- different ways. The first is via query methods like `where` (and `not` and
672
- `find_by` in ActiveRecord, and `except` in Sequel). To query this way, use the
673
- `i18n` class method, which will return a model relation or dataset extended
674
- with Mobility-specific query method overrides.
748
+ Mobility backends also support querying on translated attributes. To enable
749
+ this feature, include the `query` plugin, and ensure you also have an ORM
750
+ plugin enabled (`active_record` or `sequel`):
751
+
752
+ ```diff
753
+ plugins do
754
+ # ...
755
+ active_record
756
+ + query
757
+ ```
758
+
759
+ Querying defines a scope or dataset class method, whose default name is `i18n`.
760
+ You can override this by passing a default in the configuration, like
761
+ `query :t` to use a name `t`.
762
+
763
+ Querying is supported in two different ways. The first is via query methods
764
+ like `where` (and `not` and `find_by` in ActiveRecord, and `except` in Sequel).
675
765
 
676
766
  So for ActiveRecord, assuming a model using KeyValue as its default backend:
677
767