active_type 2.3.3 → 2.4.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: cdcf7c3fd638833572dc67e729b154148f26c7e7dfbe107b9752e1e4aec08c0a
4
- data.tar.gz: e7909485f8b1147a5d94079e5933bc5ee7f75f0eab32a68b6be9abd0be2d75b8
3
+ metadata.gz: ddb772a51e5470b64366773d50daa9d1527ccee54eff6f59121aa795c5bb57a4
4
+ data.tar.gz: 5a30c57fdc09d75347e25de79707752bf301ae5cc3cb1419232129c97e55124e
5
5
  SHA512:
6
- metadata.gz: 93d20dd89b89f2764104074d36624feb091204f3e42f05100e715a1f36374dfcb13cc5f1c023be7fe75eecfdc2875cfb91c7ceeacfcc473ef424ebe7423060ba
7
- data.tar.gz: 721e41bb1299dbd7ed944c33dae47e10fac3f6e167cb5b31f67faa32a017a6f3e8bbd2b4316d9ed32ea0eed2ba8e995b334df3e7640eb8ec69f3c46726ae36c7
6
+ metadata.gz: 7ad05ccd1badf7e22f1615ab8ed5c0f893e712ba2a669109839996c743b2ce4982492a317a64601cd4f5f52328e784cf1f15211bdf0e0a7684883501db1e51d5
7
+ data.tar.gz: 9b88114bf7e5bf46af8b6b59e069da70a71e469ac50a1490b0380515616929705b6fa43492e52dcc4d97e9d81604aeda3eb64749bbfbf22a0db881c6c5ec5a0e
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.0 (2023-12-22)
6
+ * Added: You can implement an `#after_cast` that is called with the original record when calling `ActiveType.cast`.
7
+ Thanks to @MaximilianoGarciaRoe.
8
+
9
+ ## 2.3.4 (2023-05-11)
10
+
11
+ * Fixed: ActiveType.cast preserves `.strict_loading?` and `.readonly?`
12
+
5
13
  ## 2.3.3 (2023-05-11)
6
14
 
7
15
  * Fixed: `accepts_nested_attributes_for` ignores virtual attributes. Thanks to @nalabjp.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
data/Gemfile.5.2.pg.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
data/Gemfile.6.1.pg.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
data/Gemfile.7.0.pg.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.3)
4
+ active_type (2.4.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
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
 
@@ -43,6 +43,12 @@ module ActiveType
43
43
  casted.instance_variable_set(:@destroyed, record.destroyed?)
44
44
  # Rails 5.2+
45
45
  casted.instance_variable_set(:@mutations_from_database, record.instance_variable_get(:@mutations_from_database))
46
+ # Rails 6.1+
47
+ casted.instance_variable_set(:@strict_loading, record.instance_variable_get(:@strict_loading))
48
+ # Rails 7.0+
49
+ casted.instance_variable_set(:@strict_loading_mode, record.instance_variable_get(:@strict_loading_mode))
50
+ # Rails 1.0+
51
+ casted.instance_variable_set(:@readonly, record.instance_variable_get(:@readonly))
46
52
 
47
53
  # Rails 3.2, 4.2
48
54
  errors = record.errors
@@ -56,9 +62,12 @@ module ActiveType
56
62
 
57
63
  casted[klass.inheritance_column] = klass.sti_name if using_single_table_inheritance
58
64
 
65
+ casted.after_cast(record) if casted.respond_to?(:after_cast)
66
+
59
67
  if !force
60
68
  make_record_unusable(record)
61
69
  end
70
+
62
71
  casted
63
72
  end
64
73
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '2.3.3'
2
+ VERSION = '2.4.0'
3
3
  end
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.3.3
4
+ version: 2.4.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: 2023-05-11 00:00:00.000000000 Z
12
+ date: 2023-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler