passive_model 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c2b1ac63fdec874fc2f59c9d9bedd53f40dfec303cf9c045ce7f922cb312679
4
- data.tar.gz: e6344a1d4168704cdc9160ebb5fcfbd6bc9d98e661c0c1c6e9feeffa7cb28648
3
+ metadata.gz: 8f8f6dbda24a133cb3d85c64c34c1aeb120babbf12f8efb6273fb191dee677a4
4
+ data.tar.gz: 03a411981c4aefd4aefbc9063490b4513f1befc973e442850bfe0eeabf4e64ea
5
5
  SHA512:
6
- metadata.gz: c1c90541613b89b7704700d32a48fef9bb0adb9eeee6862f65129b71f1547a77a3c98d4ec337184381a6bbc3a5a24cdc4764d4f22424145a40b32f0cf157ccc1
7
- data.tar.gz: ddacc10308fee161f2e1d059fb8e96736700d3529466a825df52deffc5a5b67a09bcc80a6a3848ab8d1e3c70db49c5306ba5b92ab903fff8c47bd1f499912c3f
6
+ metadata.gz: 7f240b57d81a5a08ef79774a461dbb42c834d6ef987c22e1516c44fb383b59471d04c58694b3d8d17788aa116801768734c431afb49bbcef46dc7f96bb91f115
7
+ data.tar.gz: 838c1511b7e889cfa2fd1c134109f849deb37c2767de18a6c7243b5c0cc3389dc5d53fde34546e75345e310ba3e2535748a37fdc914d1a52307d5ae4675e1e04
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+
5
+ - Use ActiveModel for assignment through `.new`, `attributes=`, and
6
+ `assign_attributes`. These methods call public setters.
7
+ - Raise `ActiveModel::UnknownAttributeError` by default when a field has no
8
+ public setter. Rails controller parameters must be permitted before
9
+ assignment.
10
+ - See [Upgrading to 2.0](README.md#upgrading-to-20) for migration steps.
11
+
3
12
  ## 1.1.0 - 2026-06-14
4
13
 
5
14
  - Require `active_model` directly when loading `passive_model`, so the gem boots
data/README.md CHANGED
@@ -69,12 +69,12 @@ Assign multiple attributes with `attributes=`:
69
69
  form.attributes = { first_name: "Lewis" }
70
70
  ```
71
71
 
72
- The current implementation copies each key directly to an instance variable. For
73
- example, `first_name: "Lewis"` sets `@first_name`. Define `attr_accessor`,
74
- `attr_reader`, or explicit methods for values you need to read later.
72
+ You can also call `form.assign_attributes(first_name: "Lewis")`. Both forms and
73
+ `.new` use ActiveModel to call the public setter for each field.
75
74
 
76
- This assignment style does not call custom setters and does not reject unknown
77
- attribute names.
75
+ By default, a field without a public setter raises
76
+ `ActiveModel::UnknownAttributeError`. If you pass Rails controller parameters,
77
+ permit the fields for that form first.
78
78
 
79
79
  ### Validations
80
80
 
@@ -147,14 +147,20 @@ The callback is executed only after validations pass.
147
147
  In the current implementation it returns `false` unless an instance sets
148
148
  `@persisted` itself.
149
149
 
150
- ## Behavior Notes
150
+ ## Upgrading to 2.0
151
151
 
152
- These notes describe the current gem behavior and should be reviewed before
153
- changing runtime code:
152
+ Review the fields you pass to `.new` and `attributes=` before upgrading.
154
153
 
155
- - `persisted?` does not currently switch to `true` after a successful `save`.
156
- - Attribute assignment writes instance variables directly instead of using
157
- ActiveModel attributes or custom setters.
154
+ - Give each field you intend to write a public setter. Use `attr_accessor` for
155
+ a simple field or define the setter yourself.
156
+ - Remove extra keys before passing a hash. In Rails controllers, pass only
157
+ parameters permitted for that form.
158
+ - Review any custom setters. PassiveModel now calls them during initialization
159
+ and later assignment.
160
+
161
+ If you are upgrading from a version earlier than 1.1.0, also check any code that
162
+ rescues errors from `save!`. Since 1.1.0, a validation failure raises
163
+ `PassiveModel::ValidationError`.
158
164
 
159
165
  ## Contributing
160
166
 
@@ -8,6 +8,7 @@ module PassiveModel
8
8
  # Supports before_save (gets run only if valid) - this is a custom implementation
9
9
  # Supports passing the attributes .new and .attributes
10
10
  class Base
11
+ include ActiveModel::AttributeAssignment
11
12
  include ActiveModel::Validations
12
13
  include ActiveModel::Validations::Callbacks
13
14
  include ActiveModel::Conversion
@@ -35,11 +36,7 @@ module PassiveModel
35
36
  end
36
37
 
37
38
  def initialize(hash = {})
38
- set_attributes(hash)
39
- end
40
-
41
- def attributes=(hash = {})
42
- set_attributes(hash)
39
+ assign_attributes(hash)
43
40
  end
44
41
 
45
42
  def save
@@ -68,11 +65,5 @@ module PassiveModel
68
65
  def before_save_callbacks
69
66
  self.class.send(:before_save_callbacks)
70
67
  end
71
-
72
- def set_attributes(hash)
73
- hash.keys.each do |key|
74
- instance_variable_set('@' + key.to_s, hash[key])
75
- end
76
- end
77
68
  end
78
69
  end
@@ -1,3 +1,3 @@
1
1
  module PassiveModel
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey Geethan
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 4.0.11
63
+ rubygems_version: 3.6.9
64
64
  specification_version: 4
65
65
  summary: For using models without saving to the database
66
66
  test_files: []