mobility 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 459bb89be95d70ecd22eed9ea9b0672615428a1f
4
- data.tar.gz: a8a96d4906781731c7cb00da31850f2493d1d9e9
3
+ metadata.gz: 02ff52251ec982025bdc93821a706fce97ddfb5b
4
+ data.tar.gz: 00cc021046e222050f8baea42bdf436d93f689b3
5
5
  SHA512:
6
- metadata.gz: 2f6e6dbbe8085153bc920405dd9c95f988c2b215108b23e0d2330bcc44e286b2860f30cc51a4fa351614365777a3a4c2193699369b6b98233c11e46ef03deeb4
7
- data.tar.gz: c506df78bcabef6249efa7aedea2e6753c6e453c670cd097a155be7ca5649a3a6c29c051192cac2caa2980b130ab23c2a59e723c8f17c4fd4902244a6f43e496
6
+ metadata.gz: 9b65346069fb65cb2b90fa311ce72c1c50122f30319da89e5752d72c61295bca4c83aca798e256824b324b97e1c87e9e93ef3b38faed4e9f528329eab02c47e2
7
+ data.tar.gz: 14f9257baed55a7de39b53b37dc3f6c07e3c415ee0f088af78ca6e548c6939b97f5c495a20966a9e39263b27f6280ceaec304843f0920c542f45bfce86b7d1e0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## 0.1
4
4
 
5
+ ### 0.1.5
6
+ * Add `accessor_method` to default initializer ([d4a9da98cae71de2fb9ee3d29c64decef5a16010](https://github.com/shioyama/mobility/commit/d4a9da98cae71de2fb9ee3d29c64decef5a16010))
7
+ * Include AR version in generated migrations ([ac3dfbbc053089b01dcc73d0b617fefaeaaa85cb](https://github.com/shioyama/mobility/commit/ac3dfbbc053089b01dcc73d0b617fefaeaaa85cb))
8
+ * Add `untranslated_attributes` method ([50e97f12ea219321ef9f61792e909299f570ba23](https://github.com/shioyama/mobility/commit/50e97f12ea219321ef9f61792e909299f570ba23))
9
+ * Do not require `active_support/core_ext/nil` ([39e24596482f03302542e524ca6f17275a778644](https://github.com/shioyama/mobility/commit/39e24596482f03302542e524ca6f17275a778644))
10
+ * Handle false values correctly when getting and setting ([bdf6f199aaa8318a73c5aa6332aee8d7aad254f6](https://github.com/shioyama/mobility/commit/bdf6f199aaa8318a73c5aa6332aee8d7aad254f6))
11
+ * Use proc to define accessor locales from `I18n.available_locales` ([3cd786814d8044ae5d64f939c3a7b5c49b322bc6](https://github.com/shioyama/mobility/commit/3cd786814d8044ae5d64f939c3a7b5c49b322bc6))
12
+ * Do not mark attribute as changed if value is the same (fixed in [#2](https://github.com/shioyama/mobility/pull/2))
13
+ * Pass on any args to original reload method when overriding (fixed in [#3](https://github.com/shioyama/mobility/pull/3))
14
+
5
15
  ### 0.1.4
6
16
  * Fix configuration reload issue ([#1](https://github.com/shioyama/mobility/issues/1), fixed in [478b669dae90edf9feb7c011ae93e8157dc4e2b4](https://github.com/shioyama/mobility/commit/478b669dae90edf9feb7c011ae93e8157dc4e2b4))
7
17
  * Code refactoring/cleanup ([e4dcc791c246e377352b9ac154d2b1c4aec8e98e](https://github.com/shioyama/mobility/commit/e4dcc791c246e377352b9ac154d2b1c4aec8e98e), [64f434ea7a46c9353c3638c58a3258f0fcb81821](https://github.com/shioyama/mobility/commit/64f434ea7a46c9353c3638c58a3258f0fcb81821), [8df2bbdead883725d2c87020f836b644b4d28e5c](https://github.com/shioyama/mobility/commit/8df2bbdead883725d2c87020f836b644b4d28e5c), [326a0977c98348dad85a927c20dd69fe5acb2a9e](https://github.com/shioyama/mobility/commit/326a0977c98348dad85a927c20dd69fe5acb2a9e))
data/Gemfile.lock CHANGED
@@ -1,19 +1,50 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (0.1.3)
4
+ mobility (0.1.4)
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.1)
12
+ actionview (= 5.0.1)
13
+ activesupport (= 5.0.1)
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.1)
19
+ activesupport (= 5.0.1)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ activemodel (5.0.1)
25
+ activesupport (= 5.0.1)
26
+ activerecord (5.0.1)
27
+ activemodel (= 5.0.1)
28
+ activesupport (= 5.0.1)
29
+ arel (~> 7.0)
30
+ activesupport (5.0.1)
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)
11
37
  byebug (9.0.6)
12
38
  coderay (1.1.1)
39
+ concurrent-ruby (1.0.4)
13
40
  database_cleaner (1.5.3)
14
41
  diff-lcs (1.3)
42
+ erubis (2.7.0)
15
43
  ffi (1.9.18)
16
44
  formatador (0.2.5)
45
+ generator_spec (0.9.3)
46
+ activesupport (>= 3.0.0)
47
+ railties (>= 3.0.0)
17
48
  guard (2.14.1)
18
49
  formatador (>= 0.2.4)
19
50
  listen (>= 2.7, < 4.0)
@@ -29,14 +60,19 @@ GEM
29
60
  guard-compat (~> 1.1)
30
61
  rspec (>= 2.99.0, < 4.0)
31
62
  i18n (0.8.1)
32
- listen (3.1.5)
63
+ listen (3.0.8)
33
64
  rb-fsevent (~> 0.9, >= 0.9.4)
34
65
  rb-inotify (~> 0.9, >= 0.9.7)
35
- ruby_dep (~> 1.2)
66
+ loofah (2.0.3)
67
+ nokogiri (>= 1.5.9)
36
68
  lumberjack (1.0.11)
37
69
  method_source (0.8.2)
70
+ mini_portile2 (2.1.0)
71
+ minitest (5.10.1)
38
72
  mysql2 (0.3.21)
39
73
  nenv (0.3.0)
74
+ nokogiri (1.7.0.1)
75
+ mini_portile2 (~> 2.1.0)
40
76
  notiffany (0.1.1)
41
77
  nenv (~> 0.1)
42
78
  shellany (~> 0.0)
@@ -48,6 +84,20 @@ GEM
48
84
  pry-byebug (3.4.2)
49
85
  byebug (~> 9.0)
50
86
  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.1)
96
+ actionpack (= 5.0.1)
97
+ activesupport (= 5.0.1)
98
+ method_source
99
+ rake (>= 0.8.7)
100
+ thor (>= 0.18.1, < 2.0)
51
101
  rake (10.5.0)
52
102
  rb-fsevent (0.9.8)
53
103
  rb-inotify (0.9.8)
@@ -69,20 +119,23 @@ GEM
69
119
  diff-lcs (>= 1.2.0, < 2.0)
70
120
  rspec-support (~> 3.5.0)
71
121
  rspec-support (3.5.0)
72
- ruby_dep (1.5.0)
73
- sequel (4.42.1)
74
122
  shellany (0.0.1)
75
123
  slop (3.6.0)
76
124
  sqlite3 (1.3.13)
77
125
  thor (0.19.4)
126
+ thread_safe (0.3.6)
127
+ tzinfo (1.2.2)
128
+ thread_safe (~> 0.1)
78
129
  yard (0.9.8)
79
130
 
80
131
  PLATFORMS
81
132
  ruby
82
133
 
83
134
  DEPENDENCIES
135
+ activerecord (>= 5.0, < 5.1)
84
136
  bundler (~> 1.12)
85
137
  database_cleaner (~> 1.5.3)
138
+ generator_spec (~> 0.9.3)
86
139
  guard-rspec
87
140
  mobility!
88
141
  mysql2 (~> 0.3.10)
@@ -91,9 +144,8 @@ DEPENDENCIES
91
144
  rake (~> 10.0)
92
145
  rspec (~> 3.0)
93
146
  rspec-its (~> 1.2.0)
94
- sequel (>= 4.0.0, < 5.0)
95
147
  sqlite3
96
148
  yard (~> 0.9.0)
97
149
 
98
150
  BUNDLED WITH
99
- 1.12.5
151
+ 1.14.6
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [travis]: https://travis-ci.org/shioyama/mobility
3
3
  [gemnasium]: https://gemnasium.com/shioyama/mobility
4
4
  [codeclimate]: https://codeclimate.com/github/shioyama/mobility
5
- [docs]: http://www.rubydoc.info/gems/mobility/0.1.4
5
+ [docs]: http://www.rubydoc.info/gems/mobility
6
6
 
7
7
  # Mobility
8
8
 
@@ -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.4'
59
+ gem 'mobility', '~> 0.1.5'
60
60
  ```
61
61
 
62
62
  To translate attributes on a model, you must include (or extend) `Mobility`,
@@ -23,7 +23,7 @@ module Mobility
23
23
  def create_initializer
24
24
  create_file(
25
25
  "config/initializers/mobility.rb",
26
- "Mobility.config.default_backend = :key_value"
26
+ "Mobility.configure do |config|\n config.default_backend = :key_value\n config.accessor_method = :translates\nend"
27
27
  )
28
28
  end
29
29
 
@@ -1,4 +1,4 @@
1
- class CreateStringTranslations < ActiveRecord::Migration
1
+ class CreateStringTranslations < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
2
 
3
3
  def change
4
4
  create_table :mobility_string_translations do |t|
@@ -1,4 +1,4 @@
1
- class CreateTextTranslations < ActiveRecord::Migration
1
+ class CreateTextTranslations < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
2
 
3
3
  def change
4
4
  create_table :mobility_text_translations do |t|
@@ -0,0 +1,46 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ <%- if migration_action == 'add' -%>
3
+ def change
4
+ <% attributes.each do |attribute| -%>
5
+ <%- if attribute.reference? -%>
6
+ add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
7
+ <%- elsif attribute.token? -%>
8
+ add_column :<%= table_name %>, :<%= attribute.name %>, :string<%= attribute.inject_options %>
9
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
10
+ <%- else -%>
11
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
12
+ <%- if attribute.has_index? -%>
13
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
14
+ <%- end -%>
15
+ <%- end -%>
16
+ <%- end -%>
17
+ end
18
+ <%- elsif migration_action == 'join' -%>
19
+ def change
20
+ create_join_table :<%= join_tables.first %>, :<%= join_tables.second %> do |t|
21
+ <%- attributes.each do |attribute| -%>
22
+ <%- if attribute.reference? -%>
23
+ t.references :<%= attribute.name %><%= attribute.inject_options %>
24
+ <%- else -%>
25
+ <%= '# ' unless attribute.has_index? -%>t.index <%= attribute.index_name %><%= attribute.inject_index_options %>
26
+ <%- end -%>
27
+ <%- end -%>
28
+ end
29
+ end
30
+ <%- else -%>
31
+ def change
32
+ <% attributes.each do |attribute| -%>
33
+ <%- if migration_action -%>
34
+ <%- if attribute.reference? -%>
35
+ remove_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
36
+ <%- else -%>
37
+ <%- if attribute.has_index? -%>
38
+ remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
39
+ <%- end -%>
40
+ remove_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
41
+ <%- end -%>
42
+ <%- end -%>
43
+ <%- end -%>
44
+ end
45
+ <%- end -%>
46
+ end
@@ -0,0 +1,20 @@
1
+ require "rails/generators"
2
+ require "rails/generators/active_record/migration/migration_generator"
3
+
4
+ module Mobility
5
+ class TranslationsGenerator < ::Rails::Generators::NamedBase
6
+ include Rails::Generators::Migration
7
+
8
+ argument :attributes, type: :array, default: [], banner: "field[:type] field[:type]"
9
+ source_root File.expand_path("../templates", __FILE__)
10
+ class_option(
11
+ :backend,
12
+ type: :string,
13
+ desc: "Backend to use for translations (defaults to Mobility.default_backend)"
14
+ )
15
+
16
+ def self.next_migration_number(dirname)
17
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
18
+ end
19
+ end
20
+ end
data/lib/mobility.rb CHANGED
@@ -2,7 +2,7 @@ require 'i18n'
2
2
  require 'request_store'
3
3
  require 'mobility/version'
4
4
 
5
- %w[object nil string].each do |type|
5
+ %w[object string].each do |type|
6
6
  begin
7
7
  require "active_support/core_ext/#{type}"
8
8
  rescue LoadError
@@ -11,8 +11,15 @@ ancestors.
11
11
 
12
12
  # Adds translated attributes to +attributes+.
13
13
  # @return [Array<String>] Model attributes
14
- def attributes
15
- super.merge(translated_attributes)
14
+ # @!method attributes
15
+ def self.included(model)
16
+ model.class_eval do
17
+ alias_method :untranslated_attributes, :attributes
18
+
19
+ def attributes
20
+ super.merge(translated_attributes)
21
+ end
22
+ end
16
23
  end
17
24
 
18
25
  # Translated attributes defined on model.
@@ -14,8 +14,8 @@ Backend resetter for ActiveRecord models. Adds hook on +reload+ event to
14
14
 
15
15
  model_class.class_eval do
16
16
  mod = Module.new do
17
- define_method :reload do
18
- super().tap { instance_eval(&model_reset_method) }
17
+ define_method :reload do |*args|
18
+ super(*args).tap { instance_eval(&model_reset_method) }
19
19
  end
20
20
  end
21
21
  include mod
@@ -125,7 +125,7 @@ with other backends.
125
125
  def initialize(method, *attributes_, **options_)
126
126
  raise ArgumentError, "method must be one of: reader, writer, accessor" unless %i[reader writer accessor].include?(method)
127
127
  @options = options_
128
- @attributes = attributes_.map &:to_s
128
+ @attributes = attributes_.map(&:to_s)
129
129
  model_class = options[:model_class]
130
130
  @backend_name = options.delete(:backend) || Mobility.config.default_backend
131
131
  @backend_class = Class.new(get_backend_class(backend: @backend_name,
@@ -139,7 +139,7 @@ with other backends.
139
139
  @backend_class.include Backend::Dirty.for(model_class) if options[:dirty]
140
140
  @backend_class.include Backend::Fallbacks if options[:fallbacks]
141
141
  @accessor_locales = options[:locale_accessors]
142
- @accessor_locales = Mobility.config.default_accessor_locales if options[:locale_accessors] == true
142
+ @accessor_locales = Mobility.config.default_accessor_locales.call if options[:locale_accessors] == true
143
143
 
144
144
  attributes.each do |attribute|
145
145
  define_backend(attribute)
@@ -173,7 +173,7 @@ with other backends.
173
173
  # Yield each attribute to block
174
174
  # @yield [String] Attribute
175
175
  def each &block
176
- attributes.each &block
176
+ attributes.each(&block)
177
177
  end
178
178
 
179
179
  private
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  module Mobility
2
4
  =begin
3
5
 
@@ -102,7 +104,7 @@ On top of this, a backend will normally:
102
104
  # @param [String] attribute
103
105
  # @return [String] name of backend reader method
104
106
  def self.method_name(attribute)
105
- "#{attribute}_backend"
107
+ "#{attribute}_backend".freeze
106
108
  end
107
109
 
108
110
  # Defines setup hooks for backend to customize model class.
@@ -23,11 +23,11 @@ value of the translated attribute if passed to it.
23
23
  module ActiveModel::Dirty
24
24
  # @!group Backend Accessors
25
25
  # @!macro backend_writer
26
- def write(locale, value, **)
26
+ def write(locale, value, **options)
27
27
  locale_accessor = "#{attribute}_#{locale}"
28
28
  if model.changed_attributes.has_key?(locale_accessor) && model.changed_attributes[locale_accessor] == value
29
29
  model.attributes_changed_by_setter.except!(locale_accessor)
30
- else
30
+ elsif read(locale, options.merge(fallbacks: false)) != value
31
31
  model.send(:attribute_will_change!, "#{attribute}_#{locale}")
32
32
  end
33
33
  super
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  module Mobility
2
4
  module Backend
3
5
  =begin
@@ -108,10 +110,10 @@ Implements the {Mobility::Backend::Table} backend for ActiveRecord models.
108
110
  # to append to model class to generate translation class
109
111
  def self.configure!(options)
110
112
  table_name = options[:model_class].table_name
111
- options[:table_name] ||= "#{table_name.singularize}_translations"
113
+ options[:table_name] ||= "#{table_name.singularize}_translations".freeze
112
114
  options[:foreign_key] ||= table_name.downcase.singularize.camelize.foreign_key
113
115
  if (association_name = options[:association_name]).present?
114
- options[:subclass_name] ||= association_name.to_s.singularize.camelize
116
+ options[:subclass_name] ||= association_name.to_s.singularize.camelize.freeze
115
117
  else
116
118
  options[:association_name] = :mobility_model_translations
117
119
  options[:subclass_name] ||= :Translation
@@ -8,6 +8,15 @@ details.
8
8
  @see Mobility::Backend::ActiveModel::Dirty
9
9
  @see Mobility::Backend::Sequel::Dirty
10
10
 
11
+ @note Dirty tracking can have unexpected results when combined with fallbacks.
12
+ A change in the fallback locale value will not mark an attribute falling
13
+ through to that locale as changed, even though it may look like it has
14
+ changed. However, when the value for the current locale is changed from nil
15
+ or blank to a new value, the change will be recorded as a change from that
16
+ fallback value, rather than from the nil or blank value. The specs are the
17
+ most reliable source of information on the interaction between dirty tracking
18
+ and fallbacks.
19
+
11
20
  =end
12
21
  module Dirty
13
22
  # @param model_class Class of model this backend is defined on.
@@ -0,0 +1,28 @@
1
+ # module Mobility
2
+ # module Backend
3
+ # class I18n
4
+ # include Backend
5
+
6
+ # attr_reader :i18n_key
7
+ # attr_reader :mapping
8
+
9
+ # def initialize(model, attribute, **)
10
+ # super
11
+ # @key_map = options[:key_map]
12
+ # end
13
+
14
+ # def read(locale, **)
15
+ # I18n.t(i18n_key)
16
+ # end
17
+
18
+ # def self.configure!(options)
19
+ # raise ArgumentError, "missing key_map" unless options[:key_map].present?
20
+ # end
21
+
22
+ # private
23
+
24
+ # def i18n_key
25
+ # key_map.call(model, attribute))
26
+ # end
27
+ # end
28
+ # end
@@ -11,12 +11,12 @@ Automatically includes dirty plugin in model class when enabled.
11
11
  module Sequel::Dirty
12
12
  # @!group Backend Accessors
13
13
  # @!macro backend_writer
14
- def write(locale, value, **)
14
+ def write(locale, value, **options)
15
15
  locale_accessor = "#{attribute}_#{locale}".to_sym
16
16
  if model.column_changes.has_key?(locale_accessor) && model.initial_values[locale_accessor] == value
17
17
  super
18
18
  [model.changed_columns, model.initial_values].each { |h| h.delete(locale_accessor) }
19
- else
19
+ elsif read(locale, options.merge(fallbacks: false)) != value
20
20
  model.will_change_column("#{attribute}_#{locale}".to_sym)
21
21
  super
22
22
  end
@@ -21,7 +21,7 @@ Resets backend cache when reset events occur.
21
21
  @model_reset_method = Proc.new do
22
22
  attributes.each do |attribute|
23
23
  if @mobility_backends && @mobility_backends[attribute]
24
- @mobility_backends[attribute].instance_eval &block
24
+ @mobility_backends[attribute].instance_eval(&block)
25
25
  end
26
26
  end
27
27
  end
@@ -17,15 +17,15 @@ Stores shared Mobility configuration referenced by all backends.
17
17
  # @return [Symbol,Class]
18
18
  attr_accessor :default_backend
19
19
 
20
- # Default set of locales to use when defining accessors (defaults to
21
- # +I18n.available_locales+)
20
+ # Proc returning set of default accessor locles to use (defaults to proc
21
+ # returning +I18n.available_locales+)
22
22
  # @return [Array<Symbol>]
23
23
  attr_accessor :default_accessor_locales
24
24
 
25
25
  def initialize
26
26
  @accessor_method = :translates
27
27
  @default_fallbacks = I18n::Locale::Fallbacks.new
28
- @default_accessor_locales = I18n.available_locales
28
+ @default_accessor_locales = lambda { I18n.available_locales }
29
29
  end
30
30
  end
31
31
  end
@@ -17,3 +17,14 @@ class Object
17
17
  self if present?
18
18
  end
19
19
  end
20
+
21
+ =begin
22
+
23
+ Add +blank?+ method to +NilClass+ in case activesupport cannot be loaded.
24
+
25
+ =end
26
+ class NilClass
27
+ def blank?
28
+ true
29
+ end
30
+ end
@@ -15,7 +15,8 @@ Instance methods attached to all model classes when model includes or extends
15
15
  private
16
16
 
17
17
  def mobility_get(*args)
18
- mobility_read(*args).presence
18
+ value = mobility_read(*args)
19
+ value == false ? value : value.presence
19
20
  end
20
21
 
21
22
  def mobility_present?(*args)
@@ -23,7 +24,7 @@ Instance methods attached to all model classes when model includes or extends
23
24
  end
24
25
 
25
26
  def mobility_set(attribute, value, locale: Mobility.locale)
26
- mobility_backend_for(attribute).write(locale.to_sym, value.presence)
27
+ mobility_backend_for(attribute).write(locale.to_sym, value == false ? value : value.presence)
27
28
  end
28
29
 
29
30
  def mobility_read(attribute, **options)
@@ -62,7 +62,7 @@ passed to accessors to configure backend (see example below).
62
62
  class_eval <<-EOM, __FILE__, __LINE__ + 1
63
63
  def mobility_#{method}(*args, **options, &block)
64
64
  attributes = Attributes.new(:#{method}, *args, options.merge(model_class: self))
65
- attributes.backend.instance_eval &block if block_given?
65
+ attributes.backend.instance_eval(&block) if block_given?
66
66
  attributes.each do |attribute|
67
67
  alias_method "\#{attribute}_before_mobility", attribute if method_defined?(attribute) && #{%w[accessor reader].include? method}
68
68
  alias_method "\#{attribute}_before_mobility=", "\#{attribute}=" if method_defined?("\#{attribute}=") && #{%w[accessor writer].include? method}
@@ -1,3 +1,3 @@
1
1
  module Mobility
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.4
4
+ version: 0.1.5
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-05 00:00:00.000000000 Z
11
+ date: 2017-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store
@@ -140,6 +140,8 @@ files:
140
140
  - lib/generators/mobility/install_generator.rb
141
141
  - lib/generators/mobility/templates/create_string_translations.rb
142
142
  - lib/generators/mobility/templates/create_text_translations.rb
143
+ - lib/generators/mobility/templates/translations.rb
144
+ - lib/generators/mobility/translations_generator.rb
143
145
  - lib/mobility.rb
144
146
  - lib/mobility/active_model.rb
145
147
  - lib/mobility/active_model/attribute_methods.rb
@@ -174,6 +176,7 @@ files:
174
176
  - lib/mobility/backend/dirty.rb
175
177
  - lib/mobility/backend/fallbacks.rb
176
178
  - lib/mobility/backend/hstore.rb
179
+ - lib/mobility/backend/i18n.rb
177
180
  - lib/mobility/backend/jsonb.rb
178
181
  - lib/mobility/backend/key_value.rb
179
182
  - lib/mobility/backend/null.rb
@@ -198,7 +201,6 @@ files:
198
201
  - lib/mobility/backend/table.rb
199
202
  - lib/mobility/backend_resetter.rb
200
203
  - lib/mobility/configuration.rb
201
- - lib/mobility/core_ext/nil.rb
202
204
  - lib/mobility/core_ext/object.rb
203
205
  - lib/mobility/core_ext/string.rb
204
206
  - lib/mobility/instance_methods.rb
@@ -1,10 +0,0 @@
1
- =begin
2
-
3
- Add +blank?+ method to +NilClass+ in case activesupport cannot be loaded.
4
-
5
- =end
6
- class NilClass
7
- def blank?
8
- true
9
- end
10
- end