mobility 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +7 -65
  4. data/README.md +35 -14
  5. data/lib/mobility.rb +2 -1
  6. data/lib/mobility/active_model/backend_resetter.rb +1 -1
  7. data/lib/mobility/active_record/backend_resetter.rb +1 -1
  8. data/lib/mobility/attributes.rb +10 -10
  9. data/lib/mobility/backend.rb +1 -1
  10. data/lib/mobility/backend/active_model/dirty.rb +2 -2
  11. data/lib/mobility/backend/active_record/column/query_methods.rb +8 -9
  12. data/lib/mobility/backend/active_record/hash_valued.rb +2 -2
  13. data/lib/mobility/backend/active_record/hstore.rb +1 -1
  14. data/lib/mobility/backend/active_record/hstore/query_methods.rb +1 -1
  15. data/lib/mobility/backend/active_record/jsonb/query_methods.rb +1 -1
  16. data/lib/mobility/backend/active_record/key_value.rb +3 -3
  17. data/lib/mobility/backend/active_record/query_methods.rb +1 -1
  18. data/lib/mobility/backend/active_record/serialized.rb +2 -2
  19. data/lib/mobility/backend/active_record/serialized/query_methods.rb +1 -1
  20. data/lib/mobility/backend/active_record/table.rb +3 -3
  21. data/lib/mobility/backend/cache.rb +3 -3
  22. data/lib/mobility/backend/column.rb +2 -2
  23. data/lib/mobility/backend/sequel/column/query_methods.rb +1 -1
  24. data/lib/mobility/backend/sequel/dirty.rb +4 -2
  25. data/lib/mobility/backend/sequel/hash_valued.rb +2 -2
  26. data/lib/mobility/backend/sequel/hstore.rb +1 -1
  27. data/lib/mobility/backend/sequel/hstore/query_methods.rb +1 -1
  28. data/lib/mobility/backend/sequel/jsonb/query_methods.rb +1 -1
  29. data/lib/mobility/backend/sequel/key_value.rb +2 -2
  30. data/lib/mobility/backend/sequel/query_methods.rb +1 -1
  31. data/lib/mobility/backend/sequel/serialized.rb +2 -2
  32. data/lib/mobility/backend/sequel/serialized/query_methods.rb +1 -1
  33. data/lib/mobility/backend/sequel/table.rb +3 -3
  34. data/lib/mobility/sequel/backend_resetter.rb +1 -1
  35. data/lib/mobility/version.rb +1 -1
  36. data/lib/sequel/plugins/mobility.rb +11 -0
  37. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1cb9733fa29691f2e0097d9e500081919e132a0
4
- data.tar.gz: e3a4a9ad74165350fd1cd331f2a794e1b2402c1b
3
+ metadata.gz: 459bb89be95d70ecd22eed9ea9b0672615428a1f
4
+ data.tar.gz: a8a96d4906781731c7cb00da31850f2493d1d9e9
5
5
  SHA512:
6
- metadata.gz: 8968a7a6c8b73f8c9e588050c1d07fe5fc6145fff554d419ee1bfb5c1e284c3587ea221a7cb31bcddc6976e6bafea5a8f19738a6d6fd4e768720a49cf5f7aa90
7
- data.tar.gz: efdd9d229d550a3fd09358e42e372aadb0f7df9e0372ca8e79f53996a33d55a13b866ec9c8dfd143f19d5ad078c2ab64d7353df8ac69b95113ee550d804d81f2
6
+ metadata.gz: 2f6e6dbbe8085153bc920405dd9c95f988c2b215108b23e0d2330bcc44e286b2860f30cc51a4fa351614365777a3a4c2193699369b6b98233c11e46ef03deeb4
7
+ data.tar.gz: c506df78bcabef6249efa7aedea2e6753c6e453c670cd097a155be7ca5649a3a6c29c051192cac2caa2980b130ab23c2a59e723c8f17c4fd4902244a6f43e496
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## 0.1
4
4
 
5
+ ### 0.1.4
6
+ * Fix configuration reload issue ([#1](https://github.com/shioyama/mobility/issues/1), fixed in [478b669dae90edf9feb7c011ae93e8157dc4e2b4](https://github.com/shioyama/mobility/commit/478b669dae90edf9feb7c011ae93e8157dc4e2b4))
7
+ * 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))
8
+ * Allow using Sequel `plugin` to include Mobility in model ([b0db7cc28a47e13c6888ef263260e8dff281543d](https://github.com/shioyama/mobility/commit/b0db7cc28a47e13c6888ef263260e8dff281543d))
9
+
5
10
  ### 0.1.3
6
11
 
7
12
  * Add homepage to gemspec
data/Gemfile.lock CHANGED
@@ -1,52 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (0.1.2)
4
+ mobility (0.1.3)
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 (4.2.7.1)
12
- actionview (= 4.2.7.1)
13
- activesupport (= 4.2.7.1)
14
- rack (~> 1.6)
15
- rack-test (~> 0.6.2)
16
- rails-dom-testing (~> 1.0, >= 1.0.5)
17
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
- actionview (4.2.7.1)
19
- activesupport (= 4.2.7.1)
20
- builder (~> 3.1)
21
- erubis (~> 2.7.0)
22
- rails-dom-testing (~> 1.0, >= 1.0.5)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
- activemodel (4.2.7.1)
25
- activesupport (= 4.2.7.1)
26
- builder (~> 3.1)
27
- activerecord (4.2.7.1)
28
- activemodel (= 4.2.7.1)
29
- activesupport (= 4.2.7.1)
30
- arel (~> 6.0)
31
- activesupport (4.2.7.1)
32
- i18n (~> 0.7)
33
- json (~> 1.7, >= 1.7.7)
34
- minitest (~> 5.1)
35
- thread_safe (~> 0.3, >= 0.3.4)
36
- tzinfo (~> 1.1)
37
- arel (6.0.4)
38
- builder (3.2.3)
39
11
  byebug (9.0.6)
40
12
  coderay (1.1.1)
41
13
  database_cleaner (1.5.3)
42
14
  diff-lcs (1.3)
43
- erubis (2.7.0)
44
- ffi (1.9.17)
15
+ ffi (1.9.18)
45
16
  formatador (0.2.5)
46
- generator_spec (0.9.3)
47
- activesupport (>= 3.0.0)
48
- railties (>= 3.0.0)
49
- guard (2.14.0)
17
+ guard (2.14.1)
50
18
  formatador (>= 0.2.4)
51
19
  listen (>= 2.7, < 4.0)
52
20
  lumberjack (~> 1.0)
@@ -60,22 +28,15 @@ GEM
60
28
  guard (~> 2.1)
61
29
  guard-compat (~> 1.1)
62
30
  rspec (>= 2.99.0, < 4.0)
63
- i18n (0.7.0)
64
- json (1.8.6)
31
+ i18n (0.8.1)
65
32
  listen (3.1.5)
66
33
  rb-fsevent (~> 0.9, >= 0.9.4)
67
34
  rb-inotify (~> 0.9, >= 0.9.7)
68
35
  ruby_dep (~> 1.2)
69
- loofah (2.0.3)
70
- nokogiri (>= 1.5.9)
71
36
  lumberjack (1.0.11)
72
37
  method_source (0.8.2)
73
- mini_portile2 (2.1.0)
74
- minitest (5.10.1)
75
38
  mysql2 (0.3.21)
76
39
  nenv (0.3.0)
77
- nokogiri (1.6.8.1)
78
- mini_portile2 (~> 2.1.0)
79
40
  notiffany (0.1.1)
80
41
  nenv (~> 0.1)
81
42
  shellany (~> 0.0)
@@ -87,25 +48,9 @@ GEM
87
48
  pry-byebug (3.4.2)
88
49
  byebug (~> 9.0)
89
50
  pry (~> 0.10)
90
- rack (1.6.5)
91
- rack-test (0.6.3)
92
- rack (>= 1.0)
93
- rails-deprecated_sanitizer (1.0.3)
94
- activesupport (>= 4.2.0.alpha)
95
- rails-dom-testing (1.0.7)
96
- activesupport (>= 4.2.0.beta, < 5.0)
97
- nokogiri (~> 1.6.0)
98
- rails-deprecated_sanitizer (>= 1.0.1)
99
- rails-html-sanitizer (1.0.3)
100
- loofah (~> 2.0)
101
- railties (4.2.7.1)
102
- actionpack (= 4.2.7.1)
103
- activesupport (= 4.2.7.1)
104
- rake (>= 0.8.7)
105
- thor (>= 0.18.1, < 2.0)
106
51
  rake (10.5.0)
107
52
  rb-fsevent (0.9.8)
108
- rb-inotify (0.9.7)
53
+ rb-inotify (0.9.8)
109
54
  ffi (>= 0.5.0)
110
55
  request_store (1.3.2)
111
56
  rspec (3.5.0)
@@ -125,23 +70,19 @@ GEM
125
70
  rspec-support (~> 3.5.0)
126
71
  rspec-support (3.5.0)
127
72
  ruby_dep (1.5.0)
73
+ sequel (4.42.1)
128
74
  shellany (0.0.1)
129
75
  slop (3.6.0)
130
76
  sqlite3 (1.3.13)
131
77
  thor (0.19.4)
132
- thread_safe (0.3.5)
133
- tzinfo (1.2.2)
134
- thread_safe (~> 0.1)
135
78
  yard (0.9.8)
136
79
 
137
80
  PLATFORMS
138
81
  ruby
139
82
 
140
83
  DEPENDENCIES
141
- activerecord (>= 4.2.6, < 5.0)
142
84
  bundler (~> 1.12)
143
85
  database_cleaner (~> 1.5.3)
144
- generator_spec (~> 0.9.3)
145
86
  guard-rspec
146
87
  mobility!
147
88
  mysql2 (~> 0.3.10)
@@ -150,6 +91,7 @@ DEPENDENCIES
150
91
  rake (~> 10.0)
151
92
  rspec (~> 3.0)
152
93
  rspec-its (~> 1.2.0)
94
+ sequel (>= 4.0.0, < 5.0)
153
95
  sqlite3
154
96
  yard (~> 0.9.0)
155
97
 
data/README.md CHANGED
@@ -2,6 +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
6
 
6
7
  # Mobility
7
8
 
@@ -16,12 +17,17 @@ pluggable, customizable "backends" implemented via a common interface.
16
17
 
17
18
  Out of the box, Mobility supports:
18
19
 
19
- - translations as localized columns on the model table (like [Traco](https://github.com/barsoom/traco))
20
- - translations on a model-specific table (like [Globalize](https://github.com/globalize/globalize))
20
+ - translations as localized columns on the model table (like [traco](https://rubygems.org/gems/traco))
21
+ - translations on a model-specific table (like [globalize](https://rubygems.org/gems/globalize), [rails-translate-models](https://rubygems.org/gems/rails-translate-models), [puret](https://rubygems.org/gems/puret), etc)
21
22
  - translations as values on globally shared key-value tables (the default, see [below](#backend))
22
- - translations as values of a hash serialized on a text column of the model table (like [Multilang](https://github.com/artworklv/multilang))
23
- - translations as values of a hash stored as an hstore column on a Postgres model table (like [Trasto](https://github.com/yabawock/trasto), [Multilang-hstore](https://github.com/bithavoc/multilang-hstore), [hstore_translate](https://github.com/Leadformance/hstore_translate), etc.)
24
- - translations as values of a hash stored as a jsonb column on a Postgres model table (like [json_translate](https://github.com/cfabianski/json_translate))
23
+ - translations as values of a hash serialized on a text column of the model table (like [multilang](https://rubygems.org/gems/multilang))
24
+ - translations as values of a hash stored as an hstore column on a Postgres
25
+ model table (like [trasto](https://rubygems.org/gems/trasto),
26
+ [multilang-hstore](https://rubygems.org/gems/multilang-hstore),
27
+ [hstore_translate](https://rubygems.org/gems/hstore_translate),
28
+ [sequel-hstore-translate](https://rubygems.org/gems/sequel-hstore-translate),
29
+ etc.)
30
+ - translations as values of a hash stored as a jsonb column on a Postgres model table (like [json_translate](https://rubygems.org/gems/json_translate))
25
31
 
26
32
  Each backend is implemented for both
27
33
  [ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html) and
@@ -42,12 +48,15 @@ features, including:
42
48
  the form `<attribute>_<locale>` (similar to
43
49
  [globalize-accessors](https://github.com/globalize/globalize-accessors))
44
50
 
51
+ For a detailed introduction to Mobility, see [Translating with
52
+ Mobility](http://dejimata.com/2017/3/3/translating-with-mobility).
53
+
45
54
  ## Installation
46
55
 
47
56
  Add this line to your application's Gemfile:
48
57
 
49
58
  ```ruby
50
- gem 'mobility', '~> 0.1.3'
59
+ gem 'mobility', '~> 0.1.4'
51
60
  ```
52
61
 
53
62
  To translate attributes on a model, you must include (or extend) `Mobility`,
@@ -95,8 +104,9 @@ a class to add translated attributes:
95
104
 
96
105
  ```ruby
97
106
  class Post < ActiveRecord::Base
107
+ include Mobility
98
108
  translates :title, type: :string
99
- translates :content, type: :content
109
+ translates :content, type: :text
100
110
  end
101
111
  ```
102
112
 
@@ -104,7 +114,7 @@ You now have translated attributes `title` and `content` on the model:
104
114
 
105
115
  ```ruby
106
116
  I18n.locale = :en
107
- post = Post.create(title: "foo")
117
+ post = Post.create(title: "Mobility")
108
118
  post.title #=> "Mobility"
109
119
  I18n.locale = :ja
110
120
  post.title #=> nil
@@ -123,9 +133,20 @@ else Mobility can do.
123
133
  Requirements:
124
134
  - Sequel >= 4.0
125
135
 
126
- Essentially identical to ActiveRecord, with the exception that there is no
127
- equivalent to a Rails generator (so you will need to create the migration for
128
- any translation table(s) yourself, see the API docs for details).
136
+ You can include `Mobility` just like in ActiveRecord, or you can use the
137
+ `mobility` plugin, which does the same thing:
138
+
139
+ ```ruby
140
+ class Post < ::Sequel::Model
141
+ plugin :mobility
142
+ translates :title, type: :string
143
+ translates :content, type: :text
144
+ end
145
+ ```
146
+
147
+ Otherwise everything is almost identical to AR, with the exception that there
148
+ is no equivalent to a Rails generator (so you will need to create the migration
149
+ for any translation table(s) yourself, see the API docs for details).
129
150
 
130
151
  ## Usage
131
152
 
@@ -567,7 +588,7 @@ To this end, Mobility backends strictly enforce the rule that *no backend
567
588
  should modify a parent class in any way which would interfere with other
568
589
  backends operating on the same class*. This is done using a heavy dose of
569
590
  metaprogramming, details of which can be found in the [API
570
- documentation](http://www.rubydoc.info/gems/mobility/0.1.3) and in the actual code.
591
+ documentation][docs]
571
592
 
572
593
  In practice, this means that you can use different backends for different
573
594
  attributes *on the same class* without any conflict, e.g. (assuming we
@@ -647,7 +668,7 @@ end
647
668
 
648
669
  For details on how to define a backend class, see the {Mobility::Backend}
649
670
  module and other classes defined in the [API
650
- documentation](http://www.rubydoc.info/gems/mobility/0.1.3).
671
+ documentation][docs]
651
672
 
652
673
  ### Testing Backends
653
674
 
@@ -692,7 +713,7 @@ particular implementations.
692
713
  ## More Information
693
714
 
694
715
  - [Github repository](https://www.github.com/shioyama/mobility)
695
- - [API documentation](http://www.rubydoc.info/gems/mobility/0.1.3)
716
+ - [API documentation][docs]
696
717
 
697
718
  ## License
698
719
 
data/lib/mobility.rb CHANGED
@@ -67,6 +67,7 @@ module Mobility
67
67
  begin
68
68
  require "sequel"
69
69
  raise VersionNotSupportedError, "Mobility is only compatible with Sequel 4.0 and greater" if ::Sequel::MAJOR < 4
70
+ require "sequel/plugins/mobility"
70
71
  require "sequel/extensions/inflector"
71
72
  require "sequel/plugins/dirty"
72
73
  autoload :Sequel, "mobility/sequel"
@@ -149,7 +150,7 @@ module Mobility
149
150
  # @!group Configuration Methods
150
151
  # @return [Mobility::Configuration] Mobility configuration
151
152
  def config
152
- storage[:mobility_configuration] ||= Mobility::Configuration.new
153
+ @configuration ||= Mobility::Configuration.new
153
154
  end
154
155
 
155
156
  # (see Mobility::Configuration#accessor_method)
@@ -17,7 +17,7 @@ Backend resetter for ActiveModel models. Adds hook to reset backend when
17
17
  %i[changes_applied clear_changes_information].each do |method|
18
18
  define_method method do
19
19
  super()
20
- instance_eval &model_reset_method
20
+ instance_eval(&model_reset_method)
21
21
  end
22
22
  end
23
23
  end
@@ -15,7 +15,7 @@ Backend resetter for ActiveRecord models. Adds hook on +reload+ event to
15
15
  model_class.class_eval do
16
16
  mod = Module.new do
17
17
  define_method :reload do
18
- super().tap { instance_eval &model_reset_method }
18
+ super().tap { instance_eval(&model_reset_method) }
19
19
  end
20
20
  end
21
21
  include mod
@@ -112,20 +112,20 @@ with other backends.
112
112
  attr_reader :backend_name
113
113
 
114
114
  # @param [Symbol] method One of: [reader, writer, accessor]
115
- # @param [Array<String>] _attributes Attributes to define backend for
116
- # @param [Hash] _options Backend options hash
117
- # @option _options [Class] model_class Class of model
118
- # @option _options [Boolean, Array<Symbol>] locale_accessors Enable locale
115
+ # @param [Array<String>] attributes_ Attributes to define backend for
116
+ # @param [Hash] options_ Backend options hash
117
+ # @option options_ [Class] model_class Class of model
118
+ # @option options_ [Boolean, Array<Symbol>] locale_accessors Enable locale
119
119
  # accessors or specify locales for which accessors should be defined on
120
120
  # this model backend. Will default to +true+ if +dirty+ option is +true+.
121
- # @option _options [Boolean] cache (true) Enable cache for this model backend
122
- # @option _options [Boolean, Hash] fallbacks Enable fallbacks or specify fallbacks for this model backend
123
- # @option _options [Boolean] dirty Enable dirty tracking for this model backend
121
+ # @option options_ [Boolean] cache (true) Enable cache for this model backend
122
+ # @option options_ [Boolean, Hash] fallbacks Enable fallbacks or specify fallbacks for this model backend
123
+ # @option options_ [Boolean] dirty Enable dirty tracking for this model backend
124
124
  # @raise [ArgumentError] if method is not reader, writer or accessor
125
- def initialize(method, *_attributes, **_options)
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
- @options = _options
128
- @attributes = _attributes.map &:to_s
127
+ @options = options_
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,
@@ -23,7 +23,7 @@ On top of this, a backend will normally:
23
23
 
24
24
  @example Defining a Backend
25
25
  class MyBackend
26
- include Backend
26
+ include Mobility::Backend
27
27
 
28
28
  def read(locale, **options)
29
29
  # ...
@@ -23,7 +23,7 @@ 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, **options)
26
+ def write(locale, value, **)
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)
@@ -43,7 +43,7 @@ value of the translated attribute if passed to it.
43
43
  # methods for translated attributes onto model class.
44
44
  module ClassMethods
45
45
  # (see Mobility::Backend::Setup#setup_model)
46
- def setup_model(model_class, attributes, **options)
46
+ def setup_model(model_class, attributes, **)
47
47
  super
48
48
  model_class.class_eval do
49
49
  %w[changed? change was will_change! previously_changed? previous_change].each do |suffix|
@@ -4,13 +4,16 @@ module Mobility
4
4
  def initialize(attributes, **options)
5
5
  super
6
6
  attributes_extractor = @attributes_extractor
7
-
8
- define_method :where! do |opts, *rest|
7
+ @opts_converter = opts_converter = lambda do |opts|
9
8
  if i18n_keys = attributes_extractor.call(opts)
10
9
  opts = opts.with_indifferent_access
11
10
  i18n_keys.each { |attr| opts[Column.column_name_for(attr)] = opts.delete(attr) }
12
11
  end
13
- super(opts, *rest)
12
+ return opts
13
+ end
14
+
15
+ define_method :where! do |opts, *rest|
16
+ super(opts_converter.call(opts), *rest)
14
17
  end
15
18
 
16
19
  attributes.each do |attribute|
@@ -22,15 +25,11 @@ module Mobility
22
25
 
23
26
  def extended(relation)
24
27
  super
25
- attributes_extractor = @attributes_extractor
28
+ opts_converter = @opts_converter
26
29
 
27
30
  mod = Module.new do
28
31
  define_method :not do |opts, *rest|
29
- if i18n_keys = attributes_extractor.call(opts)
30
- opts = opts.with_indifferent_access
31
- i18n_keys.each { |attr| opts[Column.column_name_for(attr)] = opts.delete(attr) }
32
- end
33
- super(opts, *rest)
32
+ super(opts_converter.call(opts), *rest)
34
33
  end
35
34
  end
36
35
  relation.model.mobility_where_chain.prepend(mod)
@@ -11,12 +11,12 @@ Internal class used by ActiveRecord backends that store values as a hash.
11
11
  # @!group Backend Accessors
12
12
  #
13
13
  # @!macro backend_reader
14
- def read(locale, **options)
14
+ def read(locale, **)
15
15
  translations[locale]
16
16
  end
17
17
 
18
18
  # @!macro backend_writer
19
- def write(locale, value, **options)
19
+ def write(locale, value, **)
20
20
  translations[locale] = value
21
21
  end
22
22
  # @!endgroup
@@ -18,7 +18,7 @@ Implements the {Mobility::Backend::Hstore} backend for ActiveRecord models.
18
18
 
19
19
  # @!group Backend Accessors
20
20
  # @!macro backend_writer
21
- def write(locale, value, **options)
21
+ def write(locale, value, **)
22
22
  translations[locale] = value && value.to_s
23
23
  end
24
24
  # @!endgroup
@@ -1,7 +1,7 @@
1
1
  module Mobility
2
2
  module Backend
3
3
  class ActiveRecord::Hstore::QueryMethods < ActiveRecord::QueryMethods
4
- def initialize(attributes, **options)
4
+ def initialize(attributes, **)
5
5
  super
6
6
  attributes_extractor = @attributes_extractor
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Mobility
2
2
  module Backend
3
3
  class ActiveRecord::Jsonb::QueryMethods < ActiveRecord::QueryMethods
4
- def initialize(attributes, **options)
4
+ def initialize(attributes, **)
5
5
  super
6
6
  attributes_extractor = @attributes_extractor
7
7
 
@@ -28,19 +28,19 @@ Implements the {Mobility::Backend::KeyValue} backend for ActiveRecord models.
28
28
 
29
29
  # @!macro backend_constructor
30
30
  # @option options [Symbol] association_name Name of association
31
- def initialize(model, attribute, **options)
31
+ def initialize(model, attribute, **)
32
32
  super
33
33
  @association_name = options[:association_name]
34
34
  end
35
35
 
36
36
  # @!group Backend Accessors
37
37
  # @!macro backend_reader
38
- def read(locale, **options)
38
+ def read(locale, **)
39
39
  translation_for(locale).value
40
40
  end
41
41
 
42
42
  # @!macro backend_reader
43
- def write(locale, value, **options)
43
+ def write(locale, value, **)
44
44
  translation_for(locale).tap { |t| t.value = value }.value
45
45
  end
46
46
  # @!endgroup
@@ -10,7 +10,7 @@ models. For details see backend-specific subclasses.
10
10
  class QueryMethods < Module
11
11
  # @param [Array<String>] attributes Translated attributes
12
12
  # @param [Hash] options Backend options
13
- def initialize(attributes, **options)
13
+ def initialize(attributes, **)
14
14
  @attributes = attributes
15
15
  @attributes_extractor = lambda do |opts|
16
16
  opts.is_a?(Hash) && (opts.keys.map(&:to_s) & attributes).presence
@@ -28,12 +28,12 @@ Implements {Mobility::Backend::Serialized} backend for ActiveRecord models.
28
28
  # @!group Backend Accessors
29
29
  #
30
30
  # @!macro backend_reader
31
- def read(locale, **options)
31
+ def read(locale, **)
32
32
  translations[locale]
33
33
  end
34
34
 
35
35
  # @!macro backend_reader
36
- def write(locale, value, **options)
36
+ def write(locale, value, **)
37
37
  translations[locale] = value
38
38
  end
39
39
  # @!endgroup
@@ -1,7 +1,7 @@
1
1
  module Mobility
2
2
  module Backend
3
3
  class ActiveRecord::Serialized::QueryMethods < ActiveRecord::QueryMethods
4
- def initialize(attributes, **options)
4
+ def initialize(attributes, **)
5
5
  super
6
6
  attributes_extractor = @attributes_extractor
7
7
  opts_checker = @opts_checker = lambda do |opts|
@@ -82,19 +82,19 @@ Implements the {Mobility::Backend::Table} backend for ActiveRecord models.
82
82
 
83
83
  # @!macro backend_constructor
84
84
  # @option options [Symbol] association_name Name of association
85
- def initialize(model, attribute, **options)
85
+ def initialize(model, attribute, **)
86
86
  super
87
87
  @association_name = options[:association_name]
88
88
  end
89
89
 
90
90
  # @!group Backend Accessors
91
91
  # @!macro backend_reader
92
- def read(locale, **options)
92
+ def read(locale, **)
93
93
  translation_for(locale).send(attribute)
94
94
  end
95
95
 
96
96
  # @!macro backend_reader
97
- def write(locale, value, **options)
97
+ def write(locale, value, **)
98
98
  translation_for(locale).tap { |t| t.send("#{attribute}=", value) }.send(attribute)
99
99
  end
100
100
  # @!endgroup
@@ -35,7 +35,7 @@ this).
35
35
  module Cache
36
36
  # @group Backend Accessors
37
37
  # @!macro backend_reader
38
- def read(locale, **options)
38
+ def read(locale, **)
39
39
  if write_to_cache? || cache.has_key?(locale)
40
40
  cache[locale]
41
41
  else
@@ -44,7 +44,7 @@ this).
44
44
  end
45
45
 
46
46
  # @!macro backend_writer
47
- def write(locale, value, **options)
47
+ def write(locale, value, **)
48
48
  cache[locale] = write_to_cache? ? value : super
49
49
  end
50
50
  # @!endgroup
@@ -57,7 +57,7 @@ this).
57
57
  # @param model_class Model class
58
58
  # @param [Array<String>] attributes Backend attributes
59
59
  # @param [Hash] options Backend options
60
- def setup_model(model_class, attributes, **options)
60
+ def setup_model(model_class, attributes, **)
61
61
  super
62
62
  model_class.include BackendResetter.for(model_class).new(attributes) { clear_cache }
63
63
  end
@@ -22,12 +22,12 @@ be ignored if set, since it would cause a conflict with column accessors.
22
22
  # @!group Backend Accessors
23
23
  #
24
24
  # @!macro backend_reader
25
- def read(locale, **options)
25
+ def read(locale, **)
26
26
  model.send(column(locale))
27
27
  end
28
28
 
29
29
  # @!macro backend_writer
30
- def write(locale, value, **options)
30
+ def write(locale, value, **)
31
31
  model.send("#{column(locale)}=", value)
32
32
  end
33
33
  # @!endgroup
@@ -1,7 +1,7 @@
1
1
  module Mobility
2
2
  module Backend
3
3
  class Sequel::Column::QueryMethods < Backend::Sequel::QueryMethods
4
- def initialize(attributes, **options)
4
+ def initialize(attributes, **)
5
5
  super
6
6
  attributes_extractor = @attributes_extractor
7
7
 
@@ -3,6 +3,7 @@ module Mobility
3
3
  =begin
4
4
 
5
5
  Dirty tracking for Sequel models which use the +Sequel::Plugins::Dirty+ plugin.
6
+ Automatically includes dirty plugin in model class when enabled.
6
7
 
7
8
  @see http://sequel.jeremyevans.net/rdoc-plugins/index.html Sequel dirty plugin
8
9
 
@@ -10,7 +11,7 @@ Dirty tracking for Sequel models which use the +Sequel::Plugins::Dirty+ plugin.
10
11
  module Sequel::Dirty
11
12
  # @!group Backend Accessors
12
13
  # @!macro backend_writer
13
- def write(locale, value, **options)
14
+ def write(locale, value, **)
14
15
  locale_accessor = "#{attribute}_#{locale}".to_sym
15
16
  if model.column_changes.has_key?(locale_accessor) && model.initial_values[locale_accessor] == value
16
17
  super
@@ -31,8 +32,9 @@ Dirty tracking for Sequel models which use the +Sequel::Plugins::Dirty+ plugin.
31
32
  # methods for translated attributes onto model class.
32
33
  module ClassMethods
33
34
  # (see Mobility::Backend::Setup#setup_model)
34
- def setup_model(model_class, attributes, **options)
35
+ def setup_model(model_class, attributes, **)
35
36
  super
37
+ model_class.plugin :dirty
36
38
  model_class.class_eval do
37
39
  mod = Module.new do
38
40
  %w[initial_value column_change column_changed? reset_column].each do |method_name|
@@ -9,12 +9,12 @@ Internal class used by Sequel backends that store values as a hash.
9
9
  include Backend
10
10
 
11
11
  # @!macro backend_reader
12
- def read(locale, **options)
12
+ def read(locale, **)
13
13
  translations[locale.to_s]
14
14
  end
15
15
 
16
16
  # @!macro backend_writer
17
- def write(locale, value, **options)
17
+ def write(locale, value, **)
18
18
  translations[locale.to_s] = value
19
19
  end
20
20
 
@@ -18,7 +18,7 @@ Implements the {Mobility::Backend::Hstore} backend for Sequel models.
18
18
 
19
19
  # @!group Backend Accessors
20
20
  # @!macro backend_writer
21
- def write(locale, value, **options)
21
+ def write(locale, value, **)
22
22
  translations[locale.to_s] = value && value.to_s
23
23
  end
24
24
  # @!endgroup
@@ -3,7 +3,7 @@ Sequel.extension :pg_hstore, :pg_hstore_ops
3
3
  module Mobility
4
4
  module Backend
5
5
  class Sequel::Hstore::QueryMethods < Sequel::QueryMethods
6
- def initialize(attributes, **options)
6
+ def initialize(attributes, **)
7
7
  super
8
8
  attributes_extractor = @attributes_extractor
9
9
 
@@ -3,7 +3,7 @@ Sequel.extension :pg_json, :pg_json_ops
3
3
  module Mobility
4
4
  module Backend
5
5
  class Sequel::Jsonb::QueryMethods < Sequel::QueryMethods
6
- def initialize(attributes, **options)
6
+ def initialize(attributes, **)
7
7
  super
8
8
  attributes_extractor = @attributes_extractor
9
9
 
@@ -31,12 +31,12 @@ Implements the {Mobility::Backend::KeyValue} backend for Sequel models.
31
31
 
32
32
  # @!group Backend Accessors
33
33
  # @!macro backend_reader
34
- def read(locale, **options)
34
+ def read(locale, **)
35
35
  translation_for(locale).value
36
36
  end
37
37
 
38
38
  # @!macro backend_writer
39
- def write(locale, value, **options)
39
+ def write(locale, value, **)
40
40
  translation_for(locale).tap { |t| t.value = value }.value
41
41
  end
42
42
  # @!endgroup
@@ -10,7 +10,7 @@ models. For details see backend-specific subclasses.
10
10
  class QueryMethods < Module
11
11
  # @param [Array<String>] attributes Translated attributes
12
12
  # @param [Hash] options Backend options
13
- def initialize(attributes, **options)
13
+ def initialize(attributes, **)
14
14
  @attributes = attributes.map! &:to_sym
15
15
  @attributes_extractor = lambda do |cond|
16
16
  cond.is_a?(Hash) && (cond.keys & attributes).presence
@@ -35,12 +35,12 @@ Sequel serialization plugin.
35
35
  # @!group Backend Accessors
36
36
  #
37
37
  # @!macro backend_reader
38
- def read(locale, **options)
38
+ def read(locale, **)
39
39
  translations[locale]
40
40
  end
41
41
 
42
42
  # @!macro backend_reader
43
- def write(locale, value, **options)
43
+ def write(locale, value, **)
44
44
  translations[locale] = value
45
45
  end
46
46
  # @!endgroup
@@ -1,7 +1,7 @@
1
1
  module Mobility
2
2
  module Backend
3
3
  class Sequel::Serialized::QueryMethods < Sequel::QueryMethods
4
- def initialize(attributes, **options)
4
+ def initialize(attributes, **)
5
5
  super
6
6
  attributes_extractor = @attributes_extractor
7
7
  cond_checker = @cond_checker = lambda do |cond|
@@ -15,19 +15,19 @@ Implements the {Mobility::Backend::Table} backend for Sequel models.
15
15
 
16
16
  # @!macro backend_constructor
17
17
  # @option options [Symbol] association_name Name of association
18
- def initialize(model, attribute, **options)
18
+ def initialize(model, attribute, **)
19
19
  super
20
20
  @association_name = options[:association_name]
21
21
  end
22
22
 
23
23
  # @!group Backend Accessors
24
24
  # @!macro backend_reader
25
- def read(locale, **options)
25
+ def read(locale, **)
26
26
  translation_for(locale).send(attribute)
27
27
  end
28
28
 
29
29
  # @!macro backend_reader
30
- def write(locale, value, **options)
30
+ def write(locale, value, **)
31
31
  translation_for(locale).tap { |t| t.send("#{attribute}=", value) }.send(attribute)
32
32
  end
33
33
 
@@ -15,7 +15,7 @@ method is called.
15
15
  model_class.class_eval do
16
16
  mod = Module.new do
17
17
  define_method :refresh do
18
- super().tap { instance_eval &model_reset_method }
18
+ super().tap { instance_eval(&model_reset_method) }
19
19
  end
20
20
  end
21
21
  include mod
@@ -1,3 +1,3 @@
1
1
  module Mobility
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,11 @@
1
+ module Sequel
2
+ module Plugins
3
+ module Mobility
4
+ module InstanceMethods
5
+ def self.included(base)
6
+ base.include(::Mobility)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ 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.3
4
+ version: 0.1.4
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-02-25 00:00:00.000000000 Z
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store
@@ -213,6 +213,7 @@ files:
213
213
  - lib/mobility/translates.rb
214
214
  - lib/mobility/version.rb
215
215
  - lib/mobility/wrapper.rb
216
+ - lib/sequel/plugins/mobility.rb
216
217
  homepage: https://github.com/shioyama/mobility
217
218
  licenses:
218
219
  - MIT