mobility 1.0.0.beta1 → 1.0.0.beta2

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
  SHA256:
3
- metadata.gz: a27c475aac12e8c93750cd6b11b7b339912c95bb24ada1e579c8f87598359388
4
- data.tar.gz: faf2187673842e059b204715e774b2ef22d0a98e6162d7014ef875236a0db192
3
+ metadata.gz: 2346e4ef46985b520c5feea3577a6644f213e1fe89e3dfd5960f3347c72a1134
4
+ data.tar.gz: df38726f94dca7139a3eb9cf838b27dfede5378c34290a5298e7dcde01bf3c90
5
5
  SHA512:
6
- metadata.gz: 51dfb02fb8624897834dbc9260eb7edc67f6120f2971de120f7084e59df0865a027eca3ccae435ba77604fa8086760a1c682b9879a4c625be71368fa21d3b2c7
7
- data.tar.gz: 5133980f0433ba31d157ebda7e1a8028dc84aa8d8dc7ab6b0df94861c347e60f34b09665eb890341998080be5256bea566f7e0dea62f96f6c85fcfd931319969
6
+ metadata.gz: 236ad0894645f98bf2a21c6848b4ba439da84b24862a56f6fca878889a6cd9a79108711923961d2f9ee75b6a6ee8482fcefff213b5433736fa507332db0cc253
7
+ data.tar.gz: a3e78f97d08d26e18ac8187b961097e686c3fc5650f45ae84fb4aa1aad1ccd0970410f2b9e887d8618ed6c1a09e559b1fe3fd0428df591de011961a0c2da1379
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,6 +4,13 @@
4
4
 
5
5
  1.0 is a rewrite of many internals of the gem. Please see the [wiki page on v1.0](https://github.com/shioyama/mobility/wiki/Introduction-to-Mobility-v1.0) for more details on how to upgrade.
6
6
 
7
+ ## 1.0.0.beta2 (pre-release)
8
+
9
+ - Refactor attributes & backend plugins and make `mobility_attributes` public
10
+ ([#462](https://github.com/shioyama/mobility/pull/462))
11
+ - Make attribute_methods plugin depend on attributes
12
+ ([#461](https://github.com/shioyama/mobility/pull/461))
13
+
7
14
  ## 1.0.0.beta1 (pre-release)
8
15
 
9
16
  - Remove `Mobility::Backend#apply_plugin`
@@ -1,14 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobility (1.0.0.alpha)
4
+ mobility (1.0.0.beta2)
5
5
  i18n (>= 0.6.10, < 2)
6
6
  request_store (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- allocation_stats (0.1.5)
12
11
  benchmark-ips (2.8.3)
13
12
  byebug (11.1.3)
14
13
  coderay (1.1.3)
@@ -76,7 +75,6 @@ PLATFORMS
76
75
  ruby
77
76
 
78
77
  DEPENDENCIES
79
- allocation_stats
80
78
  benchmark-ips
81
79
  database_cleaner (~> 1.5, >= 1.5.3)
82
80
  guard-rspec
data/README.md CHANGED
@@ -58,7 +58,7 @@ To use the latest pre-version of Mobility 1.0, add this line to your
58
58
  application's Gemfile:
59
59
 
60
60
  ```ruby
61
- gem 'mobility', '~> 1.0.0.beta1'
61
+ gem 'mobility', '~> 1.0.0.beta2'
62
62
  ```
63
63
 
64
64
  For the latest stable version of Mobility, see the readme on the
@@ -15,6 +15,7 @@ attributes only.
15
15
  extend Plugin
16
16
 
17
17
  default true
18
+ requires :attributes
18
19
 
19
20
  initialize_hook do |*names|
20
21
  include InstanceMethods
@@ -32,8 +32,15 @@ for aggregating attributes.
32
32
  end
33
33
 
34
34
  included_hook do |klass|
35
- klass.extend ClassMethods
36
- @names.each { |name| klass.register_mobility_attribute(name) }
35
+ names = @names
36
+
37
+ klass.class_eval do
38
+ extend ClassMethods
39
+ names.each { |name| mobility_attributes << name.to_s }
40
+ mobility_attributes.uniq!
41
+ rescue FrozenError
42
+ raise FrozenAttributesError, "Attempting to translate these attributes on #{klass}, which has already been subclassed: #{names.join(', ')}."
43
+ end
37
44
  end
38
45
 
39
46
  module ClassMethods
@@ -44,25 +51,20 @@ for aggregating attributes.
44
51
  mobility_attributes.include?(name.to_s)
45
52
  end
46
53
 
47
- # Register a new attribute name. Public, but treat as internal.
48
- # @param [String, Symbol] Attribute name
49
- def register_mobility_attribute(name)
50
- (self.mobility_attributes << name.to_s).uniq!
51
- end
52
-
53
- def inherited(klass)
54
- super
55
- mobility_attributes.each { |name| klass.register_mobility_attribute(name) }
56
- end
57
-
58
- protected
59
-
60
54
  # Return translated attribute names on this model.
61
55
  # @return [Array<String>] Attribute names
62
56
  def mobility_attributes
63
57
  @mobility_attributes ||= []
64
58
  end
59
+
60
+ def inherited(klass)
61
+ super
62
+ attrs = mobility_attributes.freeze # ensure attributes are not modified after being inherited
63
+ klass.class_eval { @mobility_attributes = attrs.dup }
64
+ end
65
65
  end
66
+
67
+ class FrozenAttributesError < Error; end
66
68
  end
67
69
 
68
70
  register_plugin(:attributes, Attributes)
@@ -56,8 +56,11 @@ Defines:
56
56
 
57
57
  backend_class.setup_model(klass, names)
58
58
 
59
- @names.each do |name|
60
- klass.register_mobility_backend_class(name, @backend_class)
59
+ names = @names
60
+ backend_class = @backend_class
61
+
62
+ klass.class_eval do
63
+ names.each { |name| mobility_backend_classes[name.to_sym] = backend_class }
61
64
  end
62
65
 
63
66
  backend_class
@@ -137,12 +140,9 @@ Defines:
137
140
  raise KeyError, "No backend for: #{name}"
138
141
  end
139
142
 
140
- def register_mobility_backend_class(name, backend_class)
141
- mobility_backend_classes[name.to_sym] = backend_class
142
- end
143
-
144
143
  def inherited(klass)
145
- klass.mobility_backend_classes.merge!(@mobility_backend_classes)
144
+ parent_classes = mobility_backend_classes.freeze # ensure backend classes are not modified after being inherited
145
+ klass.class_eval { @mobility_backend_classes = parent_classes.dup }
146
146
  super
147
147
  end
148
148
 
@@ -9,7 +9,7 @@ module Mobility
9
9
  MAJOR = 1
10
10
  MINOR = 0
11
11
  TINY = 0
12
- PRE = "beta1"
12
+ PRE = "beta2"
13
13
 
14
14
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
15
15
  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: 1.0.0.beta1
4
+ version: 1.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -34,7 +34,7 @@ cert_chain:
34
34
  gSQml7TqcC6dZRsZRwYqzD9kUwdAJoCqno2CBUKs2l0yQAjFT36lRrVJznb7uWwa
35
35
  xpPFnsrtyaZW6Dty8TSG3qzmeGpmpIotA8x1VA==
36
36
  -----END CERTIFICATE-----
37
- date: 2020-11-03 00:00:00.000000000 Z
37
+ date: 2020-11-11 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: request_store
metadata.gz.sig CHANGED
Binary file