mobility 1.0.0.beta2 → 1.0.3

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 +49 -4
  5. data/Gemfile +5 -16
  6. data/Gemfile.lock +20 -1
  7. data/README.md +23 -28
  8. data/lib/mobility.rb +62 -8
  9. data/lib/mobility/backends/active_record.rb +1 -1
  10. data/lib/mobility/backends/active_record/column.rb +1 -1
  11. data/lib/mobility/backends/active_record/container.rb +4 -4
  12. data/lib/mobility/backends/active_record/hstore.rb +3 -3
  13. data/lib/mobility/backends/active_record/json.rb +3 -3
  14. data/lib/mobility/backends/active_record/jsonb.rb +3 -3
  15. data/lib/mobility/backends/active_record/key_value.rb +27 -11
  16. data/lib/mobility/backends/active_record/table.rb +11 -6
  17. data/lib/mobility/backends/sequel.rb +32 -0
  18. data/lib/mobility/backends/sequel/container.rb +5 -3
  19. data/lib/mobility/backends/sequel/key_value.rb +79 -12
  20. data/lib/mobility/backends/sequel/pg_hash.rb +6 -6
  21. data/lib/mobility/backends/sequel/table.rb +18 -8
  22. data/lib/mobility/backends/table.rb +11 -6
  23. data/lib/mobility/plugin.rb +2 -2
  24. data/lib/mobility/plugins/active_record.rb +3 -0
  25. data/lib/mobility/plugins/active_record/backend.rb +2 -0
  26. data/lib/mobility/plugins/active_record/query.rb +7 -7
  27. data/lib/mobility/plugins/active_record/uniqueness_validation.rb +4 -0
  28. data/lib/mobility/plugins/arel.rb +125 -0
  29. data/lib/mobility/plugins/arel/nodes.rb +15 -0
  30. data/lib/mobility/plugins/arel/nodes/pg_ops.rb +134 -0
  31. data/lib/mobility/plugins/sequel/dirty.rb +1 -1
  32. data/lib/mobility/version.rb +2 -2
  33. data/lib/rails/generators/mobility/templates/create_string_translations.rb +0 -1
  34. data/lib/rails/generators/mobility/templates/create_text_translations.rb +0 -1
  35. data/lib/rails/generators/mobility/templates/initializer.rb +9 -1
  36. metadata +14 -20
  37. metadata.gz.sig +0 -0
  38. data/lib/mobility/active_record/model_translation.rb +0 -14
  39. data/lib/mobility/active_record/string_translation.rb +0 -10
  40. data/lib/mobility/active_record/text_translation.rb +0 -10
  41. data/lib/mobility/active_record/translation.rb +0 -14
  42. data/lib/mobility/arel.rb +0 -49
  43. data/lib/mobility/arel/nodes.rb +0 -13
  44. data/lib/mobility/arel/nodes/pg_ops.rb +0 -132
  45. data/lib/mobility/arel/visitor.rb +0 -61
  46. data/lib/mobility/sequel/column_changes.rb +0 -28
  47. data/lib/mobility/sequel/hash_initializer.rb +0 -21
  48. data/lib/mobility/sequel/model_translation.rb +0 -20
  49. data/lib/mobility/sequel/sql.rb +0 -16
  50. data/lib/mobility/sequel/string_translation.rb +0 -10
  51. data/lib/mobility/sequel/text_translation.rb +0 -10
  52. 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
@@ -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,10 +0,0 @@
1
- # frozen_string_literal: true
2
- require "mobility/sequel/translation"
3
-
4
- module Mobility
5
- module Sequel
6
- class StringTranslation < ::Sequel::Model(:mobility_string_translations)
7
- include Translation
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
- require "mobility/sequel/translation"
3
-
4
- module Mobility
5
- module Sequel
6
- class TextTranslation < ::Sequel::Model(:mobility_text_translations)
7
- include Translation
8
- end
9
- end
10
- 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