mobility 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +3 -2
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +39 -1
  5. data/Gemfile.lock +65 -10
  6. data/README.md +63 -27
  7. data/lib/mobility.rb +16 -31
  8. data/lib/mobility/active_record.rb +2 -12
  9. data/lib/mobility/active_record/uniqueness_validator.rb +9 -8
  10. data/lib/mobility/arel.rb +20 -0
  11. data/lib/mobility/arel/nodes.rb +16 -0
  12. data/lib/mobility/arel/nodes/pg_ops.rb +136 -0
  13. data/lib/mobility/arel/visitor.rb +61 -0
  14. data/lib/mobility/attributes.rb +82 -19
  15. data/lib/mobility/backend.rb +53 -8
  16. data/lib/mobility/backend_resetter.rb +2 -1
  17. data/lib/mobility/backends/active_record.rb +31 -11
  18. data/lib/mobility/backends/active_record/column.rb +7 -3
  19. data/lib/mobility/backends/active_record/container.rb +23 -21
  20. data/lib/mobility/backends/active_record/hstore.rb +11 -6
  21. data/lib/mobility/backends/active_record/json.rb +22 -16
  22. data/lib/mobility/backends/active_record/jsonb.rb +22 -16
  23. data/lib/mobility/backends/active_record/key_value.rb +123 -15
  24. data/lib/mobility/backends/active_record/pg_hash.rb +1 -2
  25. data/lib/mobility/backends/active_record/serialized.rb +7 -6
  26. data/lib/mobility/backends/active_record/table.rb +145 -24
  27. data/lib/mobility/backends/hash_valued.rb +15 -10
  28. data/lib/mobility/backends/key_value.rb +12 -12
  29. data/lib/mobility/backends/sequel/container.rb +3 -9
  30. data/lib/mobility/backends/sequel/hstore.rb +2 -2
  31. data/lib/mobility/backends/sequel/json.rb +15 -15
  32. data/lib/mobility/backends/sequel/jsonb.rb +14 -14
  33. data/lib/mobility/backends/sequel/key_value.rb +0 -11
  34. data/lib/mobility/backends/sequel/pg_hash.rb +2 -3
  35. data/lib/mobility/backends/sequel/pg_query_methods.rb +1 -1
  36. data/lib/mobility/backends/sequel/query_methods.rb +3 -3
  37. data/lib/mobility/backends/sequel/serialized.rb +2 -2
  38. data/lib/mobility/backends/sequel/table.rb +10 -11
  39. data/lib/mobility/backends/table.rb +17 -8
  40. data/lib/mobility/configuration.rb +4 -1
  41. data/lib/mobility/interface.rb +0 -0
  42. data/lib/mobility/plugins.rb +1 -0
  43. data/lib/mobility/plugins/active_record/query.rb +192 -0
  44. data/lib/mobility/plugins/cache.rb +1 -2
  45. data/lib/mobility/plugins/default.rb +28 -14
  46. data/lib/mobility/plugins/fallbacks.rb +1 -1
  47. data/lib/mobility/plugins/locale_accessors.rb +13 -9
  48. data/lib/mobility/plugins/presence.rb +15 -7
  49. data/lib/mobility/plugins/query.rb +28 -0
  50. data/lib/mobility/translates.rb +9 -9
  51. data/lib/mobility/version.rb +1 -1
  52. data/lib/rails/generators/mobility/templates/initializer.rb +1 -0
  53. metadata +10 -15
  54. metadata.gz.sig +0 -0
  55. data/lib/mobility/accumulator.rb +0 -33
  56. data/lib/mobility/adapter.rb +0 -20
  57. data/lib/mobility/backends/active_record/column/query_methods.rb +0 -42
  58. data/lib/mobility/backends/active_record/container/json_query_methods.rb +0 -36
  59. data/lib/mobility/backends/active_record/container/jsonb_query_methods.rb +0 -33
  60. data/lib/mobility/backends/active_record/hstore/query_methods.rb +0 -25
  61. data/lib/mobility/backends/active_record/json/query_methods.rb +0 -30
  62. data/lib/mobility/backends/active_record/jsonb/query_methods.rb +0 -26
  63. data/lib/mobility/backends/active_record/key_value/query_methods.rb +0 -76
  64. data/lib/mobility/backends/active_record/pg_query_methods.rb +0 -154
  65. data/lib/mobility/backends/active_record/serialized/query_methods.rb +0 -34
  66. data/lib/mobility/backends/active_record/table/query_methods.rb +0 -105
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aa18719235ac4c4f4dc7a50391d1aaa98e9963a0
4
- data.tar.gz: 2aea9e420788a09176509fff75f1eb397656d6cd
2
+ SHA256:
3
+ metadata.gz: e5043fe3bb4af2f09abf2cb81541680639b650777657e4ca776e178295b17ef8
4
+ data.tar.gz: cc8bead5891cd7ddcaf3d1166eb03102705c820551ffd75563219d293a2badc8
5
5
  SHA512:
6
- metadata.gz: d59832bfc7f2e3b0672b5f8d690ec167731e49225cd2d135f1325fd4ac934a22bf040c3ddaaed9a56cb7e6d9ac6b050f0fb7458f6f7f8e456a6391a9337ad6ec
7
- data.tar.gz: 8a0dde22222134bad52a65e47a83e4cc6829d3a5273aef7be06ca25491c01bdc3e53bd609079c65d45c16328506b1f4a88fc9ab43612ac8272f3d4485fc073a7
6
+ metadata.gz: b2753f7b33cac63eba6f8edee4a328cea6cc2f9f5ec36cf19a50a71731b7c1b1474b061c86ec82abd8b096b8aeb43d1e5900da8f17fd9e8c72d70052dbc8672b
7
+ data.tar.gz: 3eee2b8e73d06235472c3f1766eb64d2da8fd0367710d69865442c93c38a555fef6a8155f797d0e221ebb1fa74498786221b2da7896760841aaa2f20b2bf99ac
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- �=^��&(2x�Pf�^�n�_BE�i�ԟ;42?���ƴ�Ǿާ��Q���v����~l�YwW�w@��!
2
- ��ƕyi���ϟ�
1
+ #G��j�*l�:�)��y �� [��w 33��dNz����`
2
+ �<�[��P����$�;����tS/趔9�v��Itm �ƒ\eP����F�_�y�n�WJܔhM������ES�;�� ���F,��x%�E�t7����aՑ��I��edd����&��)ױv����MB��,�l�d��eS�e���t3�3�:eQ�؛H����q��eJ9������N/�p<_���
3
+ n2Ў �g���.����ߋ,K
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,8 +1,46 @@
1
1
  # Mobility Changelog
2
2
 
3
+ ## 0.7
4
+
5
+ ### 0.7.0 (May 30, 2018)
6
+
7
+ * Restructure querying into plugin (ActiveRecord only)
8
+ ([#216](https://github.com/shioyama/mobility/pull/216),
9
+ [#225](https://github.com/shioyama/mobility/pull/225),
10
+ [#222](https://github.com/shioyama/mobility/pull/222),
11
+ * Support querying on multiple locales at once
12
+ ([#232](https://github.com/shioyama/mobility/pull/232))
13
+ * Allow passing locale to query methods
14
+ ([#233](https://github.com/shioyama/mobility/pull/233))
15
+ * Support matches and lower predicate methods
16
+ ([#235](https://github.com/shioyama/mobility/pull/235))
17
+ * Implement case-insensitive uniqueness validation
18
+ ([#236](https://github.com/shioyama/mobility/pull/236),
19
+ [#237](https://github.com/shioyama/mobility/pull/237))
20
+ * Support equality predicates between jsonb nodes
21
+ ([#240](https://github.com/shioyama/mobility/pull/240))
22
+ * Prefer -> operator when comparing jsonb columns
23
+ ([#241](https://github.com/shioyama/mobility/pull/241))
24
+ * Define options on subclassed backend class
25
+ ([#218](https://github.com/shioyama/mobility/pull/218))
26
+ * Add column_affix
27
+ * Use module_eval to define locale_accessors
28
+ ([#219](https://github.com/shioyama/mobility/pull/219))
29
+ * Improve performance of getters/setters
30
+ ([#220](https://github.com/shioyama/mobility/pull/220))
31
+ * Do not include Default plugin by default
32
+ ([#223](https://github.com/shioyama/mobility/pull/223))
33
+ * Add specific attribute types to basic usage example
34
+ ([#228](https://github.com/shioyama/mobility/pull/228)). Thanks
35
+ [thatguysimon](https://github.com/thatguysimon)!
36
+ * Remove Mobility::Interface
37
+ ([#229](https://github.com/shioyama/mobility/pull/229))
38
+ * Freeze attributes array
39
+ ([#230](https://github.com/shioyama/mobility/pull/230))
40
+
3
41
  ## 0.6
4
42
 
5
- ### 0.6.1 (April 26, 2018)
43
+ ### 0.6.0 (April 26, 2018)
6
44
 
7
45
  * Add column_prefix/column_suffix options to hash backends
8
46
  ([#200](https://github.com/shioyama/mobility/pull/199) and
data/Gemfile.lock CHANGED
@@ -8,14 +8,45 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ actionpack (5.2.0)
12
+ actionview (= 5.2.0)
13
+ activesupport (= 5.2.0)
14
+ rack (~> 2.0)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.2.0)
19
+ activesupport (= 5.2.0)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
+ activemodel (5.2.0)
25
+ activesupport (= 5.2.0)
26
+ activerecord (5.2.0)
27
+ activemodel (= 5.2.0)
28
+ activesupport (= 5.2.0)
29
+ arel (>= 9.0)
30
+ activesupport (5.2.0)
31
+ concurrent-ruby (~> 1.0, >= 1.0.2)
32
+ i18n (>= 0.7, < 2)
33
+ minitest (~> 5.1)
34
+ tzinfo (~> 1.1)
35
+ arel (9.0.0)
11
36
  benchmark-ips (2.7.2)
12
- byebug (10.0.0)
37
+ builder (3.2.3)
38
+ byebug (10.0.2)
13
39
  coderay (1.1.2)
14
40
  concurrent-ruby (1.0.5)
15
- database_cleaner (1.6.2)
41
+ crass (1.0.4)
42
+ database_cleaner (1.7.0)
16
43
  diff-lcs (1.3)
44
+ erubi (1.7.1)
17
45
  ffi (1.9.23)
18
46
  formatador (0.2.5)
47
+ generator_spec (0.9.4)
48
+ activesupport (>= 3.0.0)
49
+ railties (>= 3.0.0)
19
50
  guard (2.14.2)
20
51
  formatador (>= 0.2.4)
21
52
  listen (>= 2.7, < 4.0)
@@ -30,16 +61,23 @@ GEM
30
61
  guard (~> 2.1)
31
62
  guard-compat (~> 1.1)
32
63
  rspec (>= 2.99.0, < 4.0)
33
- i18n (1.0.0)
64
+ i18n (1.0.1)
34
65
  concurrent-ruby (~> 1.0)
35
66
  listen (3.1.5)
36
67
  rb-fsevent (~> 0.9, >= 0.9.4)
37
68
  rb-inotify (~> 0.9, >= 0.9.7)
38
69
  ruby_dep (~> 1.2)
39
- lumberjack (1.0.12)
70
+ loofah (2.2.2)
71
+ crass (~> 1.0.2)
72
+ nokogiri (>= 1.5.9)
73
+ lumberjack (1.0.13)
40
74
  method_source (0.9.0)
75
+ mini_portile2 (2.3.0)
76
+ minitest (5.11.3)
41
77
  mysql2 (0.4.10)
42
78
  nenv (0.3.0)
79
+ nokogiri (1.8.2)
80
+ mini_portile2 (~> 2.3.0)
43
81
  notiffany (0.1.1)
44
82
  nenv (~> 0.1)
45
83
  shellany (~> 0.0)
@@ -50,8 +88,21 @@ GEM
50
88
  pry-byebug (3.6.0)
51
89
  byebug (~> 10.0)
52
90
  pry (~> 0.10)
53
- rack (2.0.4)
54
- rake (12.3.0)
91
+ rack (2.0.5)
92
+ rack-test (1.0.0)
93
+ rack (>= 1.0, < 3)
94
+ rails-dom-testing (2.0.3)
95
+ activesupport (>= 4.2.0)
96
+ nokogiri (>= 1.6)
97
+ rails-html-sanitizer (1.0.4)
98
+ loofah (~> 2.2, >= 2.2.2)
99
+ railties (5.2.0)
100
+ actionpack (= 5.2.0)
101
+ activesupport (= 5.2.0)
102
+ method_source
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.18.1, < 2.0)
105
+ rake (12.3.1)
55
106
  rb-fsevent (0.10.3)
56
107
  rb-inotify (0.9.10)
57
108
  ffi (>= 0.5.0, < 2)
@@ -71,29 +122,33 @@ GEM
71
122
  rspec-support (~> 3.7.0)
72
123
  rspec-support (3.7.1)
73
124
  ruby_dep (1.5.0)
74
- sequel (5.7.1)
75
125
  shellany (0.0.1)
76
126
  sqlite3 (1.3.13)
77
127
  thor (0.20.0)
78
- yard (0.9.12)
128
+ thread_safe (0.3.6)
129
+ tzinfo (1.2.5)
130
+ thread_safe (~> 0.1)
131
+ yard (0.9.13)
79
132
 
80
133
  PLATFORMS
81
134
  ruby
82
135
 
83
136
  DEPENDENCIES
137
+ activerecord (>= 5.2.0.rc2, < 5.3)
84
138
  benchmark-ips
85
139
  bundler (~> 1.12)
86
140
  database_cleaner (~> 1.5, >= 1.5.3)
141
+ generator_spec (~> 0.9.4)
87
142
  guard-rspec
88
143
  mobility!
89
144
  mysql2 (~> 0.4.9)
90
145
  pg (< 1.0)
91
146
  pry-byebug
147
+ railties (>= 5.2.0.rc2, < 5.3)
92
148
  rake (~> 12, >= 12.2.1)
93
149
  rspec (~> 3.0)
94
- sequel (>= 5.0.0, < 6.0.0)
95
150
  sqlite3
96
151
  yard (~> 0.9.0)
97
152
 
98
153
  BUNDLED WITH
99
- 1.16.0
154
+ 1.16.1
data/README.md CHANGED
@@ -3,14 +3,11 @@ Mobility
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/mobility.svg)][gem]
5
5
  [![Build Status](https://travis-ci.org/shioyama/mobility.svg?branch=master)][travis]
6
- [![Dependency Status](https://gemnasium.com/shioyama/mobility.svg)][gemnasium]
7
6
  [![Code Climate](https://api.codeclimate.com/v1/badges/72200f2b00c339ec4537/maintainability.svg)][codeclimate]
8
-
9
7
  [![Gitter Chat](https://badges.gitter.im/mobility-ruby/mobility.svg)](https://gitter.im/mobility-ruby/mobility)
10
8
 
11
9
  [gem]: https://rubygems.org/gems/mobility
12
10
  [travis]: https://travis-ci.org/shioyama/mobility
13
- [gemnasium]: https://gemnasium.com/shioyama/mobility
14
11
  [codeclimate]: https://codeclimate.com/github/shioyama/mobility
15
12
  [docs]: http://www.rubydoc.info/gems/mobility
16
13
  [wiki]: https://github.com/shioyama/mobility/wiki
@@ -54,7 +51,7 @@ Installation
54
51
  Add this line to your application's Gemfile:
55
52
 
56
53
  ```ruby
57
- gem 'mobility', '~> 0.6.0'
54
+ gem 'mobility', '~> 0.7.0'
58
55
  ```
59
56
 
60
57
  Mobility is cryptographically signed. To be sure the gem you install hasn't
@@ -169,6 +166,18 @@ class Word < ApplicationRecord
169
166
  end
170
167
  ```
171
168
 
169
+ Note: When using the KeyValue backend, use the options hash to pass each attribute's type:
170
+
171
+ ```ruby
172
+ class Word < ApplicationRecord
173
+ extend Mobility
174
+ translates :name, type: :string
175
+ translates :meaning, type: :text
176
+ end
177
+ ```
178
+
179
+ This is important because this is how Mobility knows to which of the [two translation tables](https://github.com/shioyama/mobility/wiki/KeyValue-Backend) it should save your translation.
180
+
172
181
  You now have translated attributes `name` and `meaning` on the model `Word`.
173
182
  You can set their values like you would any other attribute:
174
183
 
@@ -658,13 +667,13 @@ complex implementations.
658
667
 
659
668
  ### <a name="querying"></a>Querying
660
669
 
661
- Database-backed Mobility backends also optionally support querying through
662
- `where` and other query methods (`not` and `find_by` for ActiveRecord models,
663
- `except` for Sequel models, etc). To query on these attributes, use the `i18n`
664
- class method, which will return a model relation extended with
665
- Mobility-specific query method overrides.
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.
666
675
 
667
- So assuming a model:
676
+ So for ActiveRecord, assuming a model:
668
677
 
669
678
  ```ruby
670
679
  class Post < ApplicationRecord
@@ -686,29 +695,29 @@ results in the SQL:
686
695
 
687
696
  ```sql
688
697
  SELECT "posts".* FROM "posts"
689
- INNER JOIN "mobility_string_translations" "title_mobility_string_translations"
690
- ON "title_mobility_string_translations"."key" = 'title'
691
- AND "title_mobility_string_translations"."locale" = 'en'
692
- AND "title_mobility_string_translations"."translatable_type" = 'Post'
693
- AND "title_mobility_string_translations"."translatable_id" = "posts"."id"
694
- INNER JOIN "mobility_text_translations" "content_mobility_text_translations"
695
- ON "content_mobility_text_translations"."key" = 'content'
696
- AND "content_mobility_text_translations"."locale" = 'en'
697
- AND "content_mobility_text_translations"."translatable_type" = 'Post'
698
- AND "content_mobility_text_translations"."translatable_id" = "posts"."id"
699
- WHERE "content_mobility_text_translations"."value" = 'bar'
700
- AND "title_mobility_string_translations"."value" = 'foo'
698
+ INNER JOIN "mobility_string_translations" "Post_title_en_string_translations"
699
+ ON "Post_title_en_string_translations"."key" = 'title'
700
+ AND "Post_title_en_string_translations"."locale" = 'en'
701
+ AND "Post_title_en_string_translations"."translatable_type" = 'Post'
702
+ AND "Post_title_en_string_translations"."translatable_id" = "posts"."id"
703
+ INNER JOIN "mobility_text_translations" "Post_content_en_text_translations"
704
+ ON "Post_content_en_text_translations"."key" = 'content'
705
+ AND "Post_content_en_text_translations"."locale" = 'en'
706
+ AND "Post_content_en_text_translations"."translatable_type" = 'Post'
707
+ AND "Post_content_en_text_translations"."translatable_id" = "posts"."id"
708
+ WHERE "Post_title_en_string_translations"."value" = 'foo'
709
+ AND "Post_content_en_text_translations"."value" = 'bar'
701
710
  ```
702
711
 
703
712
  As can be seen in the query above, behind the scenes Mobility joins two tables,
704
713
  one with string translations and one with text translations, and aliases the
705
- joins for each attribute so as to match the particular values passed in to the
706
- query. Details of how this is done can be found in the [Wiki page for the
707
- KeyValue
714
+ joins for each attribute so as to match the particular model, attribute(s),
715
+ locale(s) and value(s) passed in to the query. Details of how this is done can
716
+ be found in the [Wiki page for the KeyValue
708
717
  backend](https://github.com/shioyama/mobility/wiki/KeyValue-Backend#querying).
709
718
 
710
- If you would prefer to avoid the `i18n` scope everywhere, define it as a
711
- default scope on your model:
719
+ If you would prefer to avoid the `i18n` scope everywhere, you can define it as
720
+ a default scope on your model:
712
721
 
713
722
  ```ruby
714
723
  class Post < ApplicationRecord
@@ -726,6 +735,29 @@ Post.find_by(title: "Introducing Mobility")
726
735
  #=> finds post with English title "Introducing Mobility"
727
736
  ```
728
737
 
738
+ If you want more fine-grained control over your queries, you can alternatively
739
+ pass a block to the query method and call attribute names from the block scope
740
+ to build Arel predicates:
741
+
742
+ ```ruby
743
+ Post.i18n do |title, content|
744
+ title.matches("foo").and(content.matches("bar"))
745
+ end
746
+ ```
747
+
748
+ which generates the same SQL as above, except the `WHERE` clause becomes:
749
+
750
+ ```sql
751
+ SELECT "posts".* FROM "posts"
752
+ ...
753
+ WHERE "Post_title_en_string_translations"."value" ILIKE 'foo'
754
+ AND "Post_content_en_text_translations"."value" ILIKE 'bar'
755
+ ```
756
+
757
+ The block-format query format is very powerful and allows you to build complex
758
+ backend-independent queries on translated and untranslated attributes without
759
+ having to deal with the details of how these translations are stored.
760
+
729
761
  <a name="backends"></a>Backends
730
762
  --------
731
763
 
@@ -817,6 +849,10 @@ pages of the wiki and in the API documentation
817
849
  and
818
850
  [`Mobility::Backend::Hstore`](http://www.rubydoc.info/gems/mobility/Mobility/Backends/Hstore)).
819
851
 
852
+ *Note: The Json backend (`:json`) may also work with recent versions of MySQL
853
+ with JSON column support, although this backend/db combination is not tested.
854
+ See [this issue](https://github.com/shioyama/mobility/issues/226) for details.*
855
+
820
856
  Development
821
857
  -----------
822
858
 
data/lib/mobility.rb CHANGED
@@ -25,8 +25,6 @@ in backends to define gem-dependent behavior.
25
25
 
26
26
  =end
27
27
  module Mobility
28
- require "mobility/adapter"
29
- require "mobility/accumulator"
30
28
  require "mobility/attributes"
31
29
  require "mobility/backend"
32
30
  require "mobility/backends"
@@ -83,8 +81,9 @@ module Mobility
83
81
  def extended(model_class)
84
82
  return if model_class.respond_to? :mobility_accessor
85
83
 
86
- model_class.include(InstanceMethods)
87
- model_class.extend(ClassMethods)
84
+ model_class.extend Translates
85
+ #TODO: Remove in v1.0
86
+ model_class.include InstanceMethods
88
87
 
89
88
  if translates = Mobility.config.accessor_method
90
89
  model_class.singleton_class.send(:alias_method, translates, :mobility_accessor)
@@ -177,6 +176,7 @@ module Mobility
177
176
  config.public_send(:default_fallbacks, *args)
178
177
  end
179
178
 
179
+ # TODO: Make private in v1.0
180
180
  def new_fallbacks(*args)
181
181
  config.public_send(:new_fallbacks, *args)
182
182
  end
@@ -244,48 +244,33 @@ EOL
244
244
  end
245
245
  end
246
246
 
247
+ # TODO: Remove entire module in v1.0
247
248
  module InstanceMethods
248
249
  # Fetch backend for an attribute
249
- # @deprecated Use mobility.backend_for(attribute) instead.
250
+ # @deprecated Use mobility_backends[:<attribute>] instead.
250
251
  # @param [String] attribute Attribute
251
- # TODO: Remove in v1.0
252
252
  def mobility_backend_for(attribute)
253
253
  warn %{
254
254
  WARNING: mobility_backend_for is deprecated and will be removed in the next
255
- major version of Mobility. Use <post>.mobility.backend_for(attributes)
256
- instead.}
257
- mobility.backend_for(attribute)
258
- end
259
-
260
- def initialize_dup(other)
261
- @mobility_backends = nil
262
- super
255
+ version of Mobility. Use <post>.<attribute>_backend instead.}
256
+ mobility_backends[attribute.to_sym]
263
257
  end
264
258
 
265
259
  def mobility
260
+ warn %{
261
+ WARNING: <post>.mobility is deprecated and will be removed in the next
262
+ version of Mobility. To get backends, use <post>.<attribute>_backend instead.}
266
263
  @mobility ||= Adapter.new(self)
267
264
  end
268
- end
269
-
270
- module ClassMethods
271
- include Translates
272
-
273
- def mobility
274
- @mobility ||= Accumulator.new
275
- end
276
265
 
277
- def translated_attribute_names
278
- mobility.translated_attribute_names
279
- end
280
-
281
- def inherited(subclass)
282
- subclass.instance_variable_set(:@mobility, mobility.dup)
283
- super
266
+ class Adapter < Struct.new(:model)
267
+ def backend_for(attribute)
268
+ model.mobility_backends[attribute.to_sym]
269
+ end
284
270
  end
271
+ private_constant :Adapter
285
272
  end
286
- private_constant :ClassMethods, :InstanceMethods
287
273
 
288
- class BackendRequired < ArgumentError; end
289
274
  class InvalidLocale < I18n::InvalidLocale; end
290
275
  class NotImplementedError < StandardError; end
291
276
  end
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require "mobility/arel"
3
+
2
4
  module Mobility
3
5
  =begin
4
6
 
@@ -10,7 +12,6 @@ Module loading ActiveRecord-specific classes for Mobility models.
10
12
 
11
13
  def self.included(model_class)
12
14
  model_class.class_eval do
13
- extend QueryMethod.new(Mobility.query_method)
14
15
  unless const_defined?(:UniquenessValidator)
15
16
  const_set(:UniquenessValidator,
16
17
  Class.new(::Mobility::ActiveRecord::UniquenessValidator))
@@ -18,16 +19,5 @@ Module loading ActiveRecord-specific classes for Mobility models.
18
19
  delegate :translated_attribute_names, to: :class
19
20
  end
20
21
  end
21
-
22
- class QueryMethod < Module
23
- def initialize(query_method)
24
- module_eval <<-EOM, __FILE__, __LINE__ + 1
25
- def #{query_method}
26
- all
27
- end
28
- EOM
29
- end
30
- end
31
- private_constant :QueryMethod
32
22
  end
33
23
  end