mobility 0.1.7 → 0.1.10
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
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -57
- data/README.md +1 -1
- data/lib/mobility.rb +5 -1
- data/lib/mobility/attributes.rb +8 -7
- data/lib/mobility/backend.rb +1 -7
- data/lib/mobility/backend/fallbacks.rb +19 -8
- data/lib/mobility/backend/sequel/table.rb +5 -5
- data/lib/mobility/configuration.rb +5 -2
- data/lib/mobility/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4e6bd70e8b65c3c32cb116227a13af4d14c7771
|
|
4
|
+
data.tar.gz: 91d3c67192c763d729fd03e958760351d29d0330
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bdfd4ac8ea998c0d1d4d991dbfdabbb9b95fe33ab911ea47f68a8a89bb90216b7bf5c80167c62ede7f527cd85e017ba0ce8066e26d452f7c28dd116e76619f55
|
|
7
|
+
data.tar.gz: 25759fa739cacccf79210270bcaf6132b909253672d80818d7be7187a9009263c81a5afdb91d252f0a16b5ff6350441001213b2c3e7083bd8b81be62dfd992aa
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## 0.1
|
|
4
4
|
|
|
5
|
+
### 0.1.10
|
|
6
|
+
* Fix fallback options ([#12](https://github.com/shioyama/mobility/pull/12) and
|
|
7
|
+
([09a163](https://github.com/shioyama/mobility/commit/09a1636bc743633fd13dc6c59ebf1e2366a0e2c4))
|
|
8
|
+
* Include fallbacks module by default
|
|
9
|
+
([#13](https://github.com/shioyama/mobility/pull/13/files))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### 0.1.9
|
|
13
|
+
|
|
14
|
+
(yanked)
|
|
15
|
+
|
|
16
|
+
### 0.1.8
|
|
17
|
+
|
|
18
|
+
(yanked)
|
|
19
|
+
|
|
5
20
|
### 0.1.7
|
|
6
21
|
* Allow passing fallback locale or locales to getter method
|
|
7
22
|
([#9](https://github.com/shioyama/mobility/pull/9))
|
data/Gemfile.lock
CHANGED
|
@@ -1,50 +1,19 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
mobility (0.1.
|
|
4
|
+
mobility (0.1.8)
|
|
5
5
|
i18n (>= 0.6.10)
|
|
6
6
|
request_store (~> 1.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionpack (5.0.2)
|
|
12
|
-
actionview (= 5.0.2)
|
|
13
|
-
activesupport (= 5.0.2)
|
|
14
|
-
rack (~> 2.0)
|
|
15
|
-
rack-test (~> 0.6.3)
|
|
16
|
-
rails-dom-testing (~> 2.0)
|
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
18
|
-
actionview (5.0.2)
|
|
19
|
-
activesupport (= 5.0.2)
|
|
20
|
-
builder (~> 3.1)
|
|
21
|
-
erubis (~> 2.7.0)
|
|
22
|
-
rails-dom-testing (~> 2.0)
|
|
23
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
24
|
-
activemodel (5.0.2)
|
|
25
|
-
activesupport (= 5.0.2)
|
|
26
|
-
activerecord (5.0.2)
|
|
27
|
-
activemodel (= 5.0.2)
|
|
28
|
-
activesupport (= 5.0.2)
|
|
29
|
-
arel (~> 7.0)
|
|
30
|
-
activesupport (5.0.2)
|
|
31
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
32
|
-
i18n (~> 0.7)
|
|
33
|
-
minitest (~> 5.1)
|
|
34
|
-
tzinfo (~> 1.1)
|
|
35
|
-
arel (7.1.4)
|
|
36
|
-
builder (3.2.3)
|
|
37
11
|
byebug (9.0.6)
|
|
38
12
|
coderay (1.1.1)
|
|
39
|
-
concurrent-ruby (1.0.5)
|
|
40
13
|
database_cleaner (1.5.3)
|
|
41
14
|
diff-lcs (1.3)
|
|
42
|
-
erubis (2.7.0)
|
|
43
15
|
ffi (1.9.18)
|
|
44
16
|
formatador (0.2.5)
|
|
45
|
-
generator_spec (0.9.3)
|
|
46
|
-
activesupport (>= 3.0.0)
|
|
47
|
-
railties (>= 3.0.0)
|
|
48
17
|
guard (2.14.1)
|
|
49
18
|
formatador (>= 0.2.4)
|
|
50
19
|
listen (>= 2.7, < 4.0)
|
|
@@ -63,16 +32,10 @@ GEM
|
|
|
63
32
|
listen (3.0.8)
|
|
64
33
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
65
34
|
rb-inotify (~> 0.9, >= 0.9.7)
|
|
66
|
-
loofah (2.0.3)
|
|
67
|
-
nokogiri (>= 1.5.9)
|
|
68
35
|
lumberjack (1.0.11)
|
|
69
36
|
method_source (0.8.2)
|
|
70
|
-
mini_portile2 (2.1.0)
|
|
71
|
-
minitest (5.10.1)
|
|
72
37
|
mysql2 (0.3.21)
|
|
73
38
|
nenv (0.3.0)
|
|
74
|
-
nokogiri (1.7.0.1)
|
|
75
|
-
mini_portile2 (~> 2.1.0)
|
|
76
39
|
notiffany (0.1.1)
|
|
77
40
|
nenv (~> 0.1)
|
|
78
41
|
shellany (~> 0.0)
|
|
@@ -84,20 +47,6 @@ GEM
|
|
|
84
47
|
pry-byebug (3.4.2)
|
|
85
48
|
byebug (~> 9.0)
|
|
86
49
|
pry (~> 0.10)
|
|
87
|
-
rack (2.0.1)
|
|
88
|
-
rack-test (0.6.3)
|
|
89
|
-
rack (>= 1.0)
|
|
90
|
-
rails-dom-testing (2.0.2)
|
|
91
|
-
activesupport (>= 4.2.0, < 6.0)
|
|
92
|
-
nokogiri (~> 1.6)
|
|
93
|
-
rails-html-sanitizer (1.0.3)
|
|
94
|
-
loofah (~> 2.0)
|
|
95
|
-
railties (5.0.2)
|
|
96
|
-
actionpack (= 5.0.2)
|
|
97
|
-
activesupport (= 5.0.2)
|
|
98
|
-
method_source
|
|
99
|
-
rake (>= 0.8.7)
|
|
100
|
-
thor (>= 0.18.1, < 2.0)
|
|
101
50
|
rake (10.5.0)
|
|
102
51
|
rb-fsevent (0.9.8)
|
|
103
52
|
rb-inotify (0.9.8)
|
|
@@ -123,19 +72,14 @@ GEM
|
|
|
123
72
|
slop (3.6.0)
|
|
124
73
|
sqlite3 (1.3.13)
|
|
125
74
|
thor (0.19.4)
|
|
126
|
-
thread_safe (0.3.6)
|
|
127
|
-
tzinfo (1.2.2)
|
|
128
|
-
thread_safe (~> 0.1)
|
|
129
75
|
yard (0.9.8)
|
|
130
76
|
|
|
131
77
|
PLATFORMS
|
|
132
78
|
ruby
|
|
133
79
|
|
|
134
80
|
DEPENDENCIES
|
|
135
|
-
activerecord (>= 5.0, < 5.1)
|
|
136
81
|
bundler (~> 1.12)
|
|
137
82
|
database_cleaner (~> 1.5.3)
|
|
138
|
-
generator_spec (~> 0.9.3)
|
|
139
83
|
guard-rspec
|
|
140
84
|
mobility!
|
|
141
85
|
mysql2 (~> 0.3.10)
|
data/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Mobility](http://dejimata.com/2017/3/3/translating-with-mobility).
|
|
|
56
56
|
Add this line to your application's Gemfile:
|
|
57
57
|
|
|
58
58
|
```ruby
|
|
59
|
-
gem 'mobility', '~> 0.1.
|
|
59
|
+
gem 'mobility', '~> 0.1.10'
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
To translate attributes on a model, you must include (or extend) `Mobility`,
|
data/lib/mobility.rb
CHANGED
|
@@ -165,12 +165,16 @@ module Mobility
|
|
|
165
165
|
|
|
166
166
|
# (see Mobility::Configuration#default_accessor_locales)
|
|
167
167
|
# @!method default_accessor_locales
|
|
168
|
-
%w[accessor_method
|
|
168
|
+
%w[accessor_method default_backend default_accessor_locales].each do |method_name|
|
|
169
169
|
define_method method_name do
|
|
170
170
|
config.public_send(method_name)
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
+
define_method :default_fallbacks do |*args|
|
|
175
|
+
config.public_send(:default_fallbacks, *args)
|
|
176
|
+
end
|
|
177
|
+
|
|
174
178
|
# Configure Mobility
|
|
175
179
|
# @yield [Mobility::Configuration] Mobility configuration
|
|
176
180
|
def configure
|
data/lib/mobility/attributes.rb
CHANGED
|
@@ -166,13 +166,6 @@ with other backends.
|
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
def include_backend_modules(backend_class, options)
|
|
170
|
-
backend_class.include(Backend::Cache) unless options[:cache] == false
|
|
171
|
-
backend_class.include(Backend::Dirty.for(options[:model_class])) if options[:dirty]
|
|
172
|
-
backend_class.include(Backend::Fallbacks) if options[:fallbacks]
|
|
173
|
-
backend_class.include(FallthroughAccessors.new(attributes)) if options[:fallthrough_accessors]
|
|
174
|
-
end
|
|
175
|
-
|
|
176
169
|
# Add this attributes module to shared {Mobility::Wrapper} and setup model
|
|
177
170
|
# with backend setup block (see {Mobility::Backend::Setup#setup_model}).
|
|
178
171
|
# @param model_class [Class] Class of model
|
|
@@ -189,6 +182,14 @@ with other backends.
|
|
|
189
182
|
|
|
190
183
|
private
|
|
191
184
|
|
|
185
|
+
# Include backend modules depending on value of options.
|
|
186
|
+
def include_backend_modules(backend_class, options)
|
|
187
|
+
backend_class.include(Backend::Cache) unless options[:cache] == false
|
|
188
|
+
backend_class.include(Backend::Dirty.for(options[:model_class])) if options[:dirty]
|
|
189
|
+
backend_class.include(Backend::Fallbacks) unless options[:fallbacks] == false
|
|
190
|
+
backend_class.include(FallthroughAccessors.new(attributes)) if options[:fallthrough_accessors]
|
|
191
|
+
end
|
|
192
|
+
|
|
192
193
|
def define_backend(attribute)
|
|
193
194
|
_backend_class, _options = backend_class, options
|
|
194
195
|
define_method Backend.method_name(attribute) do
|
data/lib/mobility/backend.rb
CHANGED
|
@@ -70,18 +70,12 @@ On top of this, a backend will normally:
|
|
|
70
70
|
# @return [Object] Model on which backend is defined
|
|
71
71
|
attr_reader :model
|
|
72
72
|
|
|
73
|
-
# @return [Hash] Backend options
|
|
74
|
-
attr_reader :options
|
|
75
|
-
|
|
76
73
|
# @!macro [new] backend_constructor
|
|
77
74
|
# @param model Model on which backend is defined
|
|
78
75
|
# @param [String] attribute Backend attribute
|
|
79
|
-
|
|
80
|
-
def initialize(model, attribute, fallbacks: nil, **options)
|
|
76
|
+
def initialize(model, attribute, **_)
|
|
81
77
|
@model = model
|
|
82
78
|
@attribute = attribute
|
|
83
|
-
@options = options
|
|
84
|
-
@fallbacks = I18n::Locale::Fallbacks.new(fallbacks) if fallbacks.is_a?(Hash)
|
|
85
79
|
end
|
|
86
80
|
|
|
87
81
|
# @!macro [new] backend_reader
|
|
@@ -76,28 +76,39 @@ locale was +nil+.
|
|
|
76
76
|
#=> "Mobilité"
|
|
77
77
|
=end
|
|
78
78
|
module Fallbacks
|
|
79
|
+
# @!macro [new] backend_constructor
|
|
80
|
+
# @param model Model on which backend is defined
|
|
81
|
+
# @param [String] attribute Backend attribute
|
|
82
|
+
# @option backend_options [Hash] fallbacks Fallbacks hash
|
|
83
|
+
def initialize(model, attributes, **backend_options)
|
|
84
|
+
super
|
|
85
|
+
@fallbacks =
|
|
86
|
+
if (fallbacks = backend_options[:fallbacks]).is_a?(Hash)
|
|
87
|
+
Mobility.default_fallbacks(fallbacks)
|
|
88
|
+
elsif fallbacks == true
|
|
89
|
+
Mobility.default_fallbacks
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
79
93
|
# @!group Backend Accessors
|
|
80
94
|
# @!macro backend_reader
|
|
81
95
|
# @param [Boolean,Symbol,Array] fallback
|
|
82
96
|
# +false+ to disable fallbacks on lookup, or a locale or array of
|
|
83
97
|
# locales to set fallback(s) for this lookup.
|
|
84
|
-
def read(locale, fallback: nil, **
|
|
98
|
+
def read(locale, fallback: nil, **options)
|
|
85
99
|
if !options[:fallbacks].nil?
|
|
86
100
|
warn "You passed an option with key 'fallbacks', which will be
|
|
87
101
|
ignored. Did you mean 'fallback'?"
|
|
88
102
|
end
|
|
89
|
-
return super if fallback == false
|
|
90
|
-
(fallback ? [locale, *fallback] : fallbacks[locale]).detect do |
|
|
91
|
-
value = super(
|
|
103
|
+
return super if fallback == false || (fallback.nil? && fallbacks.nil?)
|
|
104
|
+
(fallback ? [locale, *fallback] : fallbacks[locale]).detect do |fallback_locale|
|
|
105
|
+
value = super(fallback_locale, **options)
|
|
92
106
|
break value if value.present?
|
|
93
107
|
end
|
|
94
108
|
end
|
|
95
109
|
|
|
96
110
|
private
|
|
97
|
-
|
|
98
|
-
def fallbacks
|
|
99
|
-
@fallbacks ||= Mobility.default_fallbacks
|
|
100
|
-
end
|
|
111
|
+
attr_reader :fallbacks
|
|
101
112
|
end
|
|
102
113
|
end
|
|
103
114
|
end
|
|
@@ -13,11 +13,15 @@ Implements the {Mobility::Backend::Table} backend for Sequel models.
|
|
|
13
13
|
# @return [Symbol] name of the association method
|
|
14
14
|
attr_reader :association_name
|
|
15
15
|
|
|
16
|
+
# @return [Symbol] class for translations
|
|
17
|
+
attr_reader :translation_class
|
|
18
|
+
|
|
16
19
|
# @!macro backend_constructor
|
|
17
20
|
# @option options [Symbol] association_name Name of association
|
|
18
21
|
def initialize(model, attribute, **options)
|
|
19
22
|
super
|
|
20
|
-
@association_name
|
|
23
|
+
@association_name = options[:association_name]
|
|
24
|
+
@translation_class = options[:model_class].const_get(options[:subclass_name])
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
# @!group Backend Accessors
|
|
@@ -130,10 +134,6 @@ Implements the {Mobility::Backend::Table} backend for Sequel models.
|
|
|
130
134
|
model.send(association_name)
|
|
131
135
|
end
|
|
132
136
|
|
|
133
|
-
def translation_class
|
|
134
|
-
@translation_class ||= options[:model_class].const_get(options[:subclass_name])
|
|
135
|
-
end
|
|
136
|
-
|
|
137
137
|
def model_cache
|
|
138
138
|
model.send(:"__#{association_name}_cache")
|
|
139
139
|
end
|
|
@@ -11,7 +11,10 @@ Stores shared Mobility configuration referenced by all backends.
|
|
|
11
11
|
|
|
12
12
|
# Default fallbacks instance
|
|
13
13
|
# @return [I18n::Locale::Fallbacks]
|
|
14
|
-
|
|
14
|
+
def default_fallbacks(fallbacks = {})
|
|
15
|
+
@default_fallbacks.call(fallbacks)
|
|
16
|
+
end
|
|
17
|
+
attr_writer :default_fallbacks
|
|
15
18
|
|
|
16
19
|
# Default backend to use (can be symbol or actual backend class)
|
|
17
20
|
# @return [Symbol,Class]
|
|
@@ -31,7 +34,7 @@ Stores shared Mobility configuration referenced by all backends.
|
|
|
31
34
|
|
|
32
35
|
def initialize
|
|
33
36
|
@accessor_method = :translates
|
|
34
|
-
@default_fallbacks = I18n::Locale::Fallbacks.new
|
|
37
|
+
@default_fallbacks = lambda { |fallbacks| I18n::Locale::Fallbacks.new(fallbacks) }
|
|
35
38
|
@default_accessor_locales = lambda { I18n.available_locales }
|
|
36
39
|
end
|
|
37
40
|
end
|
data/lib/mobility/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mobility
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Salzberg
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-03-
|
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: request_store
|