mobility 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -1
- data/Gemfile.lock +3 -1
- data/README.md +428 -411
- data/lib/generators/rails/mobility/backend_generators/base.rb +69 -0
- data/lib/generators/rails/mobility/backend_generators/column_backend.rb +15 -0
- data/lib/generators/rails/mobility/backend_generators/table_backend.rb +42 -0
- data/lib/generators/rails/mobility/generators.rb +5 -0
- data/lib/generators/rails/mobility/templates/column_translations.rb +17 -0
- data/lib/generators/rails/mobility/templates/table_migration.rb +17 -0
- data/lib/generators/rails/mobility/templates/table_translations.rb +28 -0
- data/lib/generators/rails/mobility/translations_generator.rb +75 -0
- data/lib/mobility.rb +10 -3
- data/lib/mobility/attributes.rb +4 -4
- data/lib/mobility/backend/active_model/dirty.rb +0 -2
- data/lib/mobility/backend/active_record/column.rb +15 -2
- data/lib/mobility/backend/active_record/table.rb +9 -0
- data/lib/mobility/backend/column.rb +11 -16
- data/lib/mobility/backend/sequel/column.rb +8 -2
- data/lib/mobility/backend/sequel/dirty.rb +0 -2
- data/lib/mobility/backend/table.rb +5 -0
- data/lib/mobility/fallthrough_accessors.rb +2 -3
- data/lib/mobility/instance_methods.rb +5 -4
- data/lib/mobility/rails.rb +1 -2
- data/lib/mobility/version.rb +1 -1
- metadata +10 -2
@@ -15,11 +15,17 @@ Implements the {Mobility::Backend::Column} backend for Sequel models.
|
|
15
15
|
|
16
16
|
# @!group Backend Accessors
|
17
17
|
# @!macro backend_reader
|
18
|
-
|
18
|
+
def read(locale, **_)
|
19
|
+
column = column(locale)
|
20
|
+
model.send(column) if model.columns.include?(column)
|
21
|
+
end
|
19
22
|
|
20
23
|
# @!group Backend Accessors
|
21
24
|
# @!macro backend_writer
|
22
|
-
|
25
|
+
def write(locale, value, **_)
|
26
|
+
column = column(locale)
|
27
|
+
model.send("#{column}=", value) if model.columns.include?(column)
|
28
|
+
end
|
23
29
|
|
24
30
|
# @!group Backend Configuration
|
25
31
|
def self.configure!(options)
|
@@ -17,6 +17,11 @@ The backend expects the translations table (+post_translations+) to have:
|
|
17
17
|
will be all attributes of the model)
|
18
18
|
- an integer column with name +post_id+ (where +post+ is the name of the model class)
|
19
19
|
|
20
|
+
If you are using Rails, you can use the +mobility:translations+ generator to
|
21
|
+
create a migration generating this table with:
|
22
|
+
|
23
|
+
rails generate mobility:translations post title:string content:text
|
24
|
+
|
20
25
|
Unlike Globalize, attributes need not all be on one table. Mobility supports
|
21
26
|
any number of translation tables for a given model class (all of the structure
|
22
27
|
described above), provided the +association_name+ option is different for each.
|
@@ -36,10 +36,9 @@ model class is generated.
|
|
36
36
|
class FallthroughAccessors < Module
|
37
37
|
# @param [Array<String>] Array of attributes
|
38
38
|
def initialize(*attributes)
|
39
|
-
method_name_regex = /\A(#{attributes.join('|'.freeze)})_([a-z]{2}(_[a-z]{2})?)(
|
39
|
+
method_name_regex = /\A(#{attributes.join('|'.freeze)})_([a-z]{2}(_[a-z]{2})?)(=?|\??)\z/.freeze
|
40
40
|
|
41
|
-
define_method :method_missing do |method_name, *arguments, &block|
|
42
|
-
if method_name =~ method_name_regex
|
41
|
+
define_method :method_missing do |method_name, *arguments, &block| if method_name =~ method_name_regex
|
43
42
|
attribute = $1.to_sym
|
44
43
|
locale, suffix = $2.split('_'.freeze)
|
45
44
|
locale = "#{locale}-#{suffix.upcase}".freeze if suffix
|
@@ -23,12 +23,13 @@ Instance methods attached to all model classes when model includes or extends
|
|
23
23
|
mobility_read(*args).present?
|
24
24
|
end
|
25
25
|
|
26
|
-
def mobility_set(attribute, value, locale: Mobility.locale)
|
27
|
-
|
26
|
+
def mobility_set(attribute, value, locale: Mobility.locale, **options)
|
27
|
+
Mobility.enforce_available_locales!(locale)
|
28
|
+
mobility_backend_for(attribute).write(locale.to_sym, value == false ? value : value.presence, **options)
|
28
29
|
end
|
29
30
|
|
30
|
-
def mobility_read(attribute, **options)
|
31
|
-
|
31
|
+
def mobility_read(attribute, locale: Mobility.locale, **options)
|
32
|
+
Mobility.enforce_available_locales!(locale)
|
32
33
|
mobility_backend_for(attribute).read(locale.to_sym, options)
|
33
34
|
end
|
34
35
|
end
|
data/lib/mobility/rails.rb
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
require_relative "../generators/rails/mobility/install_generator"
|
1
|
+
require_relative "../generators/rails/mobility/generators"
|
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.11
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: request_store
|
@@ -137,9 +137,17 @@ files:
|
|
137
137
|
- LICENSE.txt
|
138
138
|
- README.md
|
139
139
|
- Rakefile
|
140
|
+
- lib/generators/rails/mobility/backend_generators/base.rb
|
141
|
+
- lib/generators/rails/mobility/backend_generators/column_backend.rb
|
142
|
+
- lib/generators/rails/mobility/backend_generators/table_backend.rb
|
143
|
+
- lib/generators/rails/mobility/generators.rb
|
140
144
|
- lib/generators/rails/mobility/install_generator.rb
|
145
|
+
- lib/generators/rails/mobility/templates/column_translations.rb
|
141
146
|
- lib/generators/rails/mobility/templates/create_string_translations.rb
|
142
147
|
- lib/generators/rails/mobility/templates/create_text_translations.rb
|
148
|
+
- lib/generators/rails/mobility/templates/table_migration.rb
|
149
|
+
- lib/generators/rails/mobility/templates/table_translations.rb
|
150
|
+
- lib/generators/rails/mobility/translations_generator.rb
|
143
151
|
- lib/mobility.rb
|
144
152
|
- lib/mobility/active_model.rb
|
145
153
|
- lib/mobility/active_model/attribute_methods.rb
|