active_type 1.0.0 → 1.1.0

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: 7b2ea895daaf35c95480d9f313423d9f879e3172ebcd2b03b8f2546855abd50d
4
- data.tar.gz: e65dc197f907b1ebeefb8f4677d64c8f912a4bdc0719980263898b1e3e43ec30
3
+ metadata.gz: dedf631cb94b6d78cba8e784416802df866a1f8acbdcf3fd7d25f4d15bada221
4
+ data.tar.gz: f5a41ad162f78acca060c78341b71709f6bfcedd3dbfffcee510a39b48e1b077
5
5
  SHA512:
6
- metadata.gz: 6ac6ba4d9bdbbdee783d04fb2d7b7d2655d024938ef5403347f120808391535fbdb04ef0cddbb07304cc513e041836111aa6a8cd8bec8695f9714b0202301a2b
7
- data.tar.gz: 6b43fc5f07838c9a3aa390961d2ef70010b3eb72bbec9752b5875aa7db9d4c0ae4a01b040605fdfcb2261b3d1460d261054166717f61c78825bc153d6c9c0890
6
+ metadata.gz: 2b573202922cbdcb5b37f22b4006184c6b5133ee1637778ed2381dc4c47a4974e31715eba54048eae1de0b224a20ec80b36f861368ac4d9312eed2b03371c8be
7
+ data.tar.gz: d995b70abef2d78358677a4b6c7e26bb701b5914ef24f088e806f0cf895efad3b90ce2a9487c195da2934927e7f68bb573ea5244471baab2ee1212baaa72e034
@@ -2,116 +2,119 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ActiveType is in a pre-1.0 state. This means that its APIs and behavior are subject to breaking changes without deprecation notices. Until 1.0, version numbers will follow a [Semver][]-ish `0.y.z` format, where `y` is incremented when new features or breaking changes are introduced, and `z` is incremented for lesser changes or bug fixes.
5
+ ## 1.1.0 (2019-03-04)
6
6
 
7
- ## [1.0.0][] (2019-02-15)
7
+ * For some use cases, users need to access ActiveRecord's original `.attribute` method, which ActiveType overrides. We now alias `.attribute` as `.ar_attribute`.
8
+ * In a `ActiveRecord::Record[MyRecord]`, `.has_many` now guesses `"my_record_id"` as the foreign key. Same for `.has_one`.
9
+
10
+ ## 1.0.0 (2019-02-15)
8
11
 
9
12
  * No code changes.
10
13
  * Modernize list of supported Rails versions and Rubies.
11
14
 
12
15
 
13
- ## [0.7.5][] (2017-12-04)
16
+ ## 0.7.5 (2017-12-04)
14
17
 
15
18
  * Fixed an `chird record did not match id` exception introduced in the 0.7.3 update when using `nests_one`. Credit to @cerdiogenes.
16
19
 
17
20
 
18
- ## [0.7.4][] (2017-09-01)
21
+ ## 0.7.4 (2017-09-01)
19
22
 
20
23
  * Bugfix: ActiveType.cast sets #type correctly when casting to an STI class
21
24
 
22
- ## [0.7.3][] (2017-08-16)
25
+ ## 0.7.3 (2017-08-16)
23
26
 
24
27
  * `nests_many` / `nests_one` will now work for nested records with non-integer primary keys.
25
28
 
26
29
 
27
- ## [0.7.2][] (2017-07-31)
30
+ ## 0.7.2 (2017-07-31)
28
31
 
29
32
  * Fixed a bug when converting datetimes from certain strings. This occured if the string included an explicit time zone (i.e. `record.date_time = '2017-07-31 12:30+03:00'`), which was not the local time.
30
33
 
31
- ## [0.7.1][] (2017-06-19)
34
+ ## 0.7.1 (2017-06-19)
32
35
 
33
36
  * ActiveType::Object no longer requires a database connection on Rails 5+ (it never did on Rails 3 or 4).
34
37
 
35
- ## [0.7.0][] (2017-04-21)
38
+ ## 0.7.0 (2017-04-21)
36
39
 
37
40
  * Support `index_errors: true` for `nest_many`.
38
41
 
39
- ## [0.6.4][] (2017-02-27)
42
+ ## 0.6.4 (2017-02-27)
40
43
 
41
44
  * Fix an issue when using `ActiveType.cast` "too early".
42
45
 
43
- ## [0.6.3][] (2017-01-30)
46
+ ## 0.6.3 (2017-01-30)
44
47
 
45
48
  * Fix a load error when using `ActiveType::Object` before using `ActiveRecord::Base` within a Rails app.
46
49
 
47
- ## [0.6.2][] (2017-01-30)
50
+ ## 0.6.2 (2017-01-30)
48
51
 
49
52
  * When used with Rails, defer loading to not interfere with `ActiveRecord` configuration in initializers.
50
53
 
51
- ## [0.6.1][] (2016-12-05)
54
+ ## 0.6.1 (2016-12-05)
52
55
 
53
56
  * Remove spec folder from packaged gem.
54
57
 
55
- ## [0.6.0][] (2016-07-05)
58
+ ## 0.6.0 (2016-07-05)
56
59
 
57
60
  * Drop support for 1.8.7.
58
61
  * Rails 5 compatibility.
59
62
 
60
- ## [0.5.1][] (2016-05-09)
63
+ ## 0.5.1 (2016-05-09)
61
64
 
62
65
  * Fix an issue with incorrectly copied errors on Util.cast.
63
66
 
64
- ## [0.5.0][] (2016-04-08)
67
+ ## 0.5.0 (2016-04-08)
65
68
 
66
69
  * Nicer `#inspect` method.
67
70
 
68
- ## [0.4.5][] (2016-02-01)
71
+ ## 0.4.5 (2016-02-01)
69
72
 
70
73
  * Fixed issue `#dup`ing `ActiveType::Object`
71
74
 
72
- ## [0.4.4][] (2016-01-18)
75
+ ## 0.4.4 (2016-01-18)
73
76
 
74
77
  * Call `#after_commit` for `ActiveType::Object`
75
78
 
76
- ## [0.4.3][] (2015-11-11)
79
+ ## 0.4.3 (2015-11-11)
77
80
 
78
81
  * Fix issue with Booleans on mysql.
79
82
 
80
- ## [0.4.2][] (2015-09-24)
83
+ ## 0.4.2 (2015-09-24)
81
84
 
82
85
  * Add `attribute_will_change!` for virtual attributes.
83
86
 
84
- ## [0.4.1][] (2015-09-24)
87
+ ## 0.4.1 (2015-09-24)
85
88
 
86
89
  * Add `attribute_was` for virtual attributes.
87
90
 
88
- ## [0.4.0][] (2015-06-12)
91
+ ## 0.4.0 (2015-06-12)
89
92
 
90
93
  * Add ActiveType.cast to cast ActiveRecord instances and relations to extended models
91
94
 
92
- ## [0.3.5][] (2015-06-11)
95
+ ## 0.3.5 (2015-06-11)
93
96
 
94
97
  * Make gem crash during loading with ActiveRecord 4.2.0 because [#31](https://github.com/makandra/active_type/issues/31)
95
98
 
96
- ## [0.3.4][] (2015-03-14)
99
+ ## 0.3.4 (2015-03-14)
97
100
 
98
101
  * Support belongs_to associations for ActiveRecord 4.2.1
99
102
  * Ensure that ActiveType::Object correctly validates boolean attributes (issue [#34](https://github.com/makandra/active_type/issues/34))
100
103
 
101
- ## [0.3.3][] (2015-01-23)
104
+ ## 0.3.3 (2015-01-23)
102
105
 
103
106
  * Don't crash for database types without casting rules (fixes [#25](https://github.com/makandra/active_type/issues/25))
104
107
 
105
- ## [0.3.2][] (2015-01-22)
108
+ ## 0.3.2 (2015-01-22)
106
109
 
107
110
  * Making the gem to work with Rails version 4.0.0
108
111
  * Use native database type for type casting in pg
109
112
 
110
- ## [0.3.1][] (2014-11-19)
113
+ ## 0.3.1 (2014-11-19)
111
114
 
112
115
  * Support nested attributes in extended records (fixes [#17](https://github.com/makandra/active_type/issues/17))
113
116
 
114
- ## [0.3.0][] (2014-09-23)
117
+ ## 0.3.0 (2014-09-23)
115
118
 
116
119
  * Add support for Rails 4.2beta
117
120
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -54,4 +54,4 @@ DEPENDENCIES
54
54
  rspec (~> 3.4)
55
55
 
56
56
  BUNDLED WITH
57
- 1.16.3
57
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -54,4 +54,4 @@ DEPENDENCIES
54
54
  sqlite3
55
55
 
56
56
  BUNDLED WITH
57
- 1.16.3
57
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  rspec (~> 3.4)
59
59
 
60
60
  BUNDLED WITH
61
- 1.16.3
61
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  rspec (~> 3.4)
59
59
 
60
60
  BUNDLED WITH
61
- 1.16.3
61
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  sqlite3
59
59
 
60
60
  BUNDLED WITH
61
- 1.16.3
61
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  rspec (~> 3.4)
57
57
 
58
58
  BUNDLED WITH
59
- 1.16.3
59
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  rspec (~> 3.4)
57
57
 
58
58
  BUNDLED WITH
59
- 1.16.3
59
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  rspec (~> 3.4)
57
57
 
58
58
  BUNDLED WITH
59
- 1.16.3
59
+ 1.16.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (1.0.0)
4
+ active_type (1.1.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -56,4 +56,4 @@ DEPENDENCIES
56
56
  sqlite3
57
57
 
58
58
  BUNDLED WITH
59
- 1.16.3
59
+ 1.16.6
data/README.md CHANGED
@@ -65,6 +65,16 @@ The following behaviours are different than in vanilla Rails 5:
65
65
  - You can override attributes with custom methods and use `super`.
66
66
  - Attributes will work on records retrieved via `.find`.
67
67
  - Attributes will be duped if you dup the record.
68
+ - You cannot use `attribute :db_column` to override the behaviour of an existing database-backed attribute.
69
+
70
+ If you need to use `ActiveRecord's` own `.attribute` method, you can still access is as `ar_attribute`:
71
+
72
+ ```
73
+ class User < ApplicationRecord
74
+ # use my custom type to serialize to the database
75
+ ar_attribute :password, MyPasswordType.new
76
+ end
77
+ ```
68
78
 
69
79
 
70
80
  ### ActiveType::Object
@@ -339,6 +349,10 @@ sign_up.is_a?(SignUp) # => true
339
349
 
340
350
  This is basically like [`ActiveRecord#becomes`](http://apidock.com/rails/v4.2.1/ActiveRecord/Persistence/becomes), but with less bugs and more consistent behavior.
341
351
 
352
+ **Note that `cast` is destructive.** The originally casted record (`user`) and the returned record (`sign_up`)
353
+ share internal state (such as attributes). To avoid unexpected behavior, do not use the original record
354
+ after casting it.
355
+
342
356
  You can also cast an entire relation (scope) to a relation of an `ActiveType::Record`:
343
357
 
344
358
  ```ruby
@@ -10,6 +10,17 @@ module ActiveType
10
10
  class_attribute :extended_record_base_class
11
11
  end
12
12
 
13
+ def self.add_foreign_key_option(extended_record_base_class, scope = nil, options = {})
14
+ if scope.is_a?(Hash)
15
+ options = scope
16
+ scope = nil
17
+ end
18
+ unless options[:foreign_key]
19
+ options = options.merge(foreign_key: extended_record_base_class.name.foreign_key)
20
+ end
21
+ options
22
+ end
23
+
13
24
  module ClassMethods
14
25
 
15
26
  def model_name
@@ -20,6 +31,13 @@ module ActiveType
20
31
  extended_record_base_class.sti_name
21
32
  end
22
33
 
34
+ def has_many(name, *args, &extension)
35
+ super(name, Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
36
+ end
37
+
38
+ def has_one(name, *args, &extension)
39
+ super(name, Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension)
40
+ end
23
41
 
24
42
  private
25
43
 
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -114,6 +114,12 @@ module ActiveType
114
114
  included do
115
115
  class_attribute :virtual_columns_hash
116
116
  self.virtual_columns_hash = {}
117
+
118
+ class << self
119
+ if method_defined?(:attribute)
120
+ alias_method :ar_attribute, :attribute
121
+ end
122
+ end
117
123
  end
118
124
 
119
125
  def initialize_dup(other)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-15 00:00:00.000000000 Z
12
+ date: 2019-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.7.7
126
+ rubygems_version: 2.7.8
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Make any Ruby object quack like ActiveRecord