active_type 2.4.0 → 2.5.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: ddb772a51e5470b64366773d50daa9d1527ccee54eff6f59121aa795c5bb57a4
4
- data.tar.gz: 5a30c57fdc09d75347e25de79707752bf301ae5cc3cb1419232129c97e55124e
3
+ metadata.gz: 9b40a092b72f6361e4693545466f24456c99e8bcb99544b151ea3f2d7fc81dba
4
+ data.tar.gz: 25e7245a8e46d79a7ceb1e7de19c869e8cee5af3aabca774db5bd12e500e6a97
5
5
  SHA512:
6
- metadata.gz: 7ad05ccd1badf7e22f1615ab8ed5c0f893e712ba2a669109839996c743b2ce4982492a317a64601cd4f5f52328e784cf1f15211bdf0e0a7684883501db1e51d5
7
- data.tar.gz: 9b88114bf7e5bf46af8b6b59e069da70a71e469ac50a1490b0380515616929705b6fa43492e52dcc4d97e9d81604aeda3eb64749bbfbf22a0db881c6c5ec5a0e
6
+ metadata.gz: 15b0593912cfafd848d498cc9095928e30f925b5e1fdc82c1bdbb0e34e543f5b5f6ae981f003bd9eece9e8f3ab957daaf0b779980002b847bea73296719de286
7
+ data.tar.gz: 7b823c166979fe0786e455a39e81cf633db3784aa91a47e9c34491082489e7a7049e2997c46cc9470830fccab063c7ac693feba97eab897cea995d675cae12ae
@@ -87,6 +87,7 @@ jobs:
87
87
  image: postgres
88
88
  env:
89
89
  POSTGRES_PASSWORD: postgres
90
+ POSTGRES_DB: active_type_test
90
91
  options: >-
91
92
  --health-cmd pg_isready
92
93
  --health-interval 10s
@@ -116,16 +117,10 @@ jobs:
116
117
 
117
118
  steps:
118
119
  - uses: actions/checkout@v3
119
- - name: Install database client
120
- run: |
121
- sudo apt-get install -y postgresql-client
122
120
  - name: Install ruby
123
121
  uses: ruby/setup-ruby@v1
124
122
  with:
125
123
  ruby-version: ${{ matrix.ruby }}
126
124
  bundler-cache: true
127
- - name: Setup databases
128
- run: |
129
- PGPASSWORD=postgres psql -c 'create database active_type_test;' -U postgres -p 5432 -h localhost
130
125
  - name: Run tests
131
126
  run: bundle exec rake spec
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.5.0 (2024-02-29)
6
+
7
+ * Passing unfrozen objects as a default for an attribute is deprecated, since these objects might be shared between records.
8
+
9
+ ## 2.4.1 (2024-01-08)
10
+
11
+ * Fixed: Calling `#attributes` on the base record after a cast works now and does not throw a `MutationAfterCastError`
12
+
5
13
  ## 2.4.0 (2023-12-22)
6
14
  * Added: You can implement an `#after_cast` that is called with the original record when calling `ActiveType.cast`.
7
15
  Thanks to @MaximilianoGarciaRoe.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_type (2.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.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.4.0)
4
+ active_type (2.5.0)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -10,6 +10,7 @@ module ActiveType
10
10
  class UnmutableAttributes
11
11
 
12
12
  attr_reader :original_attributes
13
+ delegate :to_hash, to: :original_attributes
13
14
 
14
15
  def initialize(attributes)
15
16
  @original_attributes = attributes
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '2.4.0'
2
+ VERSION = '2.5.0'
3
3
  end
@@ -54,6 +54,7 @@ module ActiveType
54
54
  def build(name, type, options)
55
55
  validate_attribute_name!(name)
56
56
  options.assert_valid_keys(:default)
57
+ deprecate_non_frozen_defaults(options[:default], name)
57
58
  add_virtual_column(name, type, options)
58
59
  build_reader(name)
59
60
  build_writer(name)
@@ -68,6 +69,12 @@ module ActiveType
68
69
  @owner.virtual_columns_hash = @owner.virtual_columns_hash.merge(name.to_s => column)
69
70
  end
70
71
 
72
+ def deprecate_non_frozen_defaults(default, name)
73
+ unless default.respond_to?(:call) || default.frozen?
74
+ ActiveType.deprecator.warn("##{name}: Passing a non-frozen object as a default is deprecated. Mutating the attribute can change the default for other records. You can also wrap it in a proc.", caller_locations(3))
75
+ end
76
+ end
77
+
71
78
  def build_reader(name)
72
79
  @module.module_eval <<-BODY, __FILE__, __LINE__ + 1
73
80
  def #{name}
data/lib/active_type.rb CHANGED
@@ -21,4 +21,8 @@ module ActiveType
21
21
  # Make Util methods available under the `ActiveType` namespace
22
22
  # like `ActiveType.cast(...)`
23
23
  extend Util
24
+
25
+ def self.deprecator
26
+ @deprecator ||= ActiveSupport::Deprecation.new
27
+ end
24
28
  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.4.0
4
+ version: 2.5.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-22 00:00:00.000000000 Z
12
+ date: 2024-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler