mobility 0.7.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) 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 +14 -3
  5. data/Gemfile.lock +57 -0
  6. data/README.md +15 -4
  7. data/lib/mobility.rb +17 -1
  8. data/lib/mobility/active_record/uniqueness_validator.rb +1 -1
  9. data/lib/mobility/arel/nodes.rb +0 -3
  10. data/lib/mobility/arel/nodes/pg_ops.rb +0 -4
  11. data/lib/mobility/attributes.rb +42 -25
  12. data/lib/mobility/backends/active_record.rb +2 -2
  13. data/lib/mobility/backends/active_record/column.rb +2 -2
  14. data/lib/mobility/backends/active_record/key_value.rb +6 -9
  15. data/lib/mobility/backends/active_record/table.rb +6 -7
  16. data/lib/mobility/backends/column.rb +2 -2
  17. data/lib/mobility/backends/key_value.rb +5 -0
  18. data/lib/mobility/backends/sequel.rb +24 -11
  19. data/lib/mobility/backends/sequel/column.rb +4 -3
  20. data/lib/mobility/backends/sequel/container.rb +21 -12
  21. data/lib/mobility/backends/sequel/hstore.rb +11 -3
  22. data/lib/mobility/backends/sequel/json.rb +11 -3
  23. data/lib/mobility/backends/sequel/jsonb.rb +35 -3
  24. data/lib/mobility/backends/sequel/key_value.rb +97 -17
  25. data/lib/mobility/backends/sequel/serialized.rb +5 -4
  26. data/lib/mobility/backends/sequel/table.rb +95 -26
  27. data/lib/mobility/backends/table.rb +4 -0
  28. data/lib/mobility/configuration.rb +1 -1
  29. data/lib/mobility/plugins/active_record/query.rb +52 -26
  30. data/lib/mobility/plugins/locale_accessors.rb +3 -2
  31. data/lib/mobility/plugins/query.rb +3 -0
  32. data/lib/mobility/plugins/sequel/query.rb +140 -0
  33. data/lib/mobility/sequel.rb +0 -14
  34. data/lib/mobility/sequel/sql.rb +16 -0
  35. data/lib/mobility/version.rb +1 -1
  36. data/lib/rails/generators/mobility/templates/column_translations.rb +1 -1
  37. data/lib/rails/generators/mobility/templates/initializer.rb +3 -2
  38. data/lib/rails/generators/mobility/translations_generator.rb +1 -1
  39. metadata +27 -46
  40. metadata.gz.sig +1 -1
  41. data/lib/mobility/backends/active_record/query_methods.rb +0 -50
  42. data/lib/mobility/backends/sequel/column/query_methods.rb +0 -29
  43. data/lib/mobility/backends/sequel/container/json_query_methods.rb +0 -41
  44. data/lib/mobility/backends/sequel/container/jsonb_query_methods.rb +0 -41
  45. data/lib/mobility/backends/sequel/hstore/query_methods.rb +0 -34
  46. data/lib/mobility/backends/sequel/json/query_methods.rb +0 -34
  47. data/lib/mobility/backends/sequel/jsonb/query_methods.rb +0 -34
  48. data/lib/mobility/backends/sequel/key_value/query_methods.rb +0 -58
  49. data/lib/mobility/backends/sequel/pg_query_methods.rb +0 -114
  50. data/lib/mobility/backends/sequel/query_methods.rb +0 -36
  51. data/lib/mobility/backends/sequel/serialized/query_methods.rb +0 -22
  52. data/lib/mobility/backends/sequel/table/query_methods.rb +0 -58
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d41db6e7a795ddcef9e26a6707ead0b0e292e18a4555851f0c190e9572895f53
4
- data.tar.gz: dd1e77bbb86a8bb7f5a5740fdf5b2c3a5096c0474e651691a9c80d5fb3b000d0
3
+ metadata.gz: 93685e1d8296d7f0f9c2a74e07a40af397fa1eef52d2d8c51d63ac6ed7a33812
4
+ data.tar.gz: be5beb1769d824f8687b0d2e5b796738ffa98dd35e6018de126ce909e089c278
5
5
  SHA512:
6
- metadata.gz: adc549d6843493f3f711ffa892b2fde61de54077510a6b12a488c25196e8993c2d7b49d16cf851b2deaef551388ed9830db1a8099ba707aba5a5facd868bd4b0
7
- data.tar.gz: 6c80e9f23841f09559a4f047dac424a9a0d3f94c918fce9f4ceda80b48391b6774022d9a1936ff67f65cc4942824466ab92632fe18fddcb3ae71a150599d5c48
6
+ metadata.gz: 0dfa4ca2101b75d34a62d8a445bb58cf84a75d39346568bd816d064bdfc637fb11e8e79cf963789d18cde779ce588fff596d264b728f68cf53c382ad57a5ccb9
7
+ data.tar.gz: 3b907f55dffe8823d12f2b04bb57fea611cea6ac316f4572859c484e8692a89179d1114c8966ad801007d6833615943abf9c7ff89be5c924f9b9b719cdc25894
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,6 +1,16 @@
1
1
  # Mobility Changelog
2
2
 
3
- ## 0.7
3
+ ## 0.8
4
+
5
+ ### 0.8.0 (September 11, 2018)
6
+ * Support order clause on translated queries (ActiveRecord)
7
+ ([#261](https://github.com/shioyama/mobility/pull/261))
8
+ * Restructure Sequel querying into plugin
9
+ ([#255](https://github.com/shioyama/mobility/pull/255),
10
+ [#267](https://github.com/shioyama/mobility/pull/267),
11
+ [#268](https://github.com/shioyama/mobility/pull/267))
12
+ * Default locale to Mobility.locale in apply_scope
13
+ ([#263](https://github.com/shioyama/mobility/pull/263))
4
14
 
5
15
  ### 0.7.6 (July 6, 2018)
6
16
  * Sequel pg_hash require hash_initializer
@@ -33,7 +43,7 @@
33
43
  * Restructure querying into plugin (ActiveRecord only)
34
44
  ([#216](https://github.com/shioyama/mobility/pull/216),
35
45
  [#225](https://github.com/shioyama/mobility/pull/225),
36
- [#222](https://github.com/shioyama/mobility/pull/222),
46
+ [#222](https://github.com/shioyama/mobility/pull/222))
37
47
  * Support querying on multiple locales at once
38
48
  ([#232](https://github.com/shioyama/mobility/pull/232))
39
49
  * Allow passing locale to query methods
@@ -49,7 +59,8 @@
49
59
  ([#241](https://github.com/shioyama/mobility/pull/241))
50
60
  * Define options on subclassed backend class
51
61
  ([#218](https://github.com/shioyama/mobility/pull/218))
52
- * Add column_affix
62
+ * Add column_affix when configuring options
63
+ ([#217](https://github.com/shioyama/mobility/pull/217))
53
64
  * Use module_eval to define locale_accessors
54
65
  ([#219](https://github.com/shioyama/mobility/pull/219))
55
66
  * Improve performance of getters/setters
@@ -8,14 +8,45 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ actionpack (5.2.1)
12
+ actionview (= 5.2.1)
13
+ activesupport (= 5.2.1)
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.1)
19
+ activesupport (= 5.2.1)
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.1)
25
+ activesupport (= 5.2.1)
26
+ activerecord (5.2.1)
27
+ activemodel (= 5.2.1)
28
+ activesupport (= 5.2.1)
29
+ arel (>= 9.0)
30
+ activesupport (5.2.1)
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)
37
+ builder (3.2.3)
12
38
  byebug (10.0.2)
13
39
  coderay (1.1.2)
14
40
  concurrent-ruby (1.0.5)
41
+ crass (1.0.4)
15
42
  database_cleaner (1.7.0)
16
43
  diff-lcs (1.3)
44
+ erubi (1.7.1)
17
45
  ffi (1.9.24)
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)
@@ -36,10 +67,17 @@ GEM
36
67
  rb-fsevent (~> 0.9, >= 0.9.4)
37
68
  rb-inotify (~> 0.9, >= 0.9.7)
38
69
  ruby_dep (~> 1.2)
70
+ loofah (2.2.2)
71
+ crass (~> 1.0.2)
72
+ nokogiri (>= 1.5.9)
39
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.4)
80
+ mini_portile2 (~> 2.3.0)
43
81
  notiffany (0.1.1)
44
82
  nenv (~> 0.1)
45
83
  shellany (~> 0.0)
@@ -51,6 +89,19 @@ GEM
51
89
  byebug (~> 10.0)
52
90
  pry (~> 0.10)
53
91
  rack (2.0.5)
92
+ rack-test (1.1.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.1)
100
+ actionpack (= 5.2.1)
101
+ activesupport (= 5.2.1)
102
+ method_source
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.19.0, < 2.0)
54
105
  rake (12.3.1)
55
106
  rb-fsevent (0.10.3)
56
107
  rb-inotify (0.9.10)
@@ -74,19 +125,25 @@ GEM
74
125
  shellany (0.0.1)
75
126
  sqlite3 (1.3.13)
76
127
  thor (0.20.0)
128
+ thread_safe (0.3.6)
129
+ tzinfo (1.2.5)
130
+ thread_safe (~> 0.1)
77
131
  yard (0.9.14)
78
132
 
79
133
  PLATFORMS
80
134
  ruby
81
135
 
82
136
  DEPENDENCIES
137
+ activerecord (>= 5.2.0.rc2, < 5.3)
83
138
  benchmark-ips
84
139
  database_cleaner (~> 1.5, >= 1.5.3)
140
+ generator_spec (~> 0.9.4)
85
141
  guard-rspec
86
142
  mobility!
87
143
  mysql2 (~> 0.4.9)
88
144
  pg (< 1.0)
89
145
  pry-byebug
146
+ railties (>= 5.2.0.rc2, < 5.3)
90
147
  rake (~> 12, >= 12.2.1)
91
148
  rspec (~> 3.0)
92
149
  sqlite3
data/README.md CHANGED
@@ -51,7 +51,7 @@ Installation
51
51
  Add this line to your application's Gemfile:
52
52
 
53
53
  ```ruby
54
- gem 'mobility', '~> 0.7.6'
54
+ gem 'mobility', '~> 0.8.0'
55
55
  ```
56
56
 
57
57
  Mobility is cryptographically signed. To be sure the gem you install hasn't
@@ -673,7 +673,7 @@ different ways. The first is via query methods like `where` (and `not` and
673
673
  `i18n` class method, which will return a model relation or dataset extended
674
674
  with Mobility-specific query method overrides.
675
675
 
676
- So for ActiveRecord, assuming a model:
676
+ So for ActiveRecord, assuming a model using KeyValue as its default backend:
677
677
 
678
678
  ```ruby
679
679
  class Post < ApplicationRecord
@@ -740,7 +740,7 @@ pass a block to the query method and call attribute names from the block scope
740
740
  to build Arel predicates:
741
741
 
742
742
  ```ruby
743
- Post.i18n do |title, content|
743
+ Post.i18n do
744
744
  title.matches("foo").and(content.matches("bar"))
745
745
  end
746
746
  ```
@@ -756,7 +756,8 @@ WHERE "Post_title_en_string_translations"."value" ILIKE 'foo'
756
756
 
757
757
  The block-format query format is very powerful and allows you to build complex
758
758
  backend-independent queries on translated and untranslated attributes without
759
- having to deal with the details of how these translations are stored.
759
+ having to deal with the details of how these translations are stored. The same
760
+ interface is supported with Sequel to build datasets.
760
761
 
761
762
  <a name="backends"></a>Backends
762
763
  --------
@@ -930,6 +931,16 @@ Integrations
930
931
  * [friendly_id-mobility](https://github.com/shioyama/friendly_id-mobility): Use
931
932
  Mobility with [FriendlyId](https://github.com/norman/friendly_id).
932
933
 
934
+ Tutorials
935
+ ---------
936
+
937
+ - [Polyglot content in a rails
938
+ app](https://revs.runtime-revolution.com/polyglot-content-in-a-rails-app-aed823854955)
939
+ - [Translating with
940
+ Mobility](https://dejimata.com/2017/3/3/translating-with-mobility)
941
+ - [JSONify your Ruby
942
+ Translations](https://dejimata.com/2018/3/20/jsonify-your-ruby-translations)
943
+
933
944
  More Information
934
945
  ----------------
935
946
 
@@ -117,7 +117,7 @@ module Mobility
117
117
  # Sets Mobility locale
118
118
  # @param [Symbol] locale Locale to set
119
119
  # @raise [InvalidLocale] if locale is nil or not in
120
- # +I18n.available_locales+ (if +I18n.enforce_available_locales+ is +true+)
120
+ # +Mobility.available_locales+ (if +I18n.enforce_available_locales+ is +true+)
121
121
  # @return [Symbol] Locale
122
122
  def locale=(locale)
123
123
  set_locale(locale)
@@ -239,6 +239,22 @@ EOL
239
239
  end
240
240
  end
241
241
 
242
+ # Returns available locales. Defaults to I18n.available_locales, but will
243
+ # use Rails.application.config.i18n.available_locales if Rails is loaded
244
+ # and config is non-nil.
245
+ # @return [Array<Symbol>] Available locales
246
+ # @note The special case for Rails is necessary due to the fact that Rails
247
+ # may load the model before setting +I18n.available_locales+. If we
248
+ # simply default to +I18n.available_locales+, we may define many more
249
+ # methods (in LocaleAccessors) than is really necessary.
250
+ def available_locales
251
+ if Loaded::Rails && Rails.application
252
+ Rails.application.config.i18n.available_locales || I18n.available_locales
253
+ else
254
+ I18n.available_locales
255
+ end
256
+ end
257
+
242
258
  protected
243
259
 
244
260
  def read_locale
@@ -27,7 +27,7 @@ To use the validator, you must +extend Mobility+ before calling +validates+
27
27
 
28
28
  if (([*options[:scope]] + [attribute]).map(&:to_s) & klass.mobility_attributes).present?
29
29
  return unless value.present?
30
- relation = klass.__mobility_query_scope__ do |m|
30
+ relation = klass.unscoped.__mobility_query_scope__ do |m|
31
31
  node = m.__send__(attribute)
32
32
  options[:case_sensitive] == false ? node.lower.eq(value.downcase) : node.eq(value)
33
33
  end
@@ -2,13 +2,10 @@
2
2
  module Mobility
3
3
  module Arel
4
4
  module Nodes
5
- class Unary < ::Arel::Nodes::Unary; end
6
5
  class Binary < ::Arel::Nodes::Binary; end
7
6
  class Grouping < ::Arel::Nodes::Grouping; end
8
- class Equality < ::Arel::Nodes::Equality; end
9
7
 
10
8
  ::Arel::Visitors::ToSql.class_eval do
11
- alias :visit_Mobility_Arel_Nodes_Equality :visit_Arel_Nodes_Equality
12
9
  alias :visit_Mobility_Arel_Nodes_Grouping :visit_Arel_Nodes_Grouping
13
10
  end
14
11
  end
@@ -19,10 +19,6 @@ module Mobility
19
19
  include ::Arel::OrderPredications
20
20
  include ::Arel::AliasPredication
21
21
 
22
- def eq other
23
- Equality.new self, quoted_node(other)
24
- end
25
-
26
22
  def lower
27
23
  super self
28
24
  end
@@ -20,53 +20,61 @@ like including a module. Creating an instance like this:
20
20
 
21
21
  Attributes.new("title", backend: :my_backend, locale_accessors: [:en, :ja], cache: true, fallbacks: true)
22
22
 
23
- will generate an anonymous module that behaves (approximately) like this:
23
+ will generate an anonymous module that behaves approximately like this:
24
24
 
25
25
  Module.new do
26
- def title_backend
27
- # Create a subclass of Mobility::Backends::MyBackend and include in it:
26
+ def mobility_backends
27
+ # Returns a memoized hash with attribute name keys and backend instance
28
+ # values. When a key is fetched from the hash, the hash calls
29
+ # +self.class.mobility_backend_class(name)+ (where +name+ is the
30
+ # attribute name) to get the backend class, then instantiate it (passing
31
+ # the model instance and attribute name to its initializer) and return it.
32
+ #
33
+ # The backend class returned from the class method
34
+ # +mobility_backend_class+ returns a subclass of
35
+ # +Mobility::Backends::MyBackend+ and includes into it:
36
+ #
28
37
  # - Mobility::Plugins::Cache (from the +cache: true+ option)
29
- # - Mobility::Plugins::Fallbacks (from the +fallbacks: true+ option)
38
+ # - instance of Mobility::Plugins::Fallbacks (from the +fallbacks: true+ option)
30
39
  # - Mobility::Plugins::Presence (by default, disabled by +presence: false+)
31
- # Then instantiate the backend, memoize it, and return it.
32
40
  end
33
41
 
34
- def title(**options)
35
- title_backend.read(Mobility.locale, **options).presence
42
+ def title(locale: Mobility.locale)
43
+ mobility_backends[:title].read(locale)
36
44
  end
37
45
 
38
- def title?(**options)
39
- title_backend.read(Mobility.locale, **options).present?
46
+ def title?(locale: Mobility.locale)
47
+ mobility_backends[:title].read(locale).present?
40
48
  end
41
49
 
42
- def title=(value)
43
- title_backend.write(Mobility.locale, value.presence)
50
+ def title=(value, locale: Mobility.locale)
51
+ mobility_backends[:title].write(locale, value)
44
52
  end
45
53
 
46
54
  # Start Locale Accessors
47
55
  #
48
- def title_en(**options)
49
- title_backend.read(:en, **options).presence
56
+ def title_en
57
+ title(locale: :en)
50
58
  end
51
59
 
52
- def title_en?(**options)
53
- title_backend.read(:en, **options).present?
60
+ def title_en?
61
+ title?(locale: :en)
54
62
  end
55
63
 
56
64
  def title_en=(value)
57
- title_backend.write(:en, value.presence)
65
+ public_send(:title=, value, locale: :en)
58
66
  end
59
67
 
60
- def title_ja(**options)
61
- title_backend.read(:ja, **options).presence
68
+ def title_ja
69
+ title(locale: :ja)
62
70
  end
63
71
 
64
- def title_ja?(**options)
65
- title_backend.read(:ja, **options).present?
72
+ def title_ja?
73
+ title?(locale: :ja)
66
74
  end
67
75
 
68
76
  def title_ja=(value)
69
- title_backend.write(:ja, value.presence)
77
+ public_send(:title=, value, locale: :ja)
70
78
  end
71
79
  # End Locale Accessors
72
80
  end
@@ -75,6 +83,10 @@ Including this module into a model class will thus add the backend method, the
75
83
  reader, writer and presence methods, and the locale accessor so the model
76
84
  class. (These methods are in fact added to the model in an +included+ hook.)
77
85
 
86
+ Note that some simplifications have been made above for readability. (In
87
+ reality, all getters and setters accept an options hash which is passed along
88
+ to the backend instance.)
89
+
78
90
  ==Setting up the Model Class
79
91
 
80
92
  Accessor methods alone are of limited use without a hook to actually modify the
@@ -88,9 +100,6 @@ This allows a backend to do things like (for example) define associations on a
88
100
  model class required by the backend, as happens in the {Backends::KeyValue} and
89
101
  {Backends::Table} backends.
90
102
 
91
- The +setup+ block is also used to extend the query scope/dataset (+i18n+ by
92
- default) with backend-specific query method support.
93
-
94
103
  Since setup blocks are evaluated on the model class, it is possible that
95
104
  backends can conflict (for example, overwriting previously defined methods).
96
105
  Care should be taken to avoid defining methods on the model class, or where
@@ -244,6 +253,7 @@ EOL
244
253
  module InstanceMethods
245
254
  # Return a new backend for an attribute name.
246
255
  # @return [Hash] Hash of attribute names and backend instances
256
+ # @api private
247
257
  def mobility_backends
248
258
  @mobility_backends ||= Hash.new do |hash, name|
249
259
  next hash[name.to_sym] if String === name
@@ -262,7 +272,7 @@ EOL
262
272
  # of this model.
263
273
  # @return [Array<Mobility::Attributes>] Attribute modules
264
274
  def mobility_modules
265
- ancestors.select { |mod| Attributes === mod }
275
+ ancestors.grep(Attributes)
266
276
  end
267
277
 
268
278
  # Return translated attribute names on this model.
@@ -271,6 +281,13 @@ EOL
271
281
  mobility_modules.map(&:names).flatten.uniq
272
282
  end
273
283
 
284
+ # Return true if attribute name is translated on this model.
285
+ # @param [String, Symbol] Attribute name
286
+ # @return [Boolean]
287
+ def mobility_attribute?(name)
288
+ mobility_attributes.include?(name.to_s)
289
+ end
290
+
274
291
  # @!method translated_attribute_names
275
292
  # @return (see #mobility_attributes)
276
293
  alias translated_attribute_names mobility_attributes
@@ -22,10 +22,10 @@ module Mobility
22
22
 
23
23
  # @param [ActiveRecord::Relation] relation Relation to scope
24
24
  # @param [Object] predicate Arel predicate
25
- # @param [Symbol] locale Locale
25
+ # @param [Symbol] locale (Mobility.locale) Locale
26
26
  # @option [Boolean] invert
27
27
  # @return [ActiveRecord::Relation] Relation with scope added
28
- def apply_scope(relation, _predicate, _locale, invert: false)
28
+ def apply_scope(relation, _predicate, _locale = Mobility.locale, invert: false)
29
29
  relation
30
30
  end
31
31
 
@@ -14,8 +14,8 @@ translatable columns to the model table with:
14
14
  rails generate mobility:translations post title:string
15
15
 
16
16
  The generated migration will add columns +title_<locale>+ for every locale in
17
- +I18n.available_locales+. (The generator can be run again to add new attributes
18
- or locales.)
17
+ +Mobility.available_locales+ (i.e. +I18n.available_locales+). (The generator
18
+ can be run again to add new attributes or locales.)
19
19
 
20
20
  @example
21
21
  class Post < ActiveRecord::Base
@@ -29,8 +29,6 @@ Implements the {Mobility::Backends::KeyValue} backend for ActiveRecord models.
29
29
  include ActiveRecord
30
30
  include KeyValue
31
31
 
32
- option_reader :table_alias_affix
33
-
34
32
  class << self
35
33
  # @!group Backend Configuration
36
34
  # @option (see Mobility::Backends::KeyValue::ClassMethods#configure)
@@ -59,10 +57,10 @@ Implements the {Mobility::Backends::KeyValue} backend for ActiveRecord models.
59
57
  # Joins translations using either INNER/OUTER join appropriate to the query.
60
58
  # @param [ActiveRecord::Relation] relation Relation to scope
61
59
  # @param [Object] predicate Arel predicate
62
- # @param [Symbol] locale Locale
60
+ # @param [Symbol] locale (Mobility.locale) Locale
63
61
  # @option [Boolean] invert
64
62
  # @return [ActiveRecord::Relation] relation Relation with joins applied (if needed)
65
- def apply_scope(relation, predicate, locale, invert: false)
63
+ def apply_scope(relation, predicate, locale = Mobility.locale, invert: false)
66
64
  visitor = Visitor.new(self, locale)
67
65
  visitor.accept(predicate).inject(relation) do |rel, (attr, join_type)|
68
66
  join_type &&= ::Arel::Nodes::InnerJoin if invert
@@ -72,10 +70,6 @@ Implements the {Mobility::Backends::KeyValue} backend for ActiveRecord models.
72
70
 
73
71
  private
74
72
 
75
- def table_alias(attr, locale)
76
- table_alias_affix % "#{attr}_#{Mobility.normalize_locale(locale)}"
77
- end
78
-
79
73
  def join_translations(relation, key, locale, join_type)
80
74
  return relation if already_joined?(relation, key, locale, join_type)
81
75
  m = model_class.arel_table
@@ -114,7 +108,10 @@ Implements the {Mobility::Backends::KeyValue} backend for ActiveRecord models.
114
108
  # end
115
109
  #
116
110
  # backend_class = Post.mobility_backend_class(:title)
117
- # visitor = Mobility::Backends::ActiveRecord::KeyValue::Visitor.new(backend_class)
111
+ # visitor = Mobility::Backends::ActiveRecord::KeyValue::Visitor.new(backend_class, :en)
112
+ #
113
+ # title = backend_class.build_node("title", :en) # arel node for title
114
+ # content = backend_class.build_node("content", :en) # arel node for content
118
115
  #
119
116
  # visitor.accept(title.eq("foo").and(content.eq(nil)))
120
117
  # #=> { title: Arel::Nodes::InnerJoin, content: Arel::Nodes::OuterJoin }