mobility 1.2.1 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 826490fa3ce8fc86d22c06737a226e7b35aa509d1ccc47e777f1f2fb18eacc77
4
- data.tar.gz: 4625eff941c67cde509b7e5d9e5f36deb7f204058d5ba4287d62a367244c007e
3
+ metadata.gz: bfb0cb0bd2a8efd18e8fab29abf7512a765086b4d6e3d27234d8c8d6085fd5d1
4
+ data.tar.gz: b143906e032fe332dbb169badc3cc3cd8dd876e4d45f2556ed1a8ae5d4cfb1ab
5
5
  SHA512:
6
- metadata.gz: e496eb5a3a3635d749ded9019795ed4753dc9c4e2f25a89aa022a4ee5aa1116a5ff21b4f3f503f0cc3ecc7b7b087849d2f3fd5e805e0101d1fc23faa62f36823
7
- data.tar.gz: 395035bbfa2e3309cc627706c466f58ab8c4f6dc5af63185365be8d3d79a623cf317626acd6b3d9ab95c4c936ca3136452b1513c268ca8979aeeaea76ae4539f
6
+ metadata.gz: 35d4c26eb09f5facee434046bb1c447fb43ff4a19ab0f911414239a3b8d758f2c41fb4ae857027e8f50041fc56caa64b3c7291c05b0e80491542d72e1c88c2e3
7
+ data.tar.gz: 04d437ce889463ef6049d2f8b3cb1695a22e444a3f4057cb62be6c9fee8cd4516210dc18be4bbcfdd4b7945fdd9bb95c4960cee3e7413d2130a02b188c4f87e2
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # Mobility Changelog
2
2
 
3
3
  ## Unreleased
4
- - Assign blank values in pg hash backends
5
- ([#516](https://github.com/shioyama/mobility/pull/516))
6
-
7
- ## 1.1
4
+ - Simplify Fallbacks plugin
5
+ ([#531](https://github.com/shioyama/mobility/pull/531))
8
6
 
9
7
  ## 1.2
10
8
 
9
+ ### 1.2.2
10
+ - Make models work with `Marshal.dump`
11
+ ([#532](https://github.com/shioyama/mobility/pull/532))
12
+
11
13
  ### 1.2.1
12
14
  - Refactor ColumnFallback plugin
13
15
  ([#530](https://github.com/shioyama/mobility/pull/530))
@@ -22,6 +24,8 @@
22
24
  - Clearly distinguish backend classes from their configured subclasses
23
25
  ([#527](https://github.com/shioyama/mobility/pull/527))
24
26
 
27
+ ## 1.1
28
+
25
29
  ### 1.1.3
26
30
  - Do not swallow keyword args on ruby 3 in fallthrough accessors
27
31
  ([#520](https://github.com/shioyama/mobility/pull/520)) thanks
data/Gemfile.lock CHANGED
@@ -1,44 +1,28 @@
1
- GIT
2
- remote: https://github.com/rails/rails.git
3
- revision: 53000f3a2df5c59252d019bbb8d46728b291ec74
4
- branch: main
5
- specs:
6
- activemodel (7.0.0.alpha2)
7
- activesupport (= 7.0.0.alpha2)
8
- activerecord (7.0.0.alpha2)
9
- activemodel (= 7.0.0.alpha2)
10
- activesupport (= 7.0.0.alpha2)
11
- activesupport (7.0.0.alpha2)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 1.6, < 2)
14
- minitest (>= 5.1)
15
- tzinfo (~> 2.0)
16
-
17
1
  PATH
18
2
  remote: .
19
3
  specs:
20
- mobility (1.2.0)
4
+ mobility (1.2.1)
21
5
  i18n (>= 0.6.10, < 2)
22
6
  request_store (~> 1.0)
23
7
 
24
8
  GEM
25
9
  remote: https://rubygems.org/
26
10
  specs:
27
- benchmark-ips (2.8.4)
11
+ benchmark-ips (2.9.1)
28
12
  byebug (11.1.3)
29
13
  coderay (1.1.3)
30
14
  concurrent-ruby (1.1.9)
31
15
  database_cleaner (1.99.0)
32
16
  diff-lcs (1.4.4)
33
- ffi (1.15.0)
34
- formatador (0.2.5)
35
- guard (2.16.2)
17
+ ffi (1.15.4)
18
+ formatador (0.3.0)
19
+ guard (2.18.0)
36
20
  formatador (>= 0.2.4)
37
21
  listen (>= 2.7, < 4.0)
38
22
  lumberjack (>= 1.0.12, < 2.0)
39
23
  nenv (~> 0.1)
40
24
  notiffany (~> 0.0)
41
- pry (>= 0.9.12)
25
+ pry (>= 0.13.0)
42
26
  shellany (~> 0.0)
43
27
  thor (>= 0.18.1)
44
28
  guard-compat (1.2.1)
@@ -48,12 +32,11 @@ GEM
48
32
  rspec (>= 2.99.0, < 4.0)
49
33
  i18n (1.8.10)
50
34
  concurrent-ruby (~> 1.0)
51
- listen (3.5.1)
35
+ listen (3.7.0)
52
36
  rb-fsevent (~> 0.10, >= 0.10.3)
53
37
  rb-inotify (~> 0.9, >= 0.9.10)
54
38
  lumberjack (1.2.8)
55
39
  method_source (1.0.0)
56
- minitest (5.14.4)
57
40
  nenv (0.3.0)
58
41
  notiffany (0.1.3)
59
42
  nenv (~> 0.1)
@@ -67,7 +50,7 @@ GEM
67
50
  pry (~> 0.13.0)
68
51
  rack (2.2.3)
69
52
  rake (12.3.3)
70
- rb-fsevent (0.10.4)
53
+ rb-fsevent (0.11.0)
71
54
  rb-inotify (0.10.1)
72
55
  ffi (~> 1.0)
73
56
  request_store (1.5.0)
@@ -85,18 +68,15 @@ GEM
85
68
  diff-lcs (>= 1.2.0, < 2.0)
86
69
  rspec-support (~> 3.10.0)
87
70
  rspec-support (3.10.2)
71
+ sequel (5.47.0)
88
72
  shellany (0.0.1)
89
73
  thor (1.1.0)
90
- tzinfo (2.0.4)
91
- concurrent-ruby (~> 1.0)
92
74
  yard (0.9.26)
93
75
 
94
76
  PLATFORMS
95
77
  ruby
96
78
 
97
79
  DEPENDENCIES
98
- activerecord!
99
- activesupport!
100
80
  benchmark-ips
101
81
  database_cleaner (~> 1.5, >= 1.5.3)
102
82
  guard-rspec
@@ -105,6 +85,7 @@ DEPENDENCIES
105
85
  pry-byebug
106
86
  rake (~> 12, >= 12.2.1)
107
87
  rspec (~> 3.0)
88
+ sequel (= 5.47)
108
89
  yard (~> 0.9.0)
109
90
 
110
91
  BUNDLED WITH
data/README.md CHANGED
@@ -55,7 +55,7 @@ Installation
55
55
  Add this line to your application's Gemfile:
56
56
 
57
57
  ```ruby
58
- gem 'mobility', '~> 1.2.1'
58
+ gem 'mobility', '~> 1.2.2'
59
59
  ```
60
60
 
61
61
  ### ActiveRecord (Rails)
@@ -77,6 +77,12 @@ On top of this, a backend will normally:
77
77
  @attribute = args[1]
78
78
  end
79
79
 
80
+ def ==(backend)
81
+ backend.class == self.class &&
82
+ backend.attribute == attribute &&
83
+ backend.model == model
84
+ end
85
+
80
86
  # @!macro [new] backend_reader
81
87
  # Gets the translated value for provided locale from configured backend.
82
88
  # @param [Symbol] locale Locale to read
@@ -100,7 +100,7 @@ Implements the {Mobility::Backends::Container} backend for Sequel models.
100
100
  # @return [Mobility::Backends::Sequel::Container::JSONOp,Mobility::Backends::Sequel::Container::JSONBOp]
101
101
  def self.build_op(attr, locale)
102
102
  klass = const_get("#{options[:column_type].upcase}Op")
103
- klass.new(klass.new(column_name.to_sym)[locale.to_s]).get_text(attr)
103
+ klass.new(klass.new(column_name.to_sym).get(locale.to_s)).get_text(attr)
104
104
  end
105
105
 
106
106
  class JSONOp < ::Sequel::Postgres::JSONOp; end
@@ -114,15 +114,33 @@ Defines:
114
114
  defaults[key] = [backend, backend_options] if backend
115
115
  end
116
116
 
117
+ class MobilityBackends < Hash
118
+ def initialize(model)
119
+ @model = model
120
+ super()
121
+ end
122
+
123
+ def [](name)
124
+ return fetch(name) if has_key?(name)
125
+ return self[name.to_sym] if String === name
126
+ self[name] = @model.class.mobility_backend_class(name).new(@model, name.to_s)
127
+ end
128
+
129
+ def marshal_dump
130
+ @model
131
+ end
132
+
133
+ def marshal_load(model)
134
+ @model = model
135
+ end
136
+ end
137
+
117
138
  module InstanceMethods
118
139
  # Return a new backend for an attribute name.
119
140
  # @return [Hash] Hash of attribute names and backend instances
120
141
  # @api private
121
142
  def mobility_backends
122
- @mobility_backends ||= ::Hash.new do |hash, name|
123
- next hash[name.to_sym] if String === name
124
- hash[name] = self.class.mobility_backend_class(name).new(self, name.to_s)
125
- end
143
+ @mobility_backends ||= MobilityBackends.new(self)
126
144
  end
127
145
 
128
146
  def initialize_dup(other)
@@ -117,8 +117,10 @@ the current locale was +nil+.
117
117
  # Applies fallbacks plugin to attributes. Completely disables fallbacks
118
118
  # on model if option is +false+.
119
119
  included_hook do |_, backend_class|
120
- fallbacks = options[:fallbacks]
121
- backend_class.include(BackendReader.new(fallbacks, method(:generate_fallbacks))) unless fallbacks == false
120
+ backend_class.include(BackendInstanceMethods) unless options[:fallbacks] == false
121
+ # This is weird. We need to find a better way to allow customization of
122
+ # rarely-customized code like this.
123
+ backend_class.define_method(:generate_fallbacks, &method(:generate_fallbacks))
122
124
  end
123
125
 
124
126
  private
@@ -134,33 +136,26 @@ the current locale was +nil+.
134
136
  end
135
137
  end
136
138
 
137
- class BackendReader < Module
138
- def initialize(fallbacks_option, fallbacks_generator)
139
- @fallbacks_generator = fallbacks_generator
140
- define_read(convert_option_to_fallbacks(fallbacks_option))
141
- end
142
-
143
- private
144
-
145
- def define_read(fallbacks)
146
- define_method :read do |locale, fallback: true, **options|
147
- return super(locale, **options) if !fallback || options[:locale]
139
+ module BackendInstanceMethods
140
+ def read(locale, fallback: true, **accessor_options)
141
+ return super(locale, **options) if !fallback || accessor_options[:locale]
148
142
 
149
- locales = fallback == true ? fallbacks[locale] : [locale, *fallback]
150
- locales.each do |fallback_locale|
151
- value = super(fallback_locale, **options)
152
- return value if Util.present?(value)
153
- end
154
-
155
- super(locale, **options)
143
+ locales = fallback == true ? fallbacks[locale] : [locale, *fallback]
144
+ locales.each do |fallback_locale|
145
+ value = super(fallback_locale, **accessor_options)
146
+ return value if Util.present?(value)
156
147
  end
148
+
149
+ super(locale, **options)
157
150
  end
158
151
 
159
- def convert_option_to_fallbacks(option)
160
- if option.is_a?(::Hash)
161
- @fallbacks_generator[option]
162
- elsif option == true
163
- @fallbacks_generator[{}]
152
+ private
153
+
154
+ def fallbacks
155
+ if options[:fallbacks].is_a?(Hash)
156
+ generate_fallbacks(options[:fallbacks])
157
+ elsif options[:fallbacks] == true
158
+ generate_fallbacks({})
164
159
  else
165
160
  ::Hash.new { [] }
166
161
  end
@@ -8,7 +8,7 @@ module Mobility
8
8
  module VERSION
9
9
  MAJOR = 1
10
10
  MINOR = 2
11
- TINY = 1
11
+ TINY = 2
12
12
  PRE = nil
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
data.tar.gz.sig CHANGED
Binary file
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.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -34,7 +34,7 @@ cert_chain:
34
34
  eBMcZq0d1tbtv1M1UXND9mOfhLZ31YvoSTPkrJiRpljUNgD0+ugelnr1/5X/9k8y
35
35
  J9QOd3C5jpSShf/HMvpJnFuSYFm19cH9GrHjvw==
36
36
  -----END CERTIFICATE-----
37
- date: 2021-09-27 00:00:00.000000000 Z
37
+ date: 2021-10-03 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: request_store
metadata.gz.sig CHANGED
Binary file