mobility 1.0.0.beta2 → 1.0.0.rc1
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 +3 -2
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +19 -0
- data/README.md +4 -4
- data/lib/mobility.rb +60 -6
- data/lib/mobility/backends/active_record.rb +1 -1
- data/lib/mobility/backends/active_record/column.rb +1 -1
- data/lib/mobility/backends/active_record/container.rb +4 -4
- data/lib/mobility/backends/active_record/hstore.rb +3 -3
- data/lib/mobility/backends/active_record/json.rb +3 -3
- data/lib/mobility/backends/active_record/jsonb.rb +3 -3
- data/lib/mobility/backends/active_record/key_value.rb +27 -11
- data/lib/mobility/backends/active_record/table.rb +11 -6
- data/lib/mobility/backends/sequel.rb +32 -0
- data/lib/mobility/backends/sequel/container.rb +5 -3
- data/lib/mobility/backends/sequel/key_value.rb +79 -12
- data/lib/mobility/backends/sequel/pg_hash.rb +6 -6
- data/lib/mobility/backends/sequel/table.rb +18 -8
- data/lib/mobility/backends/table.rb +11 -6
- data/lib/mobility/plugins/active_record.rb +3 -0
- data/lib/mobility/plugins/active_record/backend.rb +2 -0
- data/lib/mobility/plugins/active_record/query.rb +2 -2
- data/lib/mobility/plugins/arel.rb +125 -0
- data/lib/mobility/plugins/arel/nodes.rb +15 -0
- data/lib/mobility/plugins/arel/nodes/pg_ops.rb +134 -0
- data/lib/mobility/plugins/sequel/dirty.rb +1 -1
- data/lib/mobility/version.rb +1 -1
- metadata +5 -17
- metadata.gz.sig +0 -0
- data/lib/mobility/active_record/model_translation.rb +0 -14
- data/lib/mobility/active_record/string_translation.rb +0 -10
- data/lib/mobility/active_record/text_translation.rb +0 -10
- data/lib/mobility/active_record/translation.rb +0 -14
- data/lib/mobility/arel.rb +0 -49
- data/lib/mobility/arel/nodes.rb +0 -13
- data/lib/mobility/arel/nodes/pg_ops.rb +0 -132
- data/lib/mobility/arel/visitor.rb +0 -61
- data/lib/mobility/sequel/column_changes.rb +0 -28
- data/lib/mobility/sequel/hash_initializer.rb +0 -21
- data/lib/mobility/sequel/model_translation.rb +0 -20
- data/lib/mobility/sequel/sql.rb +0 -16
- data/lib/mobility/sequel/string_translation.rb +0 -10
- data/lib/mobility/sequel/text_translation.rb +0 -10
- data/lib/mobility/sequel/translation.rb +0 -53
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
module Mobility
|
3
|
+
module Plugins
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class Binary < ::Arel::Nodes::Binary; end
|
7
|
+
class Grouping < ::Arel::Nodes::Grouping; end
|
8
|
+
|
9
|
+
::Arel::Visitors::ToSql.class_eval do
|
10
|
+
alias :visit_Mobility_Plugins_Arel_Nodes_Grouping :visit_Arel_Nodes_Grouping
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
require "mobility/plugins/arel"
|
3
|
+
|
4
|
+
module Mobility
|
5
|
+
module Plugins
|
6
|
+
module Arel
|
7
|
+
module Nodes
|
8
|
+
%w[
|
9
|
+
JsonDashArrow
|
10
|
+
JsonDashDoubleArrow
|
11
|
+
JsonbDashArrow
|
12
|
+
JsonbDashDoubleArrow
|
13
|
+
JsonbQuestion
|
14
|
+
HstoreDashArrow
|
15
|
+
HstoreQuestion
|
16
|
+
].each do |name|
|
17
|
+
const_set name, (Class.new(Binary) do
|
18
|
+
include ::Arel::Predications
|
19
|
+
include ::Arel::OrderPredications
|
20
|
+
include ::Arel::AliasPredication
|
21
|
+
include MobilityExpressions
|
22
|
+
|
23
|
+
def lower
|
24
|
+
super self
|
25
|
+
end
|
26
|
+
end)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Needed for AR 4.2, can be removed when support is deprecated
|
30
|
+
if ::ActiveRecord::VERSION::STRING < '5.0'
|
31
|
+
[JsonbDashDoubleArrow, HstoreDashArrow].each do |klass|
|
32
|
+
klass.class_eval do
|
33
|
+
def quoted_node other
|
34
|
+
other && super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Jsonb < JsonbDashDoubleArrow
|
41
|
+
def to_dash_arrow
|
42
|
+
JsonbDashArrow.new left, right
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_question
|
46
|
+
JsonbQuestion.new left, right
|
47
|
+
end
|
48
|
+
|
49
|
+
def eq other
|
50
|
+
case other
|
51
|
+
when NilClass
|
52
|
+
to_question.not
|
53
|
+
when Integer, Array, ::Hash
|
54
|
+
to_dash_arrow.eq other.to_json
|
55
|
+
when Jsonb
|
56
|
+
to_dash_arrow.eq other.to_dash_arrow
|
57
|
+
when JsonbDashArrow
|
58
|
+
to_dash_arrow.eq other
|
59
|
+
else
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Hstore < HstoreDashArrow
|
66
|
+
def to_question
|
67
|
+
HstoreQuestion.new left, right
|
68
|
+
end
|
69
|
+
|
70
|
+
def eq other
|
71
|
+
other.nil? ? to_question.not : super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Json < JsonDashDoubleArrow; end
|
76
|
+
|
77
|
+
class JsonContainer < Json
|
78
|
+
def initialize column, locale, attr
|
79
|
+
super(Nodes::JsonDashArrow.new(column, locale), attr)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class JsonbContainer < Jsonb
|
84
|
+
def initialize column, locale, attr
|
85
|
+
@column, @locale = column, locale
|
86
|
+
super(JsonbDashArrow.new(column, locale), attr)
|
87
|
+
end
|
88
|
+
|
89
|
+
def eq other
|
90
|
+
other.nil? ? super.or(JsonbQuestion.new(@column, @locale).not) : super
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
module Visitors
|
96
|
+
def visit_Mobility_Plugins_Arel_Nodes_JsonDashArrow o, a
|
97
|
+
json_infix o, a, '->'
|
98
|
+
end
|
99
|
+
|
100
|
+
def visit_Mobility_Plugins_Arel_Nodes_JsonDashDoubleArrow o, a
|
101
|
+
json_infix o, a, '->>'
|
102
|
+
end
|
103
|
+
|
104
|
+
def visit_Mobility_Plugins_Arel_Nodes_JsonbDashArrow o, a
|
105
|
+
json_infix o, a, '->'
|
106
|
+
end
|
107
|
+
|
108
|
+
def visit_Mobility_Plugins_Arel_Nodes_JsonbDashDoubleArrow o, a
|
109
|
+
json_infix o, a, '->>'
|
110
|
+
end
|
111
|
+
|
112
|
+
def visit_Mobility_Plugins_Arel_Nodes_JsonbQuestion o, a
|
113
|
+
json_infix o, a, '?'
|
114
|
+
end
|
115
|
+
|
116
|
+
def visit_Mobility_Plugins_Arel_Nodes_HstoreDashArrow o, a
|
117
|
+
json_infix o, a, '->'
|
118
|
+
end
|
119
|
+
|
120
|
+
def visit_Mobility_Plugins_Arel_Nodes_HstoreQuestion o, a
|
121
|
+
json_infix o, a, '?'
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def json_infix o, a, opr
|
127
|
+
visit(Nodes::Grouping.new(::Arel::Nodes::InfixOperation.new(opr, o.left, o.right)), a)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
::Arel::Visitors::PostgreSQL.include Visitors
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -51,7 +51,7 @@ Automatically includes dirty plugin in model class when enabled.
|
|
51
51
|
# @!group Backend Accessors
|
52
52
|
# @!macro backend_writer
|
53
53
|
# @param [Hash] options
|
54
|
-
def write(locale, value, options
|
54
|
+
def write(locale, value, **options)
|
55
55
|
locale_accessor = Mobility.normalize_locale_accessor(attribute, locale).to_sym
|
56
56
|
if model.column_changes.has_key?(locale_accessor) && model.initial_values[locale_accessor] == value
|
57
57
|
super
|
data/lib/mobility/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
gSQml7TqcC6dZRsZRwYqzD9kUwdAJoCqno2CBUKs2l0yQAjFT36lRrVJznb7uWwa
|
35
35
|
xpPFnsrtyaZW6Dty8TSG3qzmeGpmpIotA8x1VA==
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2020-11-
|
37
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: request_store
|
@@ -156,14 +156,6 @@ files:
|
|
156
156
|
- README.md
|
157
157
|
- Rakefile
|
158
158
|
- lib/mobility.rb
|
159
|
-
- lib/mobility/active_record/model_translation.rb
|
160
|
-
- lib/mobility/active_record/string_translation.rb
|
161
|
-
- lib/mobility/active_record/text_translation.rb
|
162
|
-
- lib/mobility/active_record/translation.rb
|
163
|
-
- lib/mobility/arel.rb
|
164
|
-
- lib/mobility/arel/nodes.rb
|
165
|
-
- lib/mobility/arel/nodes/pg_ops.rb
|
166
|
-
- lib/mobility/arel/visitor.rb
|
167
159
|
- lib/mobility/backend.rb
|
168
160
|
- lib/mobility/backends.rb
|
169
161
|
- lib/mobility/backends/active_record.rb
|
@@ -209,6 +201,9 @@ files:
|
|
209
201
|
- lib/mobility/plugins/active_record/dirty.rb
|
210
202
|
- lib/mobility/plugins/active_record/query.rb
|
211
203
|
- lib/mobility/plugins/active_record/uniqueness_validation.rb
|
204
|
+
- lib/mobility/plugins/arel.rb
|
205
|
+
- lib/mobility/plugins/arel/nodes.rb
|
206
|
+
- lib/mobility/plugins/arel/nodes/pg_ops.rb
|
212
207
|
- lib/mobility/plugins/attribute_methods.rb
|
213
208
|
- lib/mobility/plugins/attributes.rb
|
214
209
|
- lib/mobility/plugins/backend.rb
|
@@ -228,13 +223,6 @@ files:
|
|
228
223
|
- lib/mobility/plugins/sequel/dirty.rb
|
229
224
|
- lib/mobility/plugins/sequel/query.rb
|
230
225
|
- lib/mobility/plugins/writer.rb
|
231
|
-
- lib/mobility/sequel/column_changes.rb
|
232
|
-
- lib/mobility/sequel/hash_initializer.rb
|
233
|
-
- lib/mobility/sequel/model_translation.rb
|
234
|
-
- lib/mobility/sequel/sql.rb
|
235
|
-
- lib/mobility/sequel/string_translation.rb
|
236
|
-
- lib/mobility/sequel/text_translation.rb
|
237
|
-
- lib/mobility/sequel/translation.rb
|
238
226
|
- lib/mobility/translations.rb
|
239
227
|
- lib/mobility/util.rb
|
240
228
|
- lib/mobility/version.rb
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Mobility
|
2
|
-
module ActiveRecord
|
3
|
-
=begin
|
4
|
-
|
5
|
-
Subclassed dynamically to generate translation class in
|
6
|
-
{Backends::ActiveRecord::Table} backend.
|
7
|
-
|
8
|
-
=end
|
9
|
-
class ModelTranslation < ::ActiveRecord::Base
|
10
|
-
self.abstract_class = true
|
11
|
-
validates :locale, presence: true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Mobility
|
2
|
-
module ActiveRecord
|
3
|
-
# @abstract Subclass and set +table_name+ to implement for a particular column type.
|
4
|
-
class Translation < ::ActiveRecord::Base
|
5
|
-
self.abstract_class = true
|
6
|
-
|
7
|
-
belongs_to :translatable, polymorphic: true, touch: true
|
8
|
-
|
9
|
-
validates :key, presence: true, uniqueness: { scope: [:translatable_id, :translatable_type, :locale], case_sensitive: true }
|
10
|
-
validates :translatable, presence: true
|
11
|
-
validates :locale, presence: true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/mobility/arel.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
require "mobility/arel/nodes"
|
3
|
-
require "mobility/arel/visitor"
|
4
|
-
|
5
|
-
module Mobility
|
6
|
-
module Arel
|
7
|
-
module MobilityExpressions
|
8
|
-
include ::Arel::Expressions
|
9
|
-
|
10
|
-
# @note This is necessary in order to ensure that when a translated
|
11
|
-
# attribute is selected with an alias using +AS+, the resulting
|
12
|
-
# expression can still be counted without blowing up.
|
13
|
-
#
|
14
|
-
# Extending +::Arel::Expressions+ is necessary to convince ActiveRecord
|
15
|
-
# that this node should not be stringified, which otherwise would
|
16
|
-
# result in garbage SQL.
|
17
|
-
#
|
18
|
-
# @see https://github.com/rails/rails/blob/847342c25c61acaea988430dc3ab66a82e3ed486/activerecord/lib/active_record/relation/calculations.rb#L261
|
19
|
-
def as(*)
|
20
|
-
super
|
21
|
-
.extend(::Arel::Expressions)
|
22
|
-
.extend(Countable)
|
23
|
-
end
|
24
|
-
|
25
|
-
module Countable
|
26
|
-
# @note This allows expressions with selected translated attributes to
|
27
|
-
# be counted.
|
28
|
-
def count(*args)
|
29
|
-
left.count(*args)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Attribute < ::Arel::Attributes::Attribute
|
35
|
-
include MobilityExpressions
|
36
|
-
|
37
|
-
attr_reader :backend_class
|
38
|
-
attr_reader :locale
|
39
|
-
attr_reader :attribute_name
|
40
|
-
|
41
|
-
def initialize(relation, column_name, locale, backend_class, attribute_name = nil)
|
42
|
-
@backend_class = backend_class
|
43
|
-
@locale = locale
|
44
|
-
@attribute_name = attribute_name || column_name
|
45
|
-
super(relation, column_name)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/mobility/arel/nodes.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
module Mobility
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class Binary < ::Arel::Nodes::Binary; end
|
6
|
-
class Grouping < ::Arel::Nodes::Grouping; end
|
7
|
-
|
8
|
-
::Arel::Visitors::ToSql.class_eval do
|
9
|
-
alias :visit_Mobility_Arel_Nodes_Grouping :visit_Arel_Nodes_Grouping
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
require "mobility/arel"
|
3
|
-
|
4
|
-
module Mobility
|
5
|
-
module Arel
|
6
|
-
module Nodes
|
7
|
-
%w[
|
8
|
-
JsonDashArrow
|
9
|
-
JsonDashDoubleArrow
|
10
|
-
JsonbDashArrow
|
11
|
-
JsonbDashDoubleArrow
|
12
|
-
JsonbQuestion
|
13
|
-
HstoreDashArrow
|
14
|
-
HstoreQuestion
|
15
|
-
].each do |name|
|
16
|
-
const_set name, (Class.new(Binary) do
|
17
|
-
include ::Arel::Predications
|
18
|
-
include ::Arel::OrderPredications
|
19
|
-
include ::Arel::AliasPredication
|
20
|
-
include ::Mobility::Arel::MobilityExpressions
|
21
|
-
|
22
|
-
def lower
|
23
|
-
super self
|
24
|
-
end
|
25
|
-
end)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Needed for AR 4.2, can be removed when support is deprecated
|
29
|
-
if ::ActiveRecord::VERSION::STRING < '5.0'
|
30
|
-
[JsonbDashDoubleArrow, HstoreDashArrow].each do |klass|
|
31
|
-
klass.class_eval do
|
32
|
-
def quoted_node other
|
33
|
-
other && super
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class Jsonb < JsonbDashDoubleArrow
|
40
|
-
def to_dash_arrow
|
41
|
-
JsonbDashArrow.new left, right
|
42
|
-
end
|
43
|
-
|
44
|
-
def to_question
|
45
|
-
JsonbQuestion.new left, right
|
46
|
-
end
|
47
|
-
|
48
|
-
def eq other
|
49
|
-
case other
|
50
|
-
when NilClass
|
51
|
-
to_question.not
|
52
|
-
when Integer, Array, ::Hash
|
53
|
-
to_dash_arrow.eq other.to_json
|
54
|
-
when Jsonb
|
55
|
-
to_dash_arrow.eq other.to_dash_arrow
|
56
|
-
when JsonbDashArrow
|
57
|
-
to_dash_arrow.eq other
|
58
|
-
else
|
59
|
-
super
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class Hstore < HstoreDashArrow
|
65
|
-
def to_question
|
66
|
-
HstoreQuestion.new left, right
|
67
|
-
end
|
68
|
-
|
69
|
-
def eq other
|
70
|
-
other.nil? ? to_question.not : super
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Json < JsonDashDoubleArrow; end
|
75
|
-
|
76
|
-
class JsonContainer < Json
|
77
|
-
def initialize column, locale, attr
|
78
|
-
super(Arel::Nodes::JsonDashArrow.new(column, locale), attr)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class JsonbContainer < Jsonb
|
83
|
-
def initialize column, locale, attr
|
84
|
-
@column, @locale = column, locale
|
85
|
-
super(JsonbDashArrow.new(column, locale), attr)
|
86
|
-
end
|
87
|
-
|
88
|
-
def eq other
|
89
|
-
other.nil? ? super.or(JsonbQuestion.new(@column, @locale).not) : super
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
module Visitors
|
95
|
-
def visit_Mobility_Arel_Nodes_JsonDashArrow o, a
|
96
|
-
json_infix o, a, '->'
|
97
|
-
end
|
98
|
-
|
99
|
-
def visit_Mobility_Arel_Nodes_JsonDashDoubleArrow o, a
|
100
|
-
json_infix o, a, '->>'
|
101
|
-
end
|
102
|
-
|
103
|
-
def visit_Mobility_Arel_Nodes_JsonbDashArrow o, a
|
104
|
-
json_infix o, a, '->'
|
105
|
-
end
|
106
|
-
|
107
|
-
def visit_Mobility_Arel_Nodes_JsonbDashDoubleArrow o, a
|
108
|
-
json_infix o, a, '->>'
|
109
|
-
end
|
110
|
-
|
111
|
-
def visit_Mobility_Arel_Nodes_JsonbQuestion o, a
|
112
|
-
json_infix o, a, '?'
|
113
|
-
end
|
114
|
-
|
115
|
-
def visit_Mobility_Arel_Nodes_HstoreDashArrow o, a
|
116
|
-
json_infix o, a, '->'
|
117
|
-
end
|
118
|
-
|
119
|
-
def visit_Mobility_Arel_Nodes_HstoreQuestion o, a
|
120
|
-
json_infix o, a, '?'
|
121
|
-
end
|
122
|
-
|
123
|
-
private
|
124
|
-
|
125
|
-
def json_infix o, a, opr
|
126
|
-
visit(Nodes::Grouping.new(::Arel::Nodes::InfixOperation.new(opr, o.left, o.right)), a)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
::Arel::Visitors::PostgreSQL.include Visitors
|
131
|
-
end
|
132
|
-
end
|