mobility 0.3.2 → 0.3.3

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: c42bb66ac64ed65434f7550515f60ab7907001d6
4
- data.tar.gz: 8a977f61b918d4ff6f0f23f6accb810b15c4d3d5
3
+ metadata.gz: 00e8866b69b091c9fd411212b4f262382dc00da3
4
+ data.tar.gz: 45f61733fe33af52d7b4be9e35d75aa0344b6c54
5
5
  SHA512:
6
- metadata.gz: 3974c3e07c18c765342863943d098eed06ff944ff8339029bf3e24c27d81c0462688798706e771595a83ebc7fc36c99f156f65de35d27a68aab9bfe56e87103a
7
- data.tar.gz: 2105d1889d4c54dafdcf41f98c2a76ee7e09773df1166caa86d31b7e320495a7e080757a9c8ec061472d341b86a35bb6059f8f981a6efe787fc7c5d39d388921
6
+ metadata.gz: a942928eba9620bdfccede2153501fa994c475d5174b1e7fdab2c76c2acaaf9a1787ec92938c46103afbb156aba5c70c729130311cbceed6903efd00a782c031
7
+ data.tar.gz: d455f2eb6fd95cf6a6a4a8a02293917a450be4a272bef424dd292d57bfab466caea1adce71ba3f64fb20770cbbb8dd681f8809b4f4112c111c40f2fd9fd38f88
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## 0.3
4
4
 
5
+ ### 0.3.3 (December 5, 2017)
6
+ * Fix duping for AR KeyValue backend ([#126](https://github.com/shioyama/mobility/pull/126))
7
+ * Pass locale and options to Proc in default plugin ([#122](https://github.com/shioyama/mobility/pull/122))
8
+
5
9
  ### 0.3.2 (December 1, 2017)
6
10
  * Fix issue with querying on translated attributes with Sequel Table backend ([#121](https://github.com/shioyama/mobility/pull/121))
7
11
 
@@ -1,20 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (0.3.1)
4
+ mobility (0.3.2)
5
5
  i18n (>= 0.6.10, < 0.10)
6
6
  request_store (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ actionpack (5.2.0.beta2)
12
+ actionview (= 5.2.0.beta2)
13
+ activesupport (= 5.2.0.beta2)
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.2.0.beta2)
19
+ activesupport (= 5.2.0.beta2)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
+ activemodel (5.2.0.beta2)
25
+ activesupport (= 5.2.0.beta2)
26
+ activerecord (5.2.0.beta2)
27
+ activemodel (= 5.2.0.beta2)
28
+ activesupport (= 5.2.0.beta2)
29
+ arel (>= 9.0)
30
+ activesupport (5.2.0.beta2)
31
+ concurrent-ruby (~> 1.0, >= 1.0.2)
32
+ i18n (~> 0.7)
33
+ minitest (~> 5.1)
34
+ tzinfo (~> 1.1)
35
+ arel (9.0.0)
36
+ builder (3.2.3)
11
37
  byebug (9.1.0)
12
38
  coderay (1.1.2)
13
39
  concurrent-ruby (1.0.5)
40
+ crass (1.0.3)
14
41
  database_cleaner (1.6.2)
15
42
  diff-lcs (1.3)
43
+ erubi (1.7.0)
16
44
  ffi (1.9.18)
17
45
  formatador (0.2.5)
46
+ generator_spec (0.9.4)
47
+ activesupport (>= 3.0.0)
48
+ railties (>= 3.0.0)
18
49
  guard (2.14.1)
19
50
  formatador (>= 0.2.4)
20
51
  listen (>= 2.7, < 4.0)
@@ -35,10 +66,17 @@ GEM
35
66
  rb-fsevent (~> 0.9, >= 0.9.4)
36
67
  rb-inotify (~> 0.9, >= 0.9.7)
37
68
  ruby_dep (~> 1.2)
69
+ loofah (2.1.1)
70
+ crass (~> 1.0.2)
71
+ nokogiri (>= 1.5.9)
38
72
  lumberjack (1.0.12)
39
73
  method_source (0.9.0)
74
+ mini_portile2 (2.3.0)
75
+ minitest (5.10.3)
40
76
  mysql2 (0.4.10)
41
77
  nenv (0.3.0)
78
+ nokogiri (1.8.1)
79
+ mini_portile2 (~> 2.3.0)
42
80
  notiffany (0.1.1)
43
81
  nenv (~> 0.1)
44
82
  shellany (~> 0.0)
@@ -49,6 +87,20 @@ GEM
49
87
  pry-byebug (3.5.1)
50
88
  byebug (~> 9.1)
51
89
  pry (~> 0.10)
90
+ rack (2.0.3)
91
+ rack-test (0.8.2)
92
+ rack (>= 1.0, < 3)
93
+ rails-dom-testing (2.0.3)
94
+ activesupport (>= 4.2.0)
95
+ nokogiri (>= 1.6)
96
+ rails-html-sanitizer (1.0.3)
97
+ loofah (~> 2.0)
98
+ railties (5.2.0.beta2)
99
+ actionpack (= 5.2.0.beta2)
100
+ activesupport (= 5.2.0.beta2)
101
+ method_source
102
+ rake (>= 0.8.7)
103
+ thor (>= 0.18.1, < 2.0)
52
104
  rake (12.3.0)
53
105
  rb-fsevent (0.10.2)
54
106
  rb-inotify (0.9.10)
@@ -68,26 +120,30 @@ GEM
68
120
  rspec-support (~> 3.7.0)
69
121
  rspec-support (3.7.0)
70
122
  ruby_dep (1.5.0)
71
- sequel (5.2.0)
72
123
  shellany (0.0.1)
73
124
  sqlite3 (1.3.13)
74
125
  thor (0.20.0)
126
+ thread_safe (0.3.6)
127
+ tzinfo (1.2.4)
128
+ thread_safe (~> 0.1)
75
129
  yard (0.9.12)
76
130
 
77
131
  PLATFORMS
78
132
  ruby
79
133
 
80
134
  DEPENDENCIES
135
+ activerecord (>= 5.2.0.beta1, < 5.3)
81
136
  bundler (~> 1.12)
82
137
  database_cleaner (~> 1.5, >= 1.5.3)
138
+ generator_spec (~> 0.9.4)
83
139
  guard-rspec
84
140
  mobility!
85
141
  mysql2 (~> 0.4.9)
86
142
  pg
87
143
  pry-byebug
144
+ railties (>= 5.2.0.beta1, < 5.3)
88
145
  rake (~> 12, >= 12.2.1)
89
146
  rspec (~> 3.0)
90
- sequel (>= 5.0.0, < 6.0.0)
91
147
  sqlite3
92
148
  yard (~> 0.9.0)
93
149
 
data/README.md CHANGED
@@ -4,7 +4,9 @@ Mobility
4
4
  [![Gem Version](https://badge.fury.io/rb/mobility.svg)][gem]
5
5
  [![Build Status](https://travis-ci.org/shioyama/mobility.svg?branch=master)][travis]
6
6
  [![Dependency Status](https://gemnasium.com/shioyama/mobility.svg)][gemnasium]
7
- [![Code Climate](https://codeclimate.com/github/shioyama/mobility/badges/gpa.svg)][codeclimate]
7
+ [![Code Climate](https://api.codeclimate.com/v1/badges/72200f2b00c339ec4537/maintainability.svg)][codeclimate]
8
+
9
+ [![Gitter Chat](https://badges.gitter.im/mobility-ruby/mobility.svg)](https://gitter.im/mobility-ruby/mobility)
8
10
 
9
11
  [gem]: https://rubygems.org/gems/mobility
10
12
  [travis]: https://travis-ci.org/shioyama/mobility
@@ -52,7 +54,7 @@ Installation
52
54
  Add this line to your application's Gemfile:
53
55
 
54
56
  ```ruby
55
- gem 'mobility', '~> 0.3.2'
57
+ gem 'mobility', '~> 0.3.3'
56
58
  ```
57
59
 
58
60
  Mobility is cryptographically signed. To be sure the gem you install hasn't
@@ -110,7 +112,7 @@ See [Getting Started](#quickstart) to get started translating your models.
110
112
  ### Sequel
111
113
 
112
114
  Requirements:
113
- - Sequel >= 4.0, < 5.0 (5.0 support is in the works)
115
+ - Sequel >= 4.0
114
116
 
115
117
  You can extend `Mobility` just like in ActiveRecord, or you can use the
116
118
  `mobility` plugin, which does the same thing:
@@ -70,6 +70,19 @@ Implements the {Mobility::Backends::KeyValue} backend for ActiveRecord models.
70
70
  end
71
71
  after_destroy :mobility_destroy_key_value_translations
72
72
 
73
+ module_name = "MobilityArKeyValue#{association_name.to_s.camelcase}"
74
+ unless const_defined?(module_name)
75
+ callback_methods = Module.new do
76
+ define_method :initialize_dup do |source|
77
+ super(source)
78
+ self.send("#{association_name}=", source.send(association_name).map(&:dup))
79
+ # Set inverse on associations
80
+ send(association_name).each { |translation| translation.translatable = self }
81
+ end
82
+ end
83
+ include const_set(module_name, callback_methods)
84
+ end
85
+
73
86
  private
74
87
 
75
88
  # Clean up *all* leftover translations of this model, only once.
@@ -21,7 +21,7 @@ module Mobility
21
21
  define_method :"join_#{association_name}" do |**options|
22
22
  if joins = @opts[:join]
23
23
  # Return self if we've already joined this table
24
- return self if joins.find { |clause| clause.table_expr == table_name }
24
+ return self if joins.any? { |clause| clause.table_expr == table_name }
25
25
  end
26
26
 
27
27
  join_type = options[:outer_join] ? :left_outer : :inner
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Mobility
4
4
  module Plugins
5
+ module ActiveModel
5
6
  =begin
6
7
 
7
8
  Dirty tracking for models which include the +ActiveModel::Dirty+ module.
@@ -22,7 +23,6 @@ value of the translated attribute if passed to it.
22
23
  @see http://api.rubyonrails.org/classes/ActiveModel/Dirty.html Rails documentation for Active Model Dirty module
23
24
 
24
25
  =end
25
- module ActiveModel
26
26
  module Dirty
27
27
  # @!group Backend Accessors
28
28
  # @!macro backend_writer
@@ -1,11 +1,5 @@
1
1
  module Mobility
2
2
  module Plugins
3
- =begin
4
-
5
- Module builder adding translated attributes to #attributes hash on model
6
- instance. See {Mobility::Plugins::AttributeMethods} for further details.
7
-
8
- =end
9
3
  module ActiveRecord
10
4
  module TranslatedAttributes
11
5
  def translated_attributes
@@ -17,6 +11,12 @@ instance. See {Mobility::Plugins::AttributeMethods} for further details.
17
11
  end
18
12
  end
19
13
 
14
+ =begin
15
+
16
+ Module builder adding translated attributes to #attributes hash on model
17
+ instance. See {Mobility::Plugins::AttributeMethods} for further details.
18
+
19
+ =end
20
20
  class AttributeMethods < Module
21
21
  def initialize(*attribute_names)
22
22
  include TranslatedAttributes
@@ -3,6 +3,7 @@ require "mobility/plugins/active_model/dirty"
3
3
 
4
4
  module Mobility
5
5
  module Plugins
6
+ module ActiveRecord
6
7
  =begin
7
8
 
8
9
  Dirty tracking for AR models. See {Mobility::Plugins::ActiveModel::Dirty} for
@@ -20,7 +21,6 @@ AR::Dirty plugin adds support for the following persistence-specific methods
20
21
  - +title_in_database+
21
22
 
22
23
  =end
23
- module ActiveRecord
24
24
  module Dirty
25
25
  include ActiveModel::Dirty
26
26
 
@@ -5,6 +5,12 @@ module Mobility
5
5
  Defines value or proc to fall through to if return value from getter would
6
6
  otherwise be nil.
7
7
 
8
+ If default is a proc, it is passed a hash with four keyword arguments:
9
+ - +model+: the model instance
10
+ - +attribute+: the attribute name (a String)
11
+ - +locale+: the locale (a Symbol)
12
+ - +options+: hash of options passed in to accessor
13
+
8
14
  @example With default enabled (falls through to default value)
9
15
  class Post
10
16
  extend Mobility
@@ -40,12 +46,13 @@ otherwise be nil.
40
46
  @example Using Proc as default
41
47
  class Post
42
48
  extend Mobility
43
- translates :title, default: lambda { |model:, attribute:| attribute.to_s }
49
+ translates :title, default: lambda { |attribute:, locale:| "#{attribute} in #{locale}" }
44
50
  end
45
51
 
52
+ Mobility.locale = :en
46
53
  post = Post.new(title: nil)
47
54
  post.title
48
- #=> "title"
55
+ #=> "title in en"
49
56
 
50
57
  post.title(default: lambda { |model:| model.class.name.to_s })
51
58
  #=> "Post"
@@ -62,7 +69,11 @@ otherwise be nil.
62
69
  define_method :read do |locale, options = {}|
63
70
  default = options.has_key?(:default) ? options.delete(:default) : default_option
64
71
  if (value = super(locale, options)).nil?
65
- default.is_a?(Proc) ? default.call(model: model, attribute: attribute) : default
72
+ return default unless default.is_a?(Proc)
73
+ default.call(model: model,
74
+ attribute: attribute,
75
+ locale: locale,
76
+ options: options)
66
77
  else
67
78
  value
68
79
  end
@@ -9,6 +9,7 @@ Dirty tracking for Mobility attributes. See class-specific implementations for
9
9
  details.
10
10
 
11
11
  @see Mobility::Plugins::ActiveModel::Dirty
12
+ @see Mobility::Plugins::ActiveRecord::Dirty
12
13
  @see Mobility::Plugins::Sequel::Dirty
13
14
 
14
15
  @note Dirty tracking can have unexpected results when combined with fallbacks.
@@ -1,3 +1,3 @@
1
1
  module Mobility
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -30,7 +30,7 @@ cert_chain:
30
30
  eGDROPZoL5RXwiOnRbexxa7dcAxMrDfGB/hpiunIPWPsi4n5P7K/6OO/sGVMl9xv
31
31
  SZBPXjzrHdyOFLBYXB+PG7s3F/4=
32
32
  -----END CERTIFICATE-----
33
- date: 2017-12-01 00:00:00.000000000 Z
33
+ date: 2017-12-05 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: request_store
metadata.gz.sig CHANGED
Binary file