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 +4 -4
- data/CHANGELOG.md +30 -27
- data/Gemfile.3.2.mysql2.lock +2 -2
- data/Gemfile.3.2.sqlite3.lock +2 -2
- data/Gemfile.4.2.mysql2.lock +2 -2
- data/Gemfile.4.2.pg.lock +2 -2
- data/Gemfile.4.2.sqlite3.lock +2 -2
- data/Gemfile.5.1.pg.lock +2 -2
- data/Gemfile.5.2.mysql2.lock +2 -2
- data/Gemfile.5.2.pg.lock +2 -2
- data/Gemfile.5.2.sqlite3.lock +2 -2
- data/README.md +14 -0
- data/lib/active_type/extended_record/inheritance.rb +18 -0
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dedf631cb94b6d78cba8e784416802df866a1f8acbdcf3fd7d25f4d15bada221
|
4
|
+
data.tar.gz: f5a41ad162f78acca060c78341b71709f6bfcedd3dbfffcee510a39b48e1b077
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b573202922cbdcb5b37f22b4006184c6b5133ee1637778ed2381dc4c47a4974e31715eba54048eae1de0b224a20ec80b36f861368ac4d9312eed2b03371c8be
|
7
|
+
data.tar.gz: d995b70abef2d78358677a4b6c7e26bb701b5914ef24f088e806f0cf895efad3b90ce2a9487c195da2934927e7f68bb573ea5244471baab2ee1212baaa72e034
|
data/CHANGELOG.md
CHANGED
@@ -2,116 +2,119 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
|
5
|
+
## 1.1.0 (2019-03-04)
|
6
6
|
|
7
|
-
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
38
|
+
## 0.7.0 (2017-04-21)
|
36
39
|
|
37
40
|
* Support `index_errors: true` for `nest_many`.
|
38
41
|
|
39
|
-
##
|
42
|
+
## 0.6.4 (2017-02-27)
|
40
43
|
|
41
44
|
* Fix an issue when using `ActiveType.cast` "too early".
|
42
45
|
|
43
|
-
##
|
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
|
-
##
|
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
|
-
##
|
54
|
+
## 0.6.1 (2016-12-05)
|
52
55
|
|
53
56
|
* Remove spec folder from packaged gem.
|
54
57
|
|
55
|
-
##
|
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
|
-
##
|
63
|
+
## 0.5.1 (2016-05-09)
|
61
64
|
|
62
65
|
* Fix an issue with incorrectly copied errors on Util.cast.
|
63
66
|
|
64
|
-
##
|
67
|
+
## 0.5.0 (2016-04-08)
|
65
68
|
|
66
69
|
* Nicer `#inspect` method.
|
67
70
|
|
68
|
-
##
|
71
|
+
## 0.4.5 (2016-02-01)
|
69
72
|
|
70
73
|
* Fixed issue `#dup`ing `ActiveType::Object`
|
71
74
|
|
72
|
-
##
|
75
|
+
## 0.4.4 (2016-01-18)
|
73
76
|
|
74
77
|
* Call `#after_commit` for `ActiveType::Object`
|
75
78
|
|
76
|
-
##
|
79
|
+
## 0.4.3 (2015-11-11)
|
77
80
|
|
78
81
|
* Fix issue with Booleans on mysql.
|
79
82
|
|
80
|
-
##
|
83
|
+
## 0.4.2 (2015-09-24)
|
81
84
|
|
82
85
|
* Add `attribute_will_change!` for virtual attributes.
|
83
86
|
|
84
|
-
##
|
87
|
+
## 0.4.1 (2015-09-24)
|
85
88
|
|
86
89
|
* Add `attribute_was` for virtual attributes.
|
87
90
|
|
88
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
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
|
-
##
|
117
|
+
## 0.3.0 (2014-09-23)
|
115
118
|
|
116
119
|
* Add support for Rails 4.2beta
|
117
120
|
|
data/Gemfile.3.2.mysql2.lock
CHANGED
data/Gemfile.3.2.sqlite3.lock
CHANGED
data/Gemfile.4.2.mysql2.lock
CHANGED
data/Gemfile.4.2.pg.lock
CHANGED
data/Gemfile.4.2.sqlite3.lock
CHANGED
data/Gemfile.5.1.pg.lock
CHANGED
data/Gemfile.5.2.mysql2.lock
CHANGED
data/Gemfile.5.2.pg.lock
CHANGED
data/Gemfile.5.2.sqlite3.lock
CHANGED
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
|
|
data/lib/active_type/version.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|