mobility 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -3,19 +3,23 @@ require "mobility/backends/sequel/query_methods"
|
|
3
3
|
|
4
4
|
module Mobility
|
5
5
|
module Backends
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module Sequel
|
7
|
+
class Column::QueryMethods < QueryMethods
|
8
|
+
def initialize(attributes, _)
|
9
|
+
super
|
10
|
+
q = self
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
%w[exclude or where].each do |method_name|
|
13
|
+
define_method method_name do |*conds, &block|
|
14
|
+
if i18n_keys = q.extract_attributes(conds.first)
|
15
|
+
cond = conds.first.dup
|
16
|
+
i18n_keys.each do |attr|
|
17
|
+
cond[Backends::Column.column_name_for(attr)] = q.collapse cond.delete(attr)
|
18
|
+
end
|
19
|
+
super(cond, &block)
|
20
|
+
else
|
21
|
+
super(*conds, &block)
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -6,29 +6,36 @@ Sequel.extension :pg_json, :pg_json_ops
|
|
6
6
|
|
7
7
|
module Mobility
|
8
8
|
module Backends
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def initialize(attributes, options)
|
14
|
-
super
|
15
|
-
@column_name = options[:column_name]
|
16
|
-
define_query_methods
|
17
|
-
end
|
9
|
+
module Sequel
|
10
|
+
class Container::JsonQueryMethods < QueryMethods
|
11
|
+
include PgQueryMethods
|
12
|
+
attr_reader :column_name
|
18
13
|
|
19
|
-
|
14
|
+
def initialize(attributes, options)
|
15
|
+
super
|
16
|
+
@column_name = options[:column_name]
|
17
|
+
define_query_methods
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def matches(key, locale)
|
21
|
+
build_op(column_name)[locale].get_text(key.to_s)
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def exists(key, locale)
|
25
|
+
matches(key, locale) !~ nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def quote(value)
|
29
|
+
value && value.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
def build_op(key)
|
35
|
+
::Sequel.pg_json_op(key)
|
36
|
+
end
|
31
37
|
end
|
38
|
+
Container.private_constant :JsonQueryMethods
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
@@ -6,29 +6,36 @@ Sequel.extension :pg_json, :pg_json_ops
|
|
6
6
|
|
7
7
|
module Mobility
|
8
8
|
module Backends
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def initialize(attributes, options)
|
14
|
-
super
|
15
|
-
@column_name = options[:column_name]
|
16
|
-
define_query_methods
|
17
|
-
end
|
9
|
+
module Sequel
|
10
|
+
class Container::JsonbQueryMethods < QueryMethods
|
11
|
+
include PgQueryMethods
|
12
|
+
attr_reader :column_name
|
18
13
|
|
19
|
-
|
14
|
+
def initialize(attributes, options)
|
15
|
+
super
|
16
|
+
@column_name = options[:column_name]
|
17
|
+
define_query_methods
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def matches(key, locale)
|
21
|
+
build_op(column_name)[locale][key.to_s]
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def exists(key, locale)
|
25
|
+
build_op(column_name).has_key?(locale) & build_op(column_name)[locale].has_key?(key.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def quote(value)
|
29
|
+
value && value.to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
def build_op(key)
|
35
|
+
::Sequel.pg_jsonb_op(key)
|
36
|
+
end
|
31
37
|
end
|
38
|
+
Container.private_constant :JsonbQueryMethods
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
@@ -9,21 +9,23 @@ Implements the {Mobility::Backends::Hstore} backend for Sequel models.
|
|
9
9
|
@see Mobility::Backends::Sequel::HashValued
|
10
10
|
|
11
11
|
=end
|
12
|
-
|
13
|
-
|
12
|
+
module Sequel
|
13
|
+
class Hstore < PgHash
|
14
|
+
require 'mobility/backends/sequel/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
|
@@ -6,22 +6,29 @@ Sequel.extension :pg_hstore, :pg_hstore_ops
|
|
6
6
|
|
7
7
|
module Mobility
|
8
8
|
module Backends
|
9
|
-
|
10
|
-
|
9
|
+
module Sequel
|
10
|
+
class Hstore::QueryMethods < QueryMethods
|
11
|
+
include PgQueryMethods
|
11
12
|
|
12
|
-
|
13
|
+
def matches(key, locale)
|
14
|
+
build_op(key)[locale]
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def exists(key, locale)
|
18
|
+
build_op(key).has_key?(locale)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def quote(value)
|
22
|
+
value && value.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
def build_op(key)
|
28
|
+
::Sequel.hstore_op(column_name(key))
|
29
|
+
end
|
24
30
|
end
|
31
|
+
Hstore.private_constant :QueryMethods
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
@@ -9,28 +9,30 @@ Implements the {Mobility::Backends::Json} backend for Sequel models.
|
|
9
9
|
@see Mobility::Backends::Sequel::HashValued
|
10
10
|
|
11
11
|
=end
|
12
|
-
|
13
|
-
|
12
|
+
module Sequel
|
13
|
+
class Json < PgHash
|
14
|
+
require 'mobility/backends/sequel/json/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
|
@@ -6,22 +6,29 @@ Sequel.extension :pg_json, :pg_json_ops
|
|
6
6
|
|
7
7
|
module Mobility
|
8
8
|
module Backends
|
9
|
-
|
10
|
-
|
9
|
+
module Sequel
|
10
|
+
class Json::QueryMethods < QueryMethods
|
11
|
+
include PgQueryMethods
|
11
12
|
|
12
|
-
|
13
|
+
def matches(key, locale)
|
14
|
+
build_op(key).get_text(locale)
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def exists(key, locale)
|
18
|
+
matches(key, locale) !~ nil
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def quote(value)
|
22
|
+
value && value.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
def build_op(key)
|
28
|
+
::Sequel.pg_json_op(column_name(key))
|
29
|
+
end
|
24
30
|
end
|
31
|
+
Json.private_constant :QueryMethods
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
@@ -9,28 +9,30 @@ Implements the {Mobility::Backends::Jsonb} backend for Sequel models.
|
|
9
9
|
@see Mobility::Backends::Sequel::HashValued
|
10
10
|
|
11
11
|
=end
|
12
|
-
|
13
|
-
|
12
|
+
module Sequel
|
13
|
+
class Jsonb < PgHash
|
14
|
+
require 'mobility/backends/sequel/jsonb/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
|
@@ -6,22 +6,29 @@ Sequel.extension :pg_json, :pg_json_ops
|
|
6
6
|
|
7
7
|
module Mobility
|
8
8
|
module Backends
|
9
|
-
|
10
|
-
|
9
|
+
module Sequel
|
10
|
+
class Jsonb::QueryMethods < QueryMethods
|
11
|
+
include PgQueryMethods
|
11
12
|
|
12
|
-
|
13
|
+
def matches(key, locale)
|
14
|
+
build_op(key)[locale]
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def exists(key, locale)
|
18
|
+
build_op(key).has_key?(locale)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def quote(value)
|
22
|
+
value && value.to_json
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
def build_op(key)
|
28
|
+
::Sequel.pg_jsonb_op(column_name(key))
|
29
|
+
end
|
24
30
|
end
|
31
|
+
Jsonb.private_constant :QueryMethods
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
@@ -37,19 +37,18 @@ Implements the {Mobility::Backends::KeyValue} backend for Sequel models.
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# @!group Backend Configuration
|
40
|
-
# @option
|
41
|
-
# @
|
42
|
-
# @option options [Symbol] class_name ({Mobility::Sequel::TextTranslation}) Translation class
|
40
|
+
# @option (see Mobility::Backends::KeyValue::ClassMethods#configure)
|
41
|
+
# @raise (see Mobility::Backends::KeyValue::ClassMethods#configure)
|
43
42
|
# @raise [CacheRequired] if cache is disabled
|
44
|
-
# @raise [ArgumentError] if type is not either :text or :string
|
45
43
|
def self.configure(options)
|
46
|
-
super
|
47
44
|
raise CacheRequired, "Cache required for Sequel::KeyValue backend" if options[:cache] == false
|
48
|
-
|
49
|
-
options[:
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
super
|
46
|
+
if type = options[:type]
|
47
|
+
options[:association_name] ||= :"#{options[:type]}_translations"
|
48
|
+
options[:class_name] ||= Mobility::Sequel.const_get("#{type.capitalize}Translation")
|
49
|
+
end
|
50
|
+
rescue NameError
|
51
|
+
raise ArgumentError, "You must define a Mobility::Sequel::#{type.capitalize}Translation class."
|
53
52
|
end
|
54
53
|
# @!endgroup
|
55
54
|
|
@@ -84,7 +83,7 @@ Implements the {Mobility::Backends::KeyValue} backend for Sequel models.
|
|
84
83
|
include callback_methods
|
85
84
|
|
86
85
|
include DestroyKeyValueTranslations
|
87
|
-
include Mobility::Sequel::ColumnChanges.new(
|
86
|
+
include Mobility::Sequel::ColumnChanges.new(attributes)
|
88
87
|
end
|
89
88
|
|
90
89
|
setup_query_methods(QueryMethods)
|