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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +17 -11
- data/lib/passive_model/base.rb +2 -11
- data/lib/passive_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f8f6dbda24a133cb3d85c64c34c1aeb120babbf12f8efb6273fb191dee677a4
|
|
4
|
+
data.tar.gz: 03a411981c4aefd4aefbc9063490b4513f1befc973e442850bfe0eeabf4e64ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
73
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
##
|
|
150
|
+
## Upgrading to 2.0
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
changing runtime code:
|
|
152
|
+
Review the fields you pass to `.new` and `attributes=` before upgrading.
|
|
154
153
|
|
|
155
|
-
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
data/lib/passive_model/base.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
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:
|
|
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:
|
|
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: []
|