mobility 1.0.0.beta2 → 1.0.3
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 +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +49 -4
- data/Gemfile +5 -16
- data/Gemfile.lock +20 -1
- data/README.md +23 -28
- data/lib/mobility.rb +62 -8
- 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/plugin.rb +2 -2
- 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 +7 -7
- data/lib/mobility/plugins/active_record/uniqueness_validation.rb +4 -0
- 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 +2 -2
- data/lib/rails/generators/mobility/templates/create_string_translations.rb +0 -1
- data/lib/rails/generators/mobility/templates/create_text_translations.rb +0 -1
- data/lib/rails/generators/mobility/templates/initializer.rb +9 -1
- metadata +14 -20
- 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
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mobility
|
4
|
-
module Sequel
|
5
|
-
=begin
|
6
|
-
|
7
|
-
Internal class used to force Sequel model to notice changes when mobility
|
8
|
-
setter method is called.
|
9
|
-
|
10
|
-
=end
|
11
|
-
class ColumnChanges < Module
|
12
|
-
# @param [Array<String>] attributes Backend attributes
|
13
|
-
def initialize(attributes, column_affix: "%s")
|
14
|
-
attributes.each do |attribute|
|
15
|
-
define_method "#{attribute}=" do |value, **options|
|
16
|
-
if !options[:super] && send(attribute) != value
|
17
|
-
locale = options[:locale] || Mobility.locale
|
18
|
-
column = (column_affix % attribute).to_sym
|
19
|
-
attribute_with_locale = :"#{attribute}_#{Mobility.normalize_locale(locale)}"
|
20
|
-
@changed_columns = changed_columns | [column, attribute.to_sym, attribute_with_locale]
|
21
|
-
end
|
22
|
-
super(value, **options)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mobility
|
4
|
-
module Sequel
|
5
|
-
=begin
|
6
|
-
|
7
|
-
Internal class used to initialize column value(s) by default to a hash.
|
8
|
-
|
9
|
-
=end
|
10
|
-
class HashInitializer < Module
|
11
|
-
def initialize(*columns)
|
12
|
-
class_eval <<-EOM, __FILE__, __LINE__ + 1
|
13
|
-
def initialize_set(values)
|
14
|
-
#{columns.map { |c| "self[:#{c}] = {}" }.join(';')}
|
15
|
-
super
|
16
|
-
end
|
17
|
-
EOM
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Mobility
|
2
|
-
module Sequel
|
3
|
-
=begin
|
4
|
-
|
5
|
-
Module included in translation class dynamically generated by
|
6
|
-
{Backends::Sequel::Table} backend.
|
7
|
-
|
8
|
-
=end
|
9
|
-
module ModelTranslation
|
10
|
-
def self.included(base)
|
11
|
-
base.plugin :validation_helpers
|
12
|
-
end
|
13
|
-
|
14
|
-
def validate
|
15
|
-
super
|
16
|
-
validates_presence [:locale]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/mobility/sequel/sql.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Mobility
|
2
|
-
module Sequel
|
3
|
-
module SQL
|
4
|
-
class QualifiedIdentifier < ::Sequel::SQL::QualifiedIdentifier
|
5
|
-
attr_reader :backend_class, :locale, :attribute_name
|
6
|
-
|
7
|
-
def initialize(table, column, locale, backend_class, attribute_name: nil)
|
8
|
-
@backend_class = backend_class
|
9
|
-
@locale = locale
|
10
|
-
@attribute_name = attribute_name || column
|
11
|
-
super(table, column)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Mobility
|
2
|
-
module Sequel
|
3
|
-
module Translation
|
4
|
-
def self.included(base)
|
5
|
-
base.class_eval do
|
6
|
-
plugin :validation_helpers
|
7
|
-
|
8
|
-
# Paraphased from sequel_polymorphic gem
|
9
|
-
#
|
10
|
-
model = underscore(self.to_s)
|
11
|
-
plural_model = pluralize(model)
|
12
|
-
many_to_one :translatable,
|
13
|
-
reciprocal: plural_model.to_sym,
|
14
|
-
reciprocal_type: :many_to_one,
|
15
|
-
setter: (proc do |able_instance|
|
16
|
-
self[:translatable_id] = (able_instance.pk if able_instance)
|
17
|
-
self[:translatable_type] = (able_instance.class.name if able_instance)
|
18
|
-
end),
|
19
|
-
dataset: (proc do
|
20
|
-
translatable_type = send :translatable_type
|
21
|
-
translatable_id = send :translatable_id
|
22
|
-
return if translatable_type.nil? || translatable_id.nil?
|
23
|
-
klass = self.class.send(:constantize, translatable_type)
|
24
|
-
klass.where(klass.primary_key => translatable_id)
|
25
|
-
end),
|
26
|
-
eager_loader: (proc do |eo|
|
27
|
-
id_map = {}
|
28
|
-
eo[:rows].each do |model|
|
29
|
-
model_able_type = model.send :translatable_type
|
30
|
-
model_able_id = model.send :translatable_id
|
31
|
-
model.associations[:translatable] = nil
|
32
|
-
((id_map[model_able_type] ||= {})[model_able_id] ||= []) << model if !model_able_type.nil? && !model_able_id.nil?
|
33
|
-
end
|
34
|
-
id_map.each do |klass_name, id_map|
|
35
|
-
klass = constantize(camelize(klass_name))
|
36
|
-
klass.where(klass.primary_key=>id_map.keys).all do |related_obj|
|
37
|
-
id_map[related_obj.pk].each do |model|
|
38
|
-
model.associations[:translatable] = related_obj
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end)
|
43
|
-
|
44
|
-
def validate
|
45
|
-
super
|
46
|
-
validates_presence [:locale, :key, :translatable_id, :translatable_type]
|
47
|
-
validates_unique [:locale, :key, :translatable_id, :translatable_type]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|