mobility 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -2
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +41 -1
- data/Gemfile.lock +3 -58
- data/README.md +22 -21
- data/lib/mobility.rb +3 -2
- data/lib/mobility/accumulator.rb +1 -2
- data/lib/mobility/active_model/backend_resetter.rb +1 -1
- data/lib/mobility/active_record.rb +12 -9
- data/lib/mobility/active_record/backend_resetter.rb +6 -7
- data/lib/mobility/active_record/uniqueness_validator.rb +12 -2
- data/lib/mobility/adapter.rb +1 -0
- data/lib/mobility/attributes.rb +3 -13
- data/lib/mobility/backends/active_record/column.rb +1 -0
- data/lib/mobility/backends/active_record/column/query_methods.rb +25 -20
- data/lib/mobility/backends/active_record/container/json_query_methods.rb +22 -16
- data/lib/mobility/backends/active_record/container/jsonb_query_methods.rb +19 -19
- data/lib/mobility/backends/active_record/hstore.rb +14 -12
- data/lib/mobility/backends/active_record/hstore/query_methods.rb +14 -5
- data/lib/mobility/backends/active_record/json.rb +21 -19
- data/lib/mobility/backends/active_record/json/query_methods.rb +16 -11
- data/lib/mobility/backends/active_record/jsonb.rb +21 -19
- data/lib/mobility/backends/active_record/jsonb/query_methods.rb +14 -5
- data/lib/mobility/backends/active_record/key_value.rb +9 -9
- data/lib/mobility/backends/active_record/key_value/query_methods.rb +53 -46
- data/lib/mobility/backends/active_record/pg_hash.rb +29 -25
- data/lib/mobility/backends/active_record/pg_query_methods.rb +76 -40
- data/lib/mobility/backends/active_record/query_methods.rb +17 -10
- data/lib/mobility/backends/active_record/serialized.rb +4 -2
- data/lib/mobility/backends/active_record/serialized/query_methods.rb +18 -15
- data/lib/mobility/backends/active_record/table.rb +21 -12
- data/lib/mobility/backends/active_record/table/query_methods.rb +82 -83
- data/lib/mobility/backends/hash_valued.rb +19 -0
- data/lib/mobility/backends/hstore.rb +3 -1
- data/lib/mobility/backends/json.rb +3 -1
- data/lib/mobility/backends/jsonb.rb +3 -1
- data/lib/mobility/backends/key_value.rb +32 -15
- data/lib/mobility/backends/sequel/column/query_methods.rb +16 -12
- data/lib/mobility/backends/sequel/container/json_query_methods.rb +25 -18
- data/lib/mobility/backends/sequel/container/jsonb_query_methods.rb +25 -18
- data/lib/mobility/backends/sequel/hstore.rb +14 -12
- data/lib/mobility/backends/sequel/hstore/query_methods.rb +18 -11
- data/lib/mobility/backends/sequel/json.rb +21 -19
- data/lib/mobility/backends/sequel/json/query_methods.rb +18 -11
- data/lib/mobility/backends/sequel/jsonb.rb +21 -19
- data/lib/mobility/backends/sequel/jsonb/query_methods.rb +18 -11
- data/lib/mobility/backends/sequel/key_value.rb +10 -11
- data/lib/mobility/backends/sequel/key_value/query_methods.rb +39 -34
- data/lib/mobility/backends/sequel/pg_hash.rb +37 -25
- data/lib/mobility/backends/sequel/pg_query_methods.rb +45 -20
- data/lib/mobility/backends/sequel/query_methods.rb +5 -0
- data/lib/mobility/backends/sequel/serialized.rb +18 -13
- data/lib/mobility/backends/sequel/serialized/query_methods.rb +10 -7
- data/lib/mobility/backends/sequel/table.rb +1 -1
- data/lib/mobility/backends/sequel/table/query_methods.rb +40 -35
- data/lib/mobility/plugins/cache/translation_cacher.rb +15 -15
- data/lib/mobility/plugins/default.rb +0 -7
- data/lib/mobility/plugins/fallbacks.rb +4 -0
- data/lib/mobility/sequel.rb +11 -5
- data/lib/mobility/sequel/backend_resetter.rb +6 -7
- data/lib/mobility/sequel/column_changes.rb +4 -4
- data/lib/mobility/version.rb +1 -1
- data/lib/rails/generators/mobility/backend_generators/base.rb +4 -0
- data/lib/rails/generators/mobility/backend_generators/table_backend.rb +0 -12
- data/lib/rails/generators/mobility/templates/column_translations.rb +2 -2
- data/lib/rails/generators/mobility/templates/create_string_translations.rb +5 -5
- data/lib/rails/generators/mobility/templates/create_text_translations.rb +5 -5
- data/lib/rails/generators/mobility/templates/initializer.rb +8 -0
- data/lib/rails/generators/mobility/templates/table_migration.rb +2 -3
- data/lib/rails/generators/mobility/templates/table_translations.rb +3 -4
- data/lib/rails/generators/mobility/translations_generator.rb +6 -5
- metadata +2 -3
- metadata.gz.sig +0 -0
- data/lib/mobility/backend/stringify_locale.rb +0 -18
data/lib/mobility/adapter.rb
CHANGED
data/lib/mobility/attributes.rb
CHANGED
@@ -153,7 +153,7 @@ with other backends.
|
|
153
153
|
plugin.apply(self, options[name])
|
154
154
|
end
|
155
155
|
|
156
|
-
|
156
|
+
each do |name|
|
157
157
|
define_backend(name)
|
158
158
|
define_reader(name) if %i[accessor reader].include?(method)
|
159
159
|
define_writer(name) if %i[accessor writer].include?(method)
|
@@ -169,18 +169,8 @@ with other backends.
|
|
169
169
|
names.each(&block)
|
170
170
|
end
|
171
171
|
|
172
|
-
|
173
|
-
|
174
|
-
# @deprecated This method was mainly used internally but is no longer
|
175
|
-
# needed. It will be removed in the next major release.
|
176
|
-
# @param [Hash] options Options hash passed to accessor method
|
177
|
-
# @return [Symbol] locale
|
178
|
-
# TODO: Remove in v1.0
|
179
|
-
def self.process_options!(options)
|
180
|
-
(options[:locale] || Mobility.locale).tap { |locale|
|
181
|
-
Mobility.enforce_available_locales!(locale)
|
182
|
-
options[:locale] &&= !!locale
|
183
|
-
}.to_sym
|
172
|
+
def inspect
|
173
|
+
"#<Attributes (#{backend_name}) @names=#{names.join(", ")}>"
|
184
174
|
end
|
185
175
|
|
186
176
|
private
|
@@ -3,35 +3,40 @@ require "mobility/backends/active_record/query_methods"
|
|
3
3
|
|
4
4
|
module Mobility
|
5
5
|
module Backends
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module ActiveRecord
|
7
|
+
class Column::QueryMethods < QueryMethods
|
8
|
+
def initialize(attributes, _)
|
9
|
+
super
|
10
|
+
q = self
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
define_method :where! do |opts, *rest|
|
13
|
+
super(q.convert_opts(opts), *rest)
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def extended(relation)
|
18
|
+
super
|
19
|
+
q = self
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
mod = Module.new do
|
22
|
+
define_method :not do |opts, *rest|
|
23
|
+
super(q.convert_opts(opts), *rest)
|
24
|
+
end
|
23
25
|
end
|
26
|
+
relation.mobility_where_chain.include(mod)
|
24
27
|
end
|
25
|
-
relation.mobility_where_chain.include(mod)
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def convert_opts(opts)
|
30
|
+
if i18n_keys = extract_attributes(opts)
|
31
|
+
opts = opts.with_indifferent_access
|
32
|
+
i18n_keys.each do |attr|
|
33
|
+
opts[Backends::Column.column_name_for(attr)] = collapse opts.delete(attr)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
opts
|
32
37
|
end
|
33
|
-
opts
|
34
38
|
end
|
39
|
+
Column.private_constant :QueryMethods
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
@@ -4,27 +4,33 @@ require "mobility/backends/active_record/query_methods"
|
|
4
4
|
|
5
5
|
module Mobility
|
6
6
|
module Backends
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
module ActiveRecord
|
8
|
+
class Container::JsonQueryMethods < QueryMethods
|
9
|
+
include PgQueryMethods
|
10
|
+
attr_reader :column_name, :column
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
def initialize(_attributes, options)
|
13
|
+
super
|
14
|
+
@column = arel_table[options[:column_name]]
|
15
|
+
end
|
16
16
|
|
17
|
-
|
17
|
+
def matches(key, locale)
|
18
|
+
build_infix(:'->>', build_infix(:'->', column, build_quoted(locale)), build_quoted(key))
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def exists(key, locale)
|
22
|
+
matches(key, locale).eq(nil).not
|
23
|
+
end
|
24
|
+
|
25
|
+
def absent(key, locale)
|
26
|
+
matches(key, locale).eq(nil)
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
29
|
+
def quote(value)
|
30
|
+
value.to_s
|
31
|
+
end
|
27
32
|
end
|
33
|
+
Container.private_constant :JsonQueryMethods
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
@@ -4,30 +4,30 @@ require "mobility/backends/active_record/query_methods"
|
|
4
4
|
|
5
5
|
module Mobility
|
6
6
|
module Backends
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
module ActiveRecord
|
8
|
+
class Container::JsonbQueryMethods < QueryMethods
|
9
|
+
include PgQueryMethods
|
10
|
+
attr_reader :column
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
def initialize(_attributes, options)
|
13
|
+
super
|
14
|
+
@column = arel_table[options[:column_name]]
|
15
|
+
end
|
16
16
|
|
17
|
-
|
17
|
+
def matches(key, locale)
|
18
|
+
build_infix(:'->', build_infix(:'->', column, build_quoted(locale)), build_quoted(key))
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
21
|
+
def exists(key, locale)
|
22
|
+
build_infix(:'?', column, build_quoted(locale)).and(
|
23
|
+
build_infix(:'?', build_infix(:'->', column, build_quoted(locale)), build_quoted(key)))
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
build_infix(:'->', column, quote(locale)),
|
29
|
-
quote(key)))
|
26
|
+
def quote(value)
|
27
|
+
build_quoted(value.to_json)
|
28
|
+
end
|
30
29
|
end
|
30
|
+
Container.private_constant :JsonbQueryMethods
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -9,21 +9,23 @@ Implements the {Mobility::Backends::Hstore} backend for ActiveRecord models.
|
|
9
9
|
@see Mobility::Backends::ActiveRecord::HashValued
|
10
10
|
|
11
11
|
=end
|
12
|
-
|
13
|
-
|
12
|
+
module ActiveRecord
|
13
|
+
class Hstore < PgHash
|
14
|
+
require 'mobility/backends/active_record/hstore/query_methods'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
# @!group Backend Accessors
|
17
|
+
# @!macro backend_reader
|
18
|
+
# @!method read(locale, **options)
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
# @!group Backend Accessors
|
21
|
+
# @!macro backend_writer
|
22
|
+
def write(locale, value, options = {})
|
23
|
+
super(locale, value && value.to_s, options)
|
24
|
+
end
|
25
|
+
# @!endgroup
|
25
26
|
|
26
|
-
|
27
|
+
setup_query_methods(QueryMethods)
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -3,14 +3,23 @@ require 'mobility/backends/active_record/query_methods'
|
|
3
3
|
|
4
4
|
module Mobility
|
5
5
|
module Backends
|
6
|
-
|
7
|
-
|
6
|
+
module ActiveRecord
|
7
|
+
class Hstore::QueryMethods < QueryMethods
|
8
|
+
include PgQueryMethods
|
8
9
|
|
9
|
-
|
10
|
+
def matches(key, locale)
|
11
|
+
build_infix(:'->', arel_table[column_name(key)], build_quoted(locale))
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
def exists(key, locale)
|
15
|
+
build_infix(:'?', arel_table[column_name(key)], build_quoted(locale))
|
16
|
+
end
|
17
|
+
|
18
|
+
def quote(value)
|
19
|
+
build_quoted(value)
|
20
|
+
end
|
13
21
|
end
|
22
|
+
Hstore.private_constant :QueryMethods
|
14
23
|
end
|
15
24
|
end
|
16
25
|
end
|
@@ -9,28 +9,30 @@ Implements the {Mobility::Backends::Json} backend for ActiveRecord models.
|
|
9
9
|
@see Mobility::Backends::ActiveRecord::HashValued
|
10
10
|
|
11
11
|
=end
|
12
|
-
|
13
|
-
|
12
|
+
module ActiveRecord
|
13
|
+
class Json < PgHash
|
14
|
+
require 'mobility/backends/active_record/json/query_methods'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# @!group Backend Accessors
|
17
|
+
#
|
18
|
+
# @note Translation may be string, integer or boolean-valued since
|
19
|
+
# value is stored on a JSON hash.
|
20
|
+
# @param [Symbol] locale Locale to read
|
21
|
+
# @param [Hash] options
|
22
|
+
# @return [String,Integer,Boolean] Value of translation
|
23
|
+
# @!method read(locale, **options)
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
# @!group Backend Accessors
|
26
|
+
# @note Translation may be string, integer or boolean-valued since
|
27
|
+
# value is stored on a JSON hash.
|
28
|
+
# @param [Symbol] locale Locale to write
|
29
|
+
# @param [String,Integer,Boolean] value Value to write
|
30
|
+
# @param [Hash] options
|
31
|
+
# @return [String,Integer,Boolean] Updated value
|
32
|
+
# @!method write(locale, value, **options)
|
32
33
|
|
33
|
-
|
34
|
+
setup_query_methods(QueryMethods)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -4,22 +4,27 @@ require "mobility/backends/active_record/query_methods"
|
|
4
4
|
|
5
5
|
module Mobility
|
6
6
|
module Backends
|
7
|
-
|
8
|
-
|
7
|
+
module ActiveRecord
|
8
|
+
class Json::QueryMethods < QueryMethods
|
9
|
+
include PgQueryMethods
|
9
10
|
|
10
|
-
|
11
|
+
def matches(key, locale)
|
12
|
+
build_infix(:'->>', arel_table[column_name(key)], build_quoted(locale))
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
def exists(key, locale)
|
16
|
+
absent(key, locale).not
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
def absent(key, locale)
|
20
|
+
matches(key, locale).eq(nil)
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
def quote(value)
|
24
|
+
value.to_s
|
25
|
+
end
|
22
26
|
end
|
27
|
+
Json.private_constant :QueryMethods
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
@@ -9,28 +9,30 @@ Implements the {Mobility::Backends::Jsonb} backend for ActiveRecord models.
|
|
9
9
|
@see Mobility::Backends::ActiveRecord::HashValued
|
10
10
|
|
11
11
|
=end
|
12
|
-
|
13
|
-
|
12
|
+
module ActiveRecord
|
13
|
+
class Jsonb < PgHash
|
14
|
+
require 'mobility/backends/active_record/jsonb/query_methods'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# @!group Backend Accessors
|
17
|
+
#
|
18
|
+
# @note Translation may be any json type, but querying will only work on
|
19
|
+
# string-typed values.
|
20
|
+
# @param [Symbol] locale Locale to read
|
21
|
+
# @param [Hash] options
|
22
|
+
# @return [String,Integer,Boolean] Value of translation
|
23
|
+
# @!method read(locale, **options)
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
# @!group Backend Accessors
|
26
|
+
# @note Translation may be any json type, but querying will only work on
|
27
|
+
# string-typed values.
|
28
|
+
# @param [Symbol] locale Locale to write
|
29
|
+
# @param [String,Integer,Boolean] value Value to write
|
30
|
+
# @param [Hash] options
|
31
|
+
# @return [String,Integer,Boolean] Updated value
|
32
|
+
# @!method write(locale, value, **options)
|
32
33
|
|
33
|
-
|
34
|
+
setup_query_methods(QueryMethods)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -4,14 +4,23 @@ require "mobility/backends/active_record/query_methods"
|
|
4
4
|
|
5
5
|
module Mobility
|
6
6
|
module Backends
|
7
|
-
|
8
|
-
|
7
|
+
module ActiveRecord
|
8
|
+
class Jsonb::QueryMethods < QueryMethods
|
9
|
+
include PgQueryMethods
|
9
10
|
|
10
|
-
|
11
|
+
def matches(key, locale)
|
12
|
+
build_infix(:'->', arel_table[column_name(key)], build_quoted(locale))
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
def exists(key, locale)
|
16
|
+
build_infix(:'?', arel_table[column_name(key)], build_quoted(locale))
|
17
|
+
end
|
18
|
+
|
19
|
+
def quote(value)
|
20
|
+
build_quoted(value.to_json)
|
21
|
+
end
|
14
22
|
end
|
23
|
+
Jsonb.private_constant :QueryMethods
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|