active_type 2.3.4 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.5.2.mysql2.lock +1 -1
- data/Gemfile.5.2.pg.lock +1 -1
- data/Gemfile.5.2.sqlite3.lock +1 -1
- data/Gemfile.6.0.sqlite3.lock +1 -1
- data/Gemfile.6.1.pg.lock +1 -1
- data/Gemfile.6.1.sqlite3.lock +1 -1
- data/Gemfile.7.0.pg.lock +1 -1
- data/Gemfile.7.0.sqlite3.lock +1 -1
- data/README.md +22 -12
- data/lib/active_type/util/unmutable_attributes.rb +1 -0
- data/lib/active_type/util.rb +3 -0
- data/lib/active_type/version.rb +1 -1
- 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: 8646e74d05d6f4f22e9999a4146192223fbe1d93e480b9cf6e2a4ac14b29b098
|
4
|
+
data.tar.gz: 6ab7306d8a5eddfef9f980d12fa9ae8eb9ba6f485b9c345cc88efd71968f6752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efdbdf46333663b2970af1e116ae9cc86fc0c7b0b557d249bfc0742de51e9dd173059d88d545d49ef9ff7916cee783b37d18ae7faae7e45870938b375690d381
|
7
|
+
data.tar.gz: cf1fe6ca9eb6921b02a48081c7a2b319293f4816e9fde88ba3608fdcda53dd9e91c6ea798fd0f34caadae0a0818d57f0bc599c0212796c86ad1c8a1ed4b5dcc3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## 2.4.1 (2024-01-08)
|
6
|
+
|
7
|
+
* Fixed: Calling `#attributes` on the base record after a cast works now and does not throw a `MutationAfterCastError`
|
8
|
+
|
9
|
+
## 2.4.0 (2023-12-22)
|
10
|
+
* Added: You can implement an `#after_cast` that is called with the original record when calling `ActiveType.cast`.
|
11
|
+
Thanks to @MaximilianoGarciaRoe.
|
12
|
+
|
5
13
|
## 2.3.4 (2023-05-11)
|
6
14
|
|
7
15
|
* Fixed: ActiveType.cast preserves `.strict_loading?` and `.readonly?`
|
data/Gemfile.5.2.mysql2.lock
CHANGED
data/Gemfile.5.2.pg.lock
CHANGED
data/Gemfile.5.2.sqlite3.lock
CHANGED
data/Gemfile.6.0.sqlite3.lock
CHANGED
data/Gemfile.6.1.pg.lock
CHANGED
data/Gemfile.6.1.sqlite3.lock
CHANGED
data/Gemfile.7.0.pg.lock
CHANGED
data/Gemfile.7.0.sqlite3.lock
CHANGED
data/README.md
CHANGED
@@ -14,13 +14,13 @@ Examples for use cases are models to support sign in:
|
|
14
14
|
class SignIn < ActiveType::Object
|
15
15
|
|
16
16
|
# this is not backed by a db table
|
17
|
-
|
17
|
+
|
18
18
|
attribute :username, :string
|
19
19
|
attribute :password, :string
|
20
20
|
|
21
21
|
validates :username, presence: true
|
22
22
|
validates :password, presence: true
|
23
|
-
|
23
|
+
|
24
24
|
# ...
|
25
25
|
|
26
26
|
end
|
@@ -38,15 +38,15 @@ class SignUp < ActiveType::Record[User]
|
|
38
38
|
# this inherits from User
|
39
39
|
|
40
40
|
validates :password, confirmation: true
|
41
|
-
|
41
|
+
|
42
42
|
after_create :send_confirmation_email
|
43
|
-
|
43
|
+
|
44
44
|
def send_confirmation_email
|
45
45
|
# this should happen on sign-up, but not when creating a user in tests etc.
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# ...
|
49
|
-
|
49
|
+
|
50
50
|
end
|
51
51
|
```
|
52
52
|
|
@@ -86,12 +86,12 @@ You can define "columns" by saying `attribute`:
|
|
86
86
|
|
87
87
|
```ruby
|
88
88
|
class SignIn < ActiveType::Object
|
89
|
-
|
89
|
+
|
90
90
|
attribute :email, :string
|
91
91
|
attribute :date_of_birth, :date
|
92
92
|
attribute :accepted_terms, :boolean
|
93
93
|
attribute :account_type
|
94
|
-
|
94
|
+
|
95
95
|
end
|
96
96
|
```
|
97
97
|
|
@@ -103,7 +103,7 @@ sign_in.date_of_birth.class # Date
|
|
103
103
|
sign_in.accepted_terms? # true
|
104
104
|
```
|
105
105
|
|
106
|
-
ActiveType knows all the types that are allowed in migrations (i.e. `:string`, `:integer`, `:float`, `:decimal`, `:datetime`, `:time`, `:date`, `:boolean`). You can also skip the type to have a virtual attribute without typecasting.
|
106
|
+
ActiveType knows all the types that are allowed in migrations (i.e. `:string`, `:integer`, `:float`, `:decimal`, `:datetime`, `:time`, `:date`, `:boolean`). You can also skip the type to have a virtual attribute without typecasting.
|
107
107
|
|
108
108
|
**`ActiveType::Object` actually inherits from `ActiveRecord::Base`, but simply skips all database access, inspired by [ActiveRecord Tableless](https://github.com/softace/activerecord-tableless).**
|
109
109
|
|
@@ -197,15 +197,15 @@ class SignIn < ActiveType::Object
|
|
197
197
|
|
198
198
|
attribute :email, :string
|
199
199
|
attribute :nickname, :string
|
200
|
-
|
200
|
+
|
201
201
|
def email
|
202
202
|
super.downcase
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
def nickname=(value)
|
206
206
|
super(value.titleize)
|
207
207
|
end
|
208
|
-
|
208
|
+
|
209
209
|
end
|
210
210
|
```
|
211
211
|
|
@@ -379,6 +379,16 @@ sign_up.is_a?(SignUp) # => true
|
|
379
379
|
```
|
380
380
|
|
381
381
|
|
382
|
+
If you need to add some special logic after casting you can add an `after_cast` method:
|
383
|
+
|
384
|
+
class SignUp < ActiveType::Record[User]
|
385
|
+
def after_cast(user)
|
386
|
+
# Called with the original user upon casting.
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
|
391
|
+
|
382
392
|
Associations
|
383
393
|
------------
|
384
394
|
|
data/lib/active_type/util.rb
CHANGED
@@ -62,9 +62,12 @@ module ActiveType
|
|
62
62
|
|
63
63
|
casted[klass.inheritance_column] = klass.sti_name if using_single_table_inheritance
|
64
64
|
|
65
|
+
casted.after_cast(record) if casted.respond_to?(:after_cast)
|
66
|
+
|
65
67
|
if !force
|
66
68
|
make_record_unusable(record)
|
67
69
|
end
|
70
|
+
|
68
71
|
casted
|
69
72
|
end
|
70
73
|
end
|
data/lib/active_type/version.rb
CHANGED
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: 2.
|
4
|
+
version: 2.4.1
|
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:
|
12
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.2.33
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Make any Ruby object quack like ActiveRecord
|