mini_model 0.0.1 → 0.0.2
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/README.md +2 -3
- data/lib/mini_model.rb +7 -4
- data/test/all.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b80bb2389a67ac22d77537e366e2de43491ad63c
|
4
|
+
data.tar.gz: 989d69035efd19a70fb42e32377894a86b079469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf447cd0e17c3ae3f290363d6ae915c412672fbc2ea465a61f0b2bd7a1216c776ec652f5fe1bc8667c75248d3a60ed4007fc9d008beef8de793611fd2883135
|
7
|
+
data.tar.gz: 66f1c3d97813966cfdac883001720d9f1d800c62bcb5c75fdb6b9c05e692ce0ce66c3fd18914f430f1d29d8667dd68a0b58f7b3bc847dae08ce32081b75e8106
|
data/README.md
CHANGED
@@ -78,9 +78,8 @@ We don't want to be assigning nil all over our associations and what have you.
|
|
78
78
|
|
79
79
|
`#attributes` Gets the attributes hash.
|
80
80
|
|
81
|
-
`#attributes=` For each key/value in the given hash, sends the writer
|
82
|
-
|
83
|
-
`::attribute` macro, or manually. This is not safe to use with user input.
|
81
|
+
`#attributes=` For each key/value in the given hash, sends the writer (from key)
|
82
|
+
to self if the method exists.
|
84
83
|
|
85
84
|
`#==` Compares two models to see if they are equals. It ensures that the class,
|
86
85
|
id, and attributes of each are the same.
|
data/lib/mini_model.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module MiniModel
|
2
|
-
VERSION = '0.0.
|
2
|
+
VERSION = '0.0.2'
|
3
3
|
|
4
4
|
class Error < StandardError; end
|
5
5
|
|
@@ -151,13 +151,16 @@ module MiniModel
|
|
151
151
|
|
152
152
|
# #attributes= is vulnerable to mass assignment attacks if used
|
153
153
|
# directly with user input. Some sort of filter must be in place
|
154
|
-
# before setting attributes or initializing a new model.
|
155
|
-
# a key in the hash argument that doesn't have an accessor raises an error.
|
154
|
+
# before setting attributes or initializing a new model.
|
156
155
|
def attributes=(attributes)
|
157
156
|
@attributes = {}
|
158
157
|
|
159
158
|
attributes.each do |key, value|
|
160
|
-
|
159
|
+
writer = :"#{key}="
|
160
|
+
|
161
|
+
if respond_to?(writer)
|
162
|
+
send(writer, value)
|
163
|
+
end
|
161
164
|
end
|
162
165
|
end
|
163
166
|
|
data/test/all.rb
CHANGED
@@ -248,12 +248,12 @@ test '#attributes= resets all attributes, but not id' do
|
|
248
248
|
assert_equal user.email, user.attributes[:email]
|
249
249
|
end
|
250
250
|
|
251
|
-
test '#attributes=
|
251
|
+
test '#attributes= ignores keys without a writer' do
|
252
252
|
user = User.new
|
253
253
|
|
254
|
-
|
255
|
-
|
256
|
-
|
254
|
+
user.attributes = { foo: :bar }
|
255
|
+
|
256
|
+
assert !user.attributes.has_key?(:foo)
|
257
257
|
end
|
258
258
|
|
259
259
|
setup do
|