mobility 0.1.10 → 0.1.11

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.
@@ -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
- # @!method read(locale, **options)
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
- # @!method write(locale, value, **options)
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)
@@ -50,8 +50,6 @@ Automatically includes dirty plugin in model class when enabled.
50
50
  end
51
51
  include mod
52
52
  end
53
-
54
- model_class.include(FallthroughAccessors.new(*attributes))
55
53
  end
56
54
  end
57
55
  end
@@ -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})?)(=?)\z/.freeze
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
- mobility_backend_for(attribute).write(locale.to_sym, value == false ? value : value.presence)
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
- locale = options.delete(:locale) || Mobility.locale
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
@@ -1,2 +1 @@
1
- require "rails/generators"
2
- require_relative "../generators/rails/mobility/install_generator"
1
+ require_relative "../generators/rails/mobility/generators"
@@ -1,3 +1,3 @@
1
1
  module Mobility
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
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.10
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-21 00:00:00.000000000 Z
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