active_type 2.3.4 → 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: bd2feb0207bfe501f78ebc8f53d783f773325f3ef50eb8d90795405a0b6e11a2
4
- data.tar.gz: 4e160637b5f863125c41f1fc879a03d5d5b0d1a57da76685886ea8a9ba499401
3
+ metadata.gz: ddb772a51e5470b64366773d50daa9d1527ccee54eff6f59121aa795c5bb57a4
4
+ data.tar.gz: 5a30c57fdc09d75347e25de79707752bf301ae5cc3cb1419232129c97e55124e
5
5
  SHA512:
6
- metadata.gz: 44834e4f7ed70fec35eaac3202546f5fa32761417c7a6aadac13533f3757dcff104cd6a8c10c34cd3a0f69f15b63a7809b08c9196ced7d570c0dccb4a96daede
7
- data.tar.gz: 297442b7ef3c0a0a2dff9be7d64518ae41dc5cd79bbd359fb40a14c6cc5b8ae93a4ad7d14b3eee2768e6328a99b4991ed80947ba1259db4b3cbce28c6e798573
6
+ metadata.gz: 7ad05ccd1badf7e22f1615ab8ed5c0f893e712ba2a669109839996c743b2ce4982492a317a64601cd4f5f52328e784cf1f15211bdf0e0a7684883501db1e51d5
7
+ data.tar.gz: 9b88114bf7e5bf46af8b6b59e069da70a71e469ac50a1490b0380515616929705b6fa43492e52dcc4d97e9d81604aeda3eb64749bbfbf22a0db881c6c5ec5a0e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
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
+
5
9
  ## 2.3.4 (2023-05-11)
6
10
 
7
11
  * Fixed: ActiveType.cast preserves `.strict_loading?` and `.readonly?`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.3.4)
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.4)
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.4)
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.4)
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.4)
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.4)
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.4)
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.4)
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '2.3.4'
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.4
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-12-14 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
@@ -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.4.10
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